:root {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --text: #1d2230;
  --muted: #6b7286;
  --line: #e2e5ec;
  --accent: #3557c8;
  --accent-text: #ffffff;
  --good: #1f9d63;
  --bad: #d64545;
  --known: #8fb8a3;
  --unknown: #e07a5f;
  --circle: #b07d14;
  --ex-bg: #f7f8fb;
  --nav-h: 60px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12141a;
    --panel: #1c1f28;
    --text: #e6e8ef;
    --muted: #9198ab;
    --line: #2d3240;
    --accent: #6f8cf0;
    --accent-text: #0e1220;
    --good: #3cc486;
    --bad: #ef6b6b;
    --known: #5f8f78;
    --unknown: #d9785c;
    --circle: #e0b04a;
    --ex-bg: #232734;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.55;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
#view { max-width: 720px; margin: 0 auto; padding: 12px 12px 96px; }
h1 { font-size: 1.35rem; margin: 0 0 .6em; }
h2 { font-size: 1.05rem; margin: 0 0 .6em; }
p { margin: .5em 0; }
code { font-size: .9em; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.panel, .card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
}
.panel.error { border-color: var(--bad); color: var(--bad); }
.panel.danger { border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }

/* ボタン */
.btn {
  display: inline-flex; align-items: center; justify-content: center; flex-direction: column;
  min-height: 44px; padding: 8px 16px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .4; pointer-events: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.bad { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; margin-top: 8px; }
.btn small { font-weight: 400; font-size: .75rem; opacity: .9; }
.btn.file { position: relative; }

/* 下部ナビ */
#nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--panel); border-top: 1px solid var(--line);
}
#nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--muted); text-decoration: none; font-size: .72rem;
}
#nav a span { font-size: 1.25rem; line-height: 1.2; }
#nav a.active { color: var(--accent); font-weight: 700; }
body[data-route="setup"] #nav { display: none; }

/* 解答ボタン列（ナビの上に固定） */
.answer-bar {
  position: fixed; left: 0; right: 0; z-index: 9;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
  display: flex; gap: 8px; padding: 8px 12px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(6px);
  max-width: 720px; margin: 0 auto;
}
.answer-bar .btn { flex: 1; min-height: 56px; font-size: 1.05rem; }
.answer-bar #undo { flex: 0 0 56px; }

/* ホーム */
.big-nums { display: flex; gap: 12px; margin-bottom: 4px; }
.big-nums div { flex: 1; text-align: center; background: var(--ex-bg); border-radius: 10px; padding: 8px; }
.big-nums .n { display: block; font-size: 2rem; font-weight: 700; line-height: 1.2; }
.big-nums .l { color: var(--muted); font-size: .85rem; }
.bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--line); }
.bar.thin { height: 6px; flex: 1; }
.b-unknown { background: var(--unknown); }
.b-known { background: var(--known); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin: 8px 0 4px; font-size: .85rem; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; background: var(--line); }
.legend i.b-unknown { background: var(--unknown); }
.legend i.b-known { background: var(--known); }
.stats dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; }

.progress-line { display: flex; align-items: center; gap: 10px; justify-content: space-between; margin: 0 2px 8px; font-size: .85rem; color: var(--muted); }

/* 単語カード */
.card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); margin-bottom: 6px; }
.card-meta .link { margin-left: auto; }
.badge { font-size: .72rem; padding: 1px 7px; border-radius: 99px; border: 1px solid currentColor; }
.badge.circle { color: var(--circle); }
.hw-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.hw { font-size: 2rem; font-weight: 700; letter-spacing: .01em; overflow-wrap: anywhere; }
.review-card:not(.flipped) .hw, .sort-card .hw { font-size: 2.3rem; }
.ipa { color: var(--muted); font-family: "Lucida Sans Unicode", "Segoe UI", "Noto Sans", sans-serif; }
.say { border: 0; background: none; cursor: pointer; font-size: .9rem; padding: 2px 4px; opacity: .75; }
.say.big { font-size: 1.3rem; }
.q-label { color: var(--muted); font-size: .85rem; margin-bottom: 4px; }
.senses { list-style: none; padding: 0; margin: 10px 0; }
.senses li { margin: 4px 0; }
.review-card:not(.flipped) .senses .mean { font-size: 1.15rem; }
.pos { display: inline-block; min-width: 3.2em; margin-right: 6px; padding: 0 6px; font-size: .75rem; color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); border-radius: 6px; text-align: center; }
.detail { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 6px; }
.ex { background: var(--ex-bg); border-radius: 8px; padding: 6px 10px; margin: 6px 0; }
.ex-en { font-size: .95rem; }
.ex-ja { color: var(--muted); font-size: .85rem; }
.phrase { margin: 10px 0; }
.ph-en { font-weight: 600; }
.ph-ja { color: var(--muted); }
.related { margin-top: 8px; }
.rel { border-left: 3px solid var(--line); padding: 2px 0 2px 10px; margin: 10px 0; }
.rel .senses { margin: 2px 0; }
.rel-mark { color: var(--accent); margin-right: 4px; }
.rel-word { font-weight: 700; }
.label, .of { color: var(--muted); font-size: .85rem; }
.note { background: color-mix(in srgb, var(--accent) 8%, var(--panel)); border-radius: 8px; padding: 8px 10px; margin: 10px 0; font-size: .9rem; }
.note-title { font-weight: 700; margin-bottom: 2px; }

/* 一覧 */
.filters { position: sticky; top: 0; z-index: 5; display: grid; gap: 8px; padding: 10px; }
input[type=search], input[type=number], select {
  width: 100%; min-height: 44px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text); font: inherit;
}
.filters .row { flex-wrap: nowrap; }
.count { margin: 0 4px 6px; }
.word-list { list-style: none; margin: 0; padding: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.word-list li + li { border-top: 1px solid var(--line); }
.word-list a { display: flex; align-items: baseline; gap: 8px; padding: 10px 12px; color: inherit; text-decoration: none; }
.word-list .no { color: var(--muted); font-size: .75rem; min-width: 2.6em; text-align: right; }
.word-list .w { font-weight: 600; }
.word-list .m { color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.dot { display: inline-block; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--line); align-self: center; }
.dot.unknown { background: var(--unknown); }
.dot.known { background: var(--known); }

/* 詳細 */
.back { margin-bottom: 8px; }
table.cards { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: .85rem; }
table.cards th, table.cards td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.history { display: flex; flex-wrap: wrap; gap: 3px; }
.history .h { width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center; border-radius: 5px; font-size: .75rem; color: #fff; }
.history .ok { background: var(--good); }
.history .ng { background: var(--bad); }

/* 設定 */
.field { display: grid; gap: 4px; margin: 10px 0; }
.field.check { grid-template-columns: auto 1fr; align-items: start; gap: 10px; }
.field.check input { width: 22px; height: 22px; margin-top: 2px; }

#toast {
  position: fixed; left: 50%; top: calc(12px + env(safe-area-inset-top)); transform: translate(-50%, -20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 20; max-width: calc(100% - 32px); font-size: .9rem;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
