:root {
  --bg: #f3f6fb;
  --ink: #1f2733;
  --ink-soft: #6b7686;
  --card: #ffffff;
  --line: #e3e9f2;
  --brand: #4c6ef5;
  --brand-deep: #3b5bdb;
  --ok: #2f9e6e;
  --bad: #e8503a;
  --warn: #f0a020;
  --cur: #4c6ef5;
  --radius: 16px;
  --shadow: 0 10px 30px -16px rgba(40,60,110,.4);
}
/* ===== 3-way theme (Light/Dark/System) — base :root above = native LIGHT. Opposite (dark) WCAG-aware auto-generated (contrast-solving ink/accent vs worst-case surface). ===== */
:root[data-theme="dark"]{
  --bg: #15181e;
  --ink: #b2bed0;
  --ink-soft: #9099a6;
  --card: #2e2e2e;
  --line: rgba(255,255,255,0.12);
  --brand: #5d7cf6;
  --brand-deep: #667fe3;
  --ok: #2d9669;
  --bad: #e8513c;
  --warn: #b9770c;
  --cur: #5d7cf6;
}











* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "Noto Sans KR", system-ui, sans-serif;
  background:
    radial-gradient(900px 500px at 90% -10%, #e7efff 0%, transparent 55%),
    var(--bg);
  color: var(--ink); min-height: 100vh; line-height: 1.5; -webkit-font-smoothing: antialiased;
}

.head { max-width: 720px; margin: 0 auto; padding: 24px clamp(16px,5vw,28px) 8px; display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.brand { display: flex; align-items: center; gap: 13px; }
.mark {
  width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center;
  font-family: "Gaegu", sans-serif; font-size: 26px; color: #fff;
  background: linear-gradient(150deg, var(--brand), var(--brand-deep));
  box-shadow: 0 10px 24px -12px rgba(76,110,245,.8); transform: rotate(-4deg);
}
.brand h1 { font-family: "Gaegu", sans-serif; font-size: 28px; line-height: 1; }
.brand p { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }
.best {
  background: #fff7e6; border: 1px solid #ffe2a8; color: #9a6b00;
  padding: 8px 13px; border-radius: 999px; font-size: 13px; font-weight: 700; white-space: nowrap;
}

.tabs { max-width: 720px; margin: 0 auto; padding: 8px clamp(16px,5vw,28px); display: flex; align-items: center; gap: 8px; }
.tab {
  border: 1px solid var(--line); background: var(--card); color: var(--ink-soft);
  font-family: inherit; font-size: 15px; font-weight: 700; padding: 9px 20px; border-radius: 999px; cursor: pointer;
  transition: all .15s ease;
}
.tab.is-active { background: var(--brand); color: #fff; border-color: var(--brand); box-shadow: var(--shadow); }
.today { margin-left: auto; font-size: 12.5px; color: var(--ink-soft); }

.wrap { max-width: 720px; margin: 0 auto; padding: 12px clamp(16px,5vw,28px) 60px; }

/* 긴글 */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 13px; padding: 12px; text-align: center; box-shadow: var(--shadow); }
.stat .k { display: block; font-size: 12px; color: var(--ink-soft); margin-bottom: 3px; }
.stat b { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat b i { font-style: normal; font-size: 13px; color: var(--ink-soft); font-weight: 500; margin-left: 1px; }

.passage {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 26px 24px; font-size: clamp(20px, 4.4vw, 27px); line-height: 1.9; letter-spacing: .01em;
  box-shadow: var(--shadow); cursor: text; word-break: keep-all; min-height: 100px;
}
.ch { position: relative; color: #c2cad6; transition: color .08s ease; border-radius: 3px; }
.ch.space { white-space: pre; }
.ch.ok { color: var(--ink); }
.ch.bad { color: var(--bad); background: #fde7e2; }
.ch.bad.space { background: #fde7e2; }
.ch.cur { color: var(--ink); }
.ch.cur::before {
  content: ""; position: absolute; left: -2px; top: 8%; bottom: 8%; width: 3px;
  background: var(--cur); border-radius: 2px; animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.typing-input {
  width: 100%; margin-top: 16px; font-family: inherit; font-size: 18px; color: var(--ink);
  background: var(--card); border: 2px solid var(--line); border-radius: 13px; padding: 15px 18px;
  box-shadow: var(--shadow);
}
.typing-input:focus { outline: none; border-color: var(--brand); }
.typing-input.center { text-align: center; font-size: 22px; font-weight: 700; }
.typing-input:disabled { opacity: .55; }

.row-actions { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.ghost { background: var(--card); border: 1px solid var(--line); color: var(--ink-soft); font-family: inherit; font-weight: 700; font-size: 14px; padding: 9px 16px; border-radius: 11px; cursor: pointer; }
.ghost:hover { border-color: var(--brand); color: var(--brand); }
.hint { font-size: 12.5px; color: var(--ink-soft); }
.primary {
  font-family: "Gaegu", sans-serif; font-size: 20px; background: linear-gradient(150deg, var(--brand), var(--brand-deep));
  color: #fff; border: 0; border-radius: 13px; padding: 12px 30px; cursor: pointer; box-shadow: var(--shadow);
}
.primary:hover { filter: brightness(1.05); }

/* 낱말 */
.word-stage { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); text-align: center; }
.word-hud { display: flex; justify-content: center; gap: 22px; margin-bottom: 18px; }
.hud-item { display: flex; flex-direction: column; gap: 2px; }
.hud-item .k { font-size: 12px; color: var(--ink-soft); }
.hud-item b { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.lives { flex-direction: row; align-items: center; gap: 4px; font-size: 22px; }
.life { color: #ff5d7a; }
.life.gone { color: #e3e9f2; }
.word-target {
  font-family: "Gaegu", sans-serif; font-size: clamp(40px, 12vw, 72px); line-height: 1.1;
  padding: 20px 0; color: var(--ink); word-break: keep-all;
}
.word-target small { font-family: "Noto Sans KR"; display: block; font-size: 16px; color: var(--ink-soft); margin-top: 6px; }
.word-target.pop { animation: pop .25s cubic-bezier(.2,1.4,.4,1); }
@keyframes pop { from { transform: scale(.8); opacity: .4; } }
.word-target.flash-ok { color: var(--ok); }
.word-target.flash-bad { color: var(--bad); animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.word-timer { height: 10px; background: #eef2f8; border-radius: 6px; overflow: hidden; margin: 8px 0 18px; }
.word-timer i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--brand-deep), var(--brand)); border-radius: 6px; }

/* 결과 */
.overlay { position: fixed; inset: 0; background: rgba(20,30,55,.5); display: grid; place-items: center; padding: 20px; z-index: 20; backdrop-filter: blur(3px); }
.overlay[hidden] { display: none; }
.mode[hidden] { display: none; }

/* 언어 스위처 (밝은 테마) */
.head-right { display: flex; align-items: center; gap: 10px; }
.i18n-switch {
  --i18n-switch-bg: #ffffff;
  --i18n-switch-border: var(--line);
  --i18n-switch-fg: var(--ink);
  --i18n-switch-active-bg: rgba(76,110,245,.12);
  --i18n-switch-active-fg: var(--brand);
  --i18n-switch-menu-bg: #ffffff;
  --i18n-switch-menu-border: var(--line);
}
.result-card { background: var(--card); border-radius: 22px; padding: 28px; max-width: 420px; width: 100%; text-align: center; box-shadow: 0 30px 70px -30px rgba(20,30,55,.6); animation: rise .3s ease; }
@keyframes rise { from { transform: translateY(16px); opacity: 0; } }
.result-card h2 { font-family: "Gaegu", sans-serif; font-size: 30px; margin-bottom: 18px; }
.r-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.r-stat { background: var(--bg); border-radius: 13px; padding: 14px 8px; }
.r-stat .rk { font-size: 12px; color: var(--ink-soft); display: block; }
.r-stat .rv { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.r-stat .rs { font-size: 11px; color: var(--ink-soft); display: block; margin-top: 2px; }
.r-note { margin: 18px 0; color: var(--ink-soft); font-size: 14px; }
.r-actions { display: flex; gap: 10px; justify-content: center; }

@media (max-width: 520px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .row-actions { flex-direction: column; align-items: flex-start; }
}

/* dark-mode overrides for hardcoded backgrounds (refinement) */
:root[data-theme="dark"] body{ background: var(--bg); }
:root[data-theme="dark"] .word-timer{ background: rgba(255,255,255,.10); }
:root[data-theme="dark"] .ch.bad.space{ background: rgba(255,255,255,.08); }
