:root {
  --blue: #1a56db;
  --blue-dark: #1e429f;
  --red: #e02424;
  --yellow: #f5b400;
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1f2a44;
  --muted: #6b7593;
  --border: #e2e7f1;
  --radius: 16px;
  --shadow: 0 2px 8px rgba(31, 42, 68, 0.08);
  font-size: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 40px;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dark) 100%);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon { width: 40px; height: 40px; }
.brand-text h1 { font-size: 1.15rem; line-height: 1.2; }
.season { font-size: 0.8rem; opacity: 0.85; }
.lang-toggle {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.4);
  color: #fff;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.9rem;
}
.lang-toggle:hover { background: rgba(255,255,255,0.25); }

/* ---------- tabs ---------- */
.tabs {
  display: flex;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 4px 8px;
  border: none;
  background: none;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
}
.tab-icon { font-size: 1.3rem; }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }

/* ---------- panels ---------- */
.panel { display: none; max-width: 760px; margin: 0 auto; padding: 20px 16px; }
.panel.active { display: block; }

/* ---------- calculator ---------- */
.score-hero {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
  padding: 20px;
  margin-bottom: 16px;
  position: sticky;
  top: 62px;
  z-index: 9;
}
.score-label { font-size: 0.9rem; color: var(--muted); font-weight: 600; }
.score-value { font-size: 3.4rem; font-weight: 800; color: var(--blue); line-height: 1.1; }
.bag-remaining { display: flex; justify-content: center; gap: 14px; font-size: 0.85rem; margin: 6px 0 10px; color: var(--muted); flex-wrap: wrap; }
.bag-remaining .over { color: var(--red); font-weight: 700; }
.btn-reset {
  background: #fff;
  border: 1.5px solid var(--border);
  color: var(--muted);
  padding: 7px 20px;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
}
.btn-reset:hover { border-color: var(--red); color: var(--red); }

.goal-cards { display: grid; gap: 14px; }
@media (min-width: 640px) { .goal-cards { grid-template-columns: 1fr 1fr; } }

.goal-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  border-top: 5px solid var(--border);
}
.goal-card.red-goal { border-top-color: var(--red); }
.goal-card.blue-goal { border-top-color: var(--blue); }
.goal-card.yellow-goal { border-top-color: var(--yellow); }
.goal-card h3 { font-size: 1rem; margin-bottom: 4px; display: flex; justify-content: space-between; align-items: center; }
.goal-card h3 .pts { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.goal-card .subtotal { font-weight: 800; color: var(--blue); }

.counter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
}
.counter-row:last-child { border-bottom: none; }
.counter-label { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; font-weight: 600; }
.dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,0.15); }
.dot.red { background: var(--red); }
.dot.blue { background: var(--blue); }
.dot.yellow { background: var(--yellow); }

.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button {
  width: 42px; height: 42px;
  border-radius: 12px;
  border: none;
  font-size: 1.4rem;
  font-weight: 700;
  cursor: pointer;
  background: #eef2fb;
  color: var(--blue);
  touch-action: manipulation;
}
.stepper button:active { transform: scale(0.94); }
.stepper button:disabled { opacity: 0.35; cursor: default; }
.stepper .count { min-width: 34px; text-align: center; font-size: 1.25rem; font-weight: 800; }

.fineprint { font-size: 0.75rem; color: var(--muted); margin-top: 18px; text-align: center; line-height: 1.5; }

/* ---------- timer ---------- */
.timer-wrap { text-align: center; padding-top: 20px; }
.timer-display {
  font-size: clamp(5rem, 22vw, 10rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1;
}
.timer-display.warning { color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

.timer-bar { height: 12px; background: var(--border); border-radius: 999px; margin: 22px auto; max-width: 480px; overflow: hidden; }
.timer-bar-fill { height: 100%; width: 100%; background: var(--blue); border-radius: 999px; transition: width 0.25s linear; }
.timer-bar-fill.warning { background: var(--red); }

.timer-controls { display: flex; gap: 12px; justify-content: center; margin-bottom: 24px; }
.btn-big {
  padding: 16px 44px;
  font-size: 1.2rem;
  font-weight: 800;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  touch-action: manipulation;
}
.btn-start { background: var(--blue); color: #fff; }
.btn-start.running { background: var(--yellow); color: var(--text); }
.btn-stop { background: #fff; border: 1.5px solid var(--border); color: var(--muted); }

.timer-modes { display: flex; flex-direction: column; gap: 8px; max-width: 380px; margin: 0 auto 18px; }
.mode {
  padding: 12px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--card);
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
}
.mode.active { border-color: var(--blue); color: var(--blue); background: #eef2fb; }
.sound-toggle { font-size: 0.85rem; color: var(--muted); display: inline-flex; gap: 8px; align-items: center; cursor: pointer; }

/* ---------- manual ---------- */
.manual-links h2, .rules-summary h2 { font-size: 1.05rem; margin: 18px 0 10px; }
.link-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 10px;
  text-decoration: none;
  color: var(--text);
}
.link-card:hover { outline: 2px solid var(--blue); }
.link-icon { font-size: 1.6rem; }
.link-card strong { display: block; font-size: 0.95rem; }
.link-card small { color: var(--muted); }

.score-table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.score-table th, .score-table td { padding: 10px 14px; text-align: left; font-size: 0.9rem; }
.score-table thead { background: #eef2fb; color: var(--blue); }
.score-table tbody tr { border-top: 1px solid var(--border); }
.score-table td:nth-child(2) { font-weight: 800; color: var(--blue); }

.quickref h2 { font-size: 1.05rem; margin: 18px 0 10px; }
.spec-table td:nth-child(2), .spec-table td:nth-child(3) { font-variant-numeric: tabular-nums; white-space: nowrap; }
.spec-table td:nth-child(3) { color: var(--red); font-weight: 700; }

/* ---------- learn tab ---------- */
.learn-heading { font-size: 1.1rem; margin: 22px 0 10px; }
.learn-heading:first-child { margin-top: 4px; }
.learn-note { font-size: 0.85rem; color: var(--muted); margin-bottom: 12px; }
.learn-topic {
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  margin-bottom: 8px;
  overflow: hidden;
}
.learn-topic summary {
  padding: 13px 16px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.learn-topic summary::-webkit-details-marker { display: none; }
.learn-topic summary::after { content: "▾"; color: var(--muted); transition: transform 0.2s; }
.learn-topic[open] summary::after { transform: rotate(180deg); }
.learn-topic[open] summary { color: var(--blue); border-bottom: 1px solid var(--border); }
.learn-body { padding: 12px 16px 16px; font-size: 0.9rem; line-height: 1.65; }
.learn-body p { margin: 8px 0; }
.learn-body ul, .learn-body ol { margin: 8px 0 8px 20px; }
.learn-body li { margin: 4px 0; }
.learn-body .formula {
  background: #eef2fb;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
  color: var(--blue-dark);
}
.mini-table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 0.85rem; }
.mini-table th, .mini-table td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; }
.mini-table th { background: #eef2fb; color: var(--blue); }

/* ---------- diagrams, sims, lightbox ---------- */
.diagram, .sim { background: #fbfcfe; border: 1px solid var(--border); border-radius: 12px; padding: 8px; margin: 10px 0; }
.diagram svg, .sim svg, .field-diagram svg { width: 100%; height: auto; display: block; }
.zoomable { cursor: zoom-in; }
.field-diagram { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; }

.hint { font-size: 0.78rem; color: var(--muted); text-align: center; margin-top: -4px; }
.tip { background: #fff8e6; border-left: 4px solid var(--yellow); border-radius: 8px; padding: 10px 12px; }

.legend { list-style: none; margin: 8px 0 0 !important; padding: 0; font-size: 0.82rem; color: var(--muted); display: grid; gap: 4px; }
.legend li { margin: 0 !important; }
.key { display: inline-block; width: 26px; height: 13px; border-radius: 4px; vertical-align: -2px; margin-right: 4px; }
.key-dash.red { background: #e0242422; border: 2px dashed var(--red); }
.key-solid { background: #f5b40033; border: 2px solid var(--red); }
.key-oct { background: #3b4252; border: 2px solid var(--yellow); border-radius: 50%; width: 15px; height: 15px; }
.key-wall { background: var(--yellow); height: 8px; border-radius: 4px; }

.gear-controls { display: flex; gap: 16px; justify-content: center; padding: 8px 0 4px; font-size: 0.85rem; font-weight: 600; flex-wrap: wrap; }
.gear-controls select { font-size: 1rem; font-weight: 700; padding: 4px 8px; border-radius: 8px; border: 1.5px solid var(--border); color: var(--blue); }
.gear-readout { text-align: center; font-size: 0.9rem; padding: 6px 0 4px; }
.gear-readout strong { color: var(--blue); }

@keyframes gearspin { to { transform: rotate(360deg); } }
#g-c1, #g-c2 { transform-box: fill-box; transform-origin: center; }

/* dual flywheel: top wheel reverse, bottom forward → both surfaces pull the bag right */
.fw-top { transform-box: fill-box; transform-origin: center; animation: gearspin 0.5s linear infinite reverse; }
.fw-bot { transform-box: fill-box; transform-origin: center; animation: gearspin 0.5s linear infinite; }
.fw-bag { animation: fwbag 3s infinite; }
@keyframes fwbag {
  0% { transform: translateX(0); opacity: 1; animation-timing-function: ease-in; }
  40% { transform: translateX(105px); opacity: 1; animation-timing-function: linear; }
  50% { transform: translateX(160px); opacity: 1; animation-timing-function: ease-out; }
  78% { transform: translateX(400px); opacity: 1; }
  79%, 100% { transform: translateX(400px); opacity: 0; }
}

.pn-rod { animation: pnrod 2.8s infinite; }
.pn-bag { animation: pnbag 2.8s infinite; }
@keyframes pnrod {
  0%, 10% { transform: translateX(0); }
  55% { transform: translateX(-70px); }
  62% { transform: translateX(8px); }
  70%, 100% { transform: translateX(0); }
}
@keyframes pnbag {
  0%, 60% { transform: translateX(0); opacity: 1; }
  85% { transform: translateX(200px); opacity: 1; }
  86%, 100% { opacity: 0; }
}

.cas-s1 { animation: cas1 4s ease-in-out infinite; }
.cas-s2 { animation: cas2 4s ease-in-out infinite; }
.cas-s3 { animation: cas3 4s ease-in-out infinite; }
@keyframes cas1 { 0%, 15% { transform: translateY(0); } 50%, 65% { transform: translateY(-50px); } 100% { transform: translateY(0); } }
@keyframes cas2 { 0%, 15% { transform: translateY(0); } 50%, 65% { transform: translateY(-105px); } 100% { transform: translateY(0); } }
@keyframes cas3 { 0%, 15% { transform: translateY(0); } 50%, 65% { transform: translateY(-160px); } 100% { transform: translateY(0); } }

.lightbox {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 20, 35, 0.88);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; cursor: zoom-out;
}
.lightbox-inner { width: min(96vw, 1100px); max-height: 92vh; background: #fff; border-radius: 14px; padding: 14px; overflow: auto; }
.lightbox-inner svg { width: 100%; height: auto; }
.lightbox-close {
  position: absolute; top: 14px; right: 16px;
  background: rgba(255,255,255,0.15); color: #fff; border: none;
  width: 40px; height: 40px; border-radius: 50%; font-size: 1.1rem; cursor: pointer;
}

.rules-list { list-style: none; display: grid; gap: 8px; }
.rules-list li {
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  font-size: 0.9rem;
  line-height: 1.5;
}
.rules-list li::before { content: "✔️ "; }
