/* 配色は CSS 変数に集約（docs/app-requirements.md 5 章） */
:root {
  --bg: #fafaf7; --panel: #ffffff; --ink: #1f2328; --muted: #6b7280; --line: #e5e7eb;
  --accent: #c2410c; --accent-ink: #ffffff; --accent-soft: #fff1e6; --chip: #eef2ff; --chip-ink: #3730a3;
  --ok: #15803d; --ok-soft: #e7f6ec; --warn: #b45309; --bad: #b91c1c; --bad-soft: #fdecec;
  --fs: 16px; --tabh: 60px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a; --panel: #1d2024; --ink: #e6e6e6; --muted: #9aa3ad; --line: #2e3238;
    --accent: #fb923c; --accent-ink: #1a1007; --accent-soft: #3a2616; --chip: #262a45; --chip-ink: #c7d2fe;
    --ok: #4ade80; --ok-soft: #14301f; --warn: #fbbf24; --bad: #f87171; --bad-soft: #3a1717;
  }
}
:root[data-theme="dark"] {
  --bg: #15171a; --panel: #1d2024; --ink: #e6e6e6; --muted: #9aa3ad; --line: #2e3238;
  --accent: #fb923c; --accent-ink: #1a1007; --accent-soft: #3a2616; --chip: #262a45; --chip-ink: #c7d2fe;
  --ok: #4ade80; --ok-soft: #14301f; --warn: #fbbf24; --bad: #f87171; --bad-soft: #3a1717;
}
:root[data-size="large"] { --fs: 18px; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 var(--fs)/1.75 "Hiragino Sans", "Meiryo", "Yu Gothic UI", system-ui, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.3; }
h2 { font-size: 1.1em; margin: 0 0 .6em; }
h3 { font-size: .8em; letter-spacing: .08em; color: var(--muted); margin: 1.4em 0 .4em; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.center { text-align: center; }
.pad { padding: 12px 16px; }

/* 上の帯とタブ（スマホでは下に） */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.15em; color: var(--ink); }
.brand:hover { text-decoration: none; }
.tabs { display: flex; gap: 4px; }
.tabs a { display: flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: 999px; color: var(--muted); font-weight: 700; }
.tabs a:hover { text-decoration: none; background: var(--bg); }
.tabs a.on { color: var(--accent); background: var(--accent-soft); }
.tabs svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
main { max-width: 760px; margin: 0 auto; padding: 16px 16px 40px; }

@media (max-width: 640px) {
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--tabh) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--panel); border-top: 1px solid var(--line); justify-content: space-around; z-index: 6; }
  .tabs a { flex-direction: column; gap: 0; padding: 6px 10px; font-size: .75em; border-radius: 10px; }
  .tabs a.on { background: none; }
  main { padding-bottom: calc(var(--tabh) + 40px + env(safe-area-inset-bottom)); }
}

/* 部品 */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; margin-bottom: 14px; }
button, .button { font: inherit; font-weight: 700; padding: 10px 18px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; display: inline-block; }
button:hover, .button:hover { text-decoration: none; filter: brightness(.97); }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.wide { display: block; width: 100%; padding: 14px; font-size: 1.05em; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.badge { display: inline-block; font-size: .75em; padding: 1px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.badge.new { border-color: var(--accent); color: var(--accent); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-left: 6px; flex: none; }

/* 学ぶの入り口 */
.hero { text-align: center; }
.big-num { font-size: 2.6em; font-weight: 700; line-height: 1.1; }
.big-num small { font-size: .4em; color: var(--muted); font-weight: 400; }
.bar { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; margin-top: 10px; }
.bar span { display: block; height: 100%; background: var(--accent); }
.today { display: flex; gap: 10px; margin-bottom: 14px; }
.today div { flex: 1; text-align: center; background: var(--bg); border-radius: 10px; padding: 10px 4px; }
.today b { display: block; font-size: 1.8em; line-height: 1.2; }
.today span { font-size: .8em; color: var(--muted); }
.done { text-align: center; font-weight: 700; color: var(--ok); }

/* カード */
.progress { display: flex; justify-content: space-between; margin-bottom: 8px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 20px; outline: none; min-height: 50vh; }
.card .front { text-align: center; padding: 18px 0 8px; }
.card.flipped .front { padding-bottom: 0; }
.lemma { font-size: 2.4em; margin: 10px 0 2px; word-break: break-word; }
.ipa { font-family: "Charis SIL", "Doulos SIL", "Lucida Sans Unicode", "Segoe UI", serif; color: var(--muted); font-size: 1.05em; }
.ipa small { font-family: inherit; font-size: .75em; }
.card .front .primary { margin-top: 28px; }
.answer { position: sticky; bottom: 0; display: flex; gap: 12px; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 30%); }
@media (max-width: 640px) { .answer { bottom: calc(var(--tabh) + env(safe-area-inset-bottom)); } }
.answer button { flex: 1; padding: 16px; font-size: 1.1em; }
button.again { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
button.good { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.link-note { margin: 12px 0 0; padding: 8px 12px; border-radius: 10px; background: var(--chip); color: var(--chip-ink); font-size: .9em; }

/* 語の中身 */
.core { margin: 14px 0; padding: 12px 16px; background: var(--accent-soft); border-left: 4px solid var(--accent); border-radius: 8px; text-align: left; }
.core .img { font-size: 1.2em; font-weight: 700; }
.sense { padding: 8px 0; border-bottom: 1px dashed var(--line); }
.pos { display: inline-block; font-size: .72em; padding: 0 6px; margin-right: 6px; border-radius: 4px; background: var(--chip); color: var(--chip-ink); vertical-align: 2px; }
.ja { font-weight: 700; }
.from { color: var(--muted); font-size: .85em; margin-left: 8px; }
.ex { font-size: .9em; margin-top: 2px; }
.ex .en { display: block; font-style: italic; }
.ex .tr { display: block; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; gap: 6px; align-items: baseline; padding: 4px 12px; border-radius: 999px; background: var(--chip); color: var(--chip-ink); }
.chip small { opacity: .8; }
.story { margin-top: 6px; }
.pit { padding: 10px 14px; margin: 8px 0; border-radius: 10px; border: 1px solid var(--line); }
.pit .t { font-size: .75em; font-weight: 700; color: var(--warn); margin-right: 8px; }
.pit .wrong { display: block; color: var(--bad); text-decoration: line-through; }
.pit .wrong::before { content: "× "; text-decoration: none; display: inline-block; }
.pit .right { display: block; color: var(--ok); }
.pit .right::before { content: "○ "; }
table.rel { border-collapse: collapse; width: 100%; font-size: .9em; }
table.rel td { padding: 4px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.rel td:first-child { white-space: nowrap; font-weight: 700; width: 1%; }

/* 引く */
.search input { width: 100%; font: inherit; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); }
.list { list-style: none; margin: 10px 0 0; padding: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.list li a { display: flex; gap: 10px; align-items: baseline; padding: 9px 14px; color: var(--ink); border-bottom: 1px solid var(--line); }
.list li a:hover { background: var(--bg); text-decoration: none; }
.list .rk { color: var(--muted); font-size: .75em; width: 36px; text-align: right; flex: none; }
.list .lm { font-weight: 700; }
.list .gl { color: var(--muted); font-size: .9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.crumb { margin-bottom: 8px; }
.word .head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.word .lemma { margin: 0; }
.hub { columns: 2 180px; padding-left: 18px; }

/* 記録 */
.field { margin: 10px 0; }
.field > div { font-weight: 700; margin-bottom: 4px; }
.opt { display: inline-flex; align-items: center; gap: 4px; margin: 0 14px 6px 0; }
details.danger { margin-top: 14px; }
details.danger summary { cursor: pointer; color: var(--bad); }

/* 学び方（カード／四択）と問題の種類: ひとつ選ぶボタンの並び */
.seg { display: flex; gap: 4px; background: var(--bg); border-radius: 12px; padding: 4px; margin: 4px 0 10px; flex-wrap: wrap; }
.seg-item { flex: 1; min-width: max-content; }
.seg-item input { position: absolute; opacity: 0; pointer-events: none; }
.seg-item span { display: block; text-align: center; padding: 8px 10px; border-radius: 9px; cursor: pointer; font-weight: 700; color: var(--muted); }
.seg-item input:checked + span { background: var(--panel); color: var(--accent); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.seg-item input:focus-visible + span { outline: 2px solid var(--accent); }
.seg.small .seg-item span { padding: 5px 8px; font-size: .85em; }
.sub { display: flex; align-items: center; gap: 10px; }
.sub > span { flex: none; width: 2.6em; }
.sub .seg { flex: 1; margin: 2px 0 6px; }

/* 登り方 */
details.route summary { cursor: pointer; list-style: none; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
details.route summary::-webkit-details-marker { display: none; }
details.route summary::before { content: "▸"; color: var(--muted); }
details.route[open] summary::before { content: "▾"; }
.opt.block { display: flex; align-items: flex-start; gap: 8px; margin: 6px 0; }
.opt.block input { margin-top: .45em; }
.chip-btn { font: inherit; font-size: .85em; font-weight: 700; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--muted); }
.chip-btn.on { background: var(--chip); color: var(--chip-ink); border-color: var(--chip-ink); }
.range-in { margin-top: 8px; }
.range-in input { width: 6em; font: inherit; padding: 4px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); }

/* 四択 */
.progress .score { font-weight: 700; color: var(--ink); }
.streak { color: var(--accent); }
.timer { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; margin-bottom: 10px; }
.timer span { display: block; height: 100%; background: var(--accent); transform-origin: left; animation: shrink linear forwards; }
@keyframes shrink { from { transform: scaleX(1); } to { transform: scaleX(0); } }
.card.quiz { min-height: 0; }
.q-prompt.lemma { margin: 10px 0 2px; }
.q-ja { font-size: 1.5em; font-weight: 700; margin: 16px 0 8px; line-height: 1.4; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
@media (max-width: 480px) { .choices { grid-template-columns: 1fr; } }
.choice { display: flex; align-items: center; gap: 10px; text-align: left; padding: 14px; font-weight: 700; min-height: 56px; }
.choice.en { font-size: 1.15em; }
.choice .num { flex: none; width: 1.6em; height: 1.6em; border-radius: 50%; background: var(--bg); color: var(--muted); font-size: .75em; display: grid; place-items: center; }
.choice:disabled { cursor: default; opacity: .55; }
.choice.right { opacity: 1; background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.choice.wrong { opacity: 1; background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.verdict { margin: 16px 0 8px; font-size: 1.3em; font-weight: 700; text-align: center; }
.verdict.ok { color: var(--ok); }
.verdict.ng { color: var(--bad); }
.mini { border-top: 1px solid var(--line); padding-top: 10px; margin-bottom: 12px; }
.mini-lemma { font-size: 1.3em; }
