:root {
  color-scheme: light dark;
  --bg: #f6f5f1;
  --card: #ffffff;
  --text: #1d1f24;
  --muted: #6b7078;
  --line: #dcdad3;
  --accent: #2456c9;
  --accent-soft: #e3eafb;
  --ok: #1a7f4b;
  --ok-soft: #dcf3e6;
  --ng: #c0392b;
  --ng-soft: #fbe3df;
  --learning: #d9900a;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b;
    --card: #1f2228;
    --text: #e9eaec;
    --muted: #9aa0a9;
    --line: #343840;
    --accent: #7ea6ff;
    --accent-soft: #24304a;
    --ok: #5fd08f;
    --ok-soft: #1c3a2a;
    --ng: #ff8a7a;
    --ng-soft: #472420;
    --learning: #f0b445;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}
header, main { max-width: 560px; margin: 0 auto; padding: 0 16px; }
header { padding-top: calc(10px + env(safe-area-inset-top)); }
h1 { margin: 0 0 4px; font-size: 1.15rem; }
h1 span { font-size: 0.8rem; font-weight: normal; color: var(--muted); margin-left: 6px; }
h2 { font-size: 1rem; margin: 24px 0 8px; }
main { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }

/* 下のメニュー(親指が届く位置) */
#nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--line);
}
#nav a {
  flex: 1; max-width: 140px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px 6px; min-height: 56px;
  color: var(--muted); font-size: 0.72rem; text-decoration: none;
}
#nav .nav-icon { font-size: 1.15rem; line-height: 1.3; font-weight: 600; }
#nav a.active { color: var(--accent); font-weight: 600; }

/* 学習中は全画面(見出しとメニューを隠す) */
body[data-mode="focus"] header, body[data-mode="focus"] #nav { display: none; }
body[data-mode="focus"] main { padding-bottom: 0; }

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible, a:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* 一覧表 */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(68px, 1fr)); gap: 8px; }
.cell {
  display: flex; flex-direction: column; align-items: center;
  padding: 8px 4px 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-bottom-width: 3px;
  border-radius: 10px;
}
.cell .ch { font-size: 1.8rem; line-height: 1.3; }
.cell .sub { font-size: 0.72rem; color: var(--muted); }
.cell.lv1 { border-bottom-color: var(--learning); }
.cell.lv2 { border-bottom-color: var(--ok); }
.cell.selected { border-color: var(--accent); background: var(--accent-soft); }
.legend { margin-top: 20px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin: 0 4px 0 10px; background: var(--line); }
.dot.lv1 { background: var(--learning); }
.dot.lv2 { background: var(--ok); }

.detail {
  position: sticky; top: 0; z-index: 1;
  margin-top: 16px; padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.detail p { margin: 0; }
.detail-head { display: flex; align-items: center; gap: 14px; }
.detail-head > div:nth-child(2) { flex: 1; min-width: 0; }
.detail .big { font-size: 3rem; line-height: 1; min-width: 56px; text-align: center; }
.reading { font-size: 1.2rem; font-weight: 600; }
.reading .kana { font-size: 0.9rem; font-weight: normal; color: var(--muted); margin-left: 8px; }
textarea {
  width: 100%; margin-top: 10px; padding: 8px 10px;
  font: inherit; color: inherit;
  background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px;
  resize: vertical;
}

/* クイズ */
.settings { margin-top: 16px; display: grid; gap: 10px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; padding: 8px 4px; background: var(--card); border: 0; border-right: 1px solid var(--line); font-size: 0.9rem; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: var(--bg); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 0.85rem; color: var(--muted); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.stage { margin-top: 20px; text-align: center; }
.prompt.big { font-size: 5.5rem; line-height: 1.3; margin: 4px 0 12px; }
.prompt.big.text { font-size: 1.8rem; font-weight: 600; margin: 28px 0 32px; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.option {
  padding: 14px 8px; min-height: 60px;
  background: var(--card);
  border: 1px solid var(--line); border-bottom-width: 3px;
  border-radius: 12px;
}
.option.hangul { font-size: 2.2rem; line-height: 1.2; }
.option:disabled { cursor: default; opacity: 0.6; }
.option.correct { background: var(--ok-soft); border-color: var(--ok); opacity: 1; font-weight: 600; }
.option.wrong { background: var(--ng-soft); border-color: var(--ng); opacity: 1; }
.feedback { min-height: 130px; margin-top: 16px; }
.feedback .ok { color: var(--ok); font-weight: 700; }
.feedback .ng { color: var(--ng); font-weight: 700; }
.explain { margin: 4px 0 12px; }
.primary { padding: 10px 28px; border: 0; border-radius: 10px; background: var(--accent); color: var(--bg); font-weight: 600; }
.ghost { padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; background: transparent; }
.ghost.danger { color: var(--ng); margin-top: 8px; }

/* 動画 */
.video {
  display: flex; gap: 14px; align-items: center;
  margin-top: 16px; padding: 12px;
  background: var(--card);
  border: 1px solid var(--line); border-radius: 12px;
  color: inherit; text-decoration: none;
}
.video img { width: 160px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 8px; flex: none; }
.video > div { flex: 1; min-width: 0; }
.video-title { font-weight: 600; line-height: 1.4; }
.bar { height: 6px; margin: 8px 0 2px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--ok); }
@media (max-width: 480px) {
  .video { flex-direction: column; align-items: stretch; }
  .video img { width: 100%; }
}

/* 単語: リスト一覧 */
.lead { margin: 12px 0 0; }
.deck, .deck-head {
  display: block;
  margin-top: 12px; padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--line); border-radius: 14px;
  color: inherit; text-decoration: none;
}
.deck { border-bottom-width: 3px; }
.deck:active { background: var(--accent-soft); }
.deck-date { font-size: 0.8rem; font-weight: 600; color: var(--accent); }
.deck-title { font-size: 1.1rem; font-weight: 600; line-height: 1.4; }
.bar { display: flex; }
.bar-fill.learning { background: var(--learning); }
.back { display: inline-block; margin-top: 8px; padding: 8px 8px 8px 0; color: var(--accent); text-decoration: none; }

/* 単語: リストの画面 */
.action {
  display: flex; flex-direction: column; align-items: flex-start;
  width: 100%; margin-top: 10px; padding: 14px 16px; min-height: 64px;
  background: var(--card);
  border: 1px solid var(--line); border-bottom-width: 3px; border-radius: 14px;
  text-align: left;
}
.action b { font-size: 1.05rem; }
.action span { font-size: 0.8rem; opacity: 0.8; }
.action.primary { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.action + .seg { margin-top: 10px; }
.seg button { min-height: 44px; }
.row { border-bottom: 1px solid var(--line); border-left: 4px solid transparent; }
.row.lv1 { border-left-color: var(--learning); }
.row.lv2 { border-left-color: var(--ok); }
.row-main {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 56px; padding: 8px 4px 8px 10px;
  background: none; border: 0; text-align: left;
}
.row-ko { display: flex; flex-direction: column; flex: none; width: 46%; font-size: 1.2rem; line-height: 1.3; }
.row-yomi { font-size: 0.72rem; color: var(--muted); }
.row-ja { flex: 1; min-width: 0; font-size: 0.95rem; }
.row-tip { padding: 0 8px 12px 10px; color: var(--muted); }

/* 単語: 学習中の画面 */
.session {
  display: flex; flex-direction: column; gap: 16px;
  min-height: 100vh; min-height: 100dvh;
  padding: calc(10px + env(safe-area-inset-top)) 0 calc(16px + env(safe-area-inset-bottom));
}
.topbar { display: flex; align-items: center; gap: 10px; }
.topbar .bar { flex: 1; height: 8px; margin: 0; border-radius: 4px; }
.close { width: 44px; height: 44px; margin-left: -10px; background: none; border: 0; font-size: 1.2rem; color: var(--muted); }
.card {
  position: relative; flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  padding: 24px 18px;
  background: var(--card);
  border: 1px solid var(--line); border-bottom-width: 4px; border-radius: 20px;
  text-align: center;
  touch-action: pan-y; user-select: none; -webkit-user-select: none;
  animation: card-in 0.18s ease-out;
}
@keyframes card-in { from { opacity: 0; transform: scale(0.97); } }
.card[data-swipe="ok"] { border-color: var(--ok); background: var(--ok-soft); }
.card[data-swipe="ng"] { border-color: var(--ng); background: var(--ng-soft); }
.card-ko { font-size: clamp(2.4rem, 13vw, 4rem); line-height: 1.25; font-weight: 600; word-break: keep-all; }
.card.open .card-ko { font-size: clamp(2rem, 10vw, 3rem); }
.say { position: absolute; top: 8px; right: 8px; width: 48px; height: 48px; background: none; border: 0; font-size: 1.4rem; }
.card-back { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 100%; }
.card-back[hidden] { display: none; }
.ans-yomi { color: var(--muted); }
.ans-ja { font-size: 1.5rem; font-weight: 600; line-height: 1.4; }
.ans-tip { margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 0.95rem; text-align: left; width: 100%; }
.ans-ko { font-size: 1.6rem; font-weight: 600; line-height: 1.3; }
.actions { display: flex; gap: 10px; }
.actions.column { flex-direction: column; }
.big {
  flex: 1; min-height: 60px; padding: 12px;
  background: var(--card);
  border: 1px solid var(--line); border-bottom-width: 3px; border-radius: 14px;
  font-size: 1.1rem; font-weight: 600;
}
.big.primary { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.big.ok { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.big.ng { background: var(--ng-soft); border-color: var(--ng); color: var(--ng); }
.big.plain { border-color: transparent; background: none; color: var(--muted); font-weight: normal; }

/* 単語: 4択テスト */
.session .prompt { display: flex; align-items: center; justify-content: center; min-height: 22vh; margin: 0; text-align: center; font-weight: 600; }
.prompt.ko { font-size: clamp(2.4rem, 13vw, 3.6rem); line-height: 1.25; word-break: keep-all; }
.prompt.ja { font-size: 1.8rem; line-height: 1.4; }
.prompt.listen { align-self: center; min-height: 0; padding: 20px 40px; font-size: 3rem; background: var(--card); border: 1px solid var(--line); border-radius: 20px; }
.session .options { grid-template-columns: 1fr; gap: 8px; }
.session .option { min-height: 56px; padding: 10px 14px; font-size: 1.05rem; }
.session .option.ko { font-size: 1.4rem; }
.session .feedback { min-height: 0; margin-top: auto; display: flex; flex-direction: column; gap: 4px; }
.session .feedback:empty { display: none; }
.feedback.is-ok, .feedback.is-ng { padding: 14px 16px; border-radius: 16px; }
.feedback.is-ok { background: var(--ok-soft); }
.feedback.is-ng { background: var(--ng-soft); }
.verdict { font-weight: 700; }
.is-ok .verdict { color: var(--ok); }
.is-ng .verdict { color: var(--ng); }
.feedback .ans-tip { border-top-color: transparent; margin-top: 0; padding-top: 4px; }
.feedback .big { margin-top: 10px; flex: none; }

/* 単語: 結果 */
.result-head { margin-top: 12vh; text-align: center; }
.result-title { font-size: 1.6rem; font-weight: 700; }
.missed { flex: 1; }
.missed .row-main { border-bottom: 1px solid var(--line); }

/* 設定(声の選択など) */
.prefs { margin-top: 32px; }
.pref { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.pref select { min-height: 44px; max-width: 60%; font: inherit; font-size: 16px; color: inherit; padding: 8px 10px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.lead + .seg { margin-top: 12px; }

/* 入口の合言葉 */
.lock {
  display: flex; flex-direction: column; gap: 14px; justify-content: center;
  min-height: 80vh; min-height: 80dvh;
  padding-top: env(safe-area-inset-top);
}
.lock-q { font-size: 1.8rem; font-weight: 700; text-align: center; }
.lock input {
  min-height: 56px; padding: 10px 14px;
  font: inherit; font-size: 1.2rem; text-align: center; color: inherit;
  background: var(--card);
  border: 1px solid var(--line); border-radius: 14px;
}
.lock input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.lock .big { flex: none; }
.lock-msg { min-height: 1.6em; text-align: center; color: var(--ng); }
.lock.shake { animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
