:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-2: #efece4;
  --text: #1c1b18;
  --muted: #6b675e;
  --line: #e2ded3;
  --accent: #0f766e;
  --accent-soft: #ccfbf1;
  --accent-text: #ffffff;
  --mark: #fde68a;
  --mark-text: #1c1b18;
  --danger: #b42318;
  --shadow: 0 1px 2px rgba(28, 27, 24, .06), 0 4px 16px rgba(28, 27, 24, .06);
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12110f;
    --surface: #1c1b18;
    --surface-2: #262420;
    --text: #f2efe8;
    --muted: #a39e93;
    --line: #34312b;
    --accent: #2dd4bf;
    --accent-soft: #134e4a;
    --accent-text: #042f2e;
    --mark: #854d0e;
    --mark-text: #fef3c7;
    --danger: #f97066;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans JP", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom));
}

h1 { font-size: 28px; line-height: 1.15; margin: 8px 0 4px; letter-spacing: -.02em; }
h2 { font-size: 18px; margin: 24px 0 8px; }
p { margin: 0 0 12px; }
a { color: var(--accent); }

.sub { color: var(--muted); margin: 0 0 16px; }

button, input { font: inherit; color: inherit; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn:disabled { opacity: .5; }

.field {
  width: 100%; min-height: 48px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface);
}
.field:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

/* ---------- header ---------- */
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.stats { display: flex; gap: 16px; color: var(--muted); font-size: 14px; }
.stats b { color: var(--text); font-size: 20px; display: block; line-height: 1.1; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.live::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.live.off::before { background: var(--muted); }

.chips { display: flex; gap: 8px; overflow-x: auto; margin: 12px 0 4px; scrollbar-width: none; }
.chip {
  flex: none; min-height: 34px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); font-size: 14px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: transparent; }

/* ---------- word list ---------- */
.list { display: grid; gap: 10px; margin-top: 12px; }

.word {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px; cursor: pointer;
}
.word.fresh { animation: fresh 2.4s ease-out; }
@keyframes fresh { from { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); } }

.word-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.lemma { font-size: 20px; font-weight: 650; letter-spacing: -.01em; overflow-wrap: anywhere; }
.reading { color: var(--muted); font-size: 14px; margin-left: 6px; font-weight: 400; }
.translation { color: var(--accent); font-weight: 600; text-align: right; overflow-wrap: anywhere; }
.pos { color: var(--muted); font-size: 13px; font-style: italic; }

.sentence { margin: 8px 0 0; color: var(--text); opacity: .9; }
mark { background: var(--mark); color: var(--mark-text); border-radius: 4px; padding: 0 2px; }

.meta { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.meta a { color: var(--muted); }

.details { display: none; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.word.open .details { display: block; }
.details .label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty svg { width: 64px; height: 64px; stroke: var(--muted); fill: none; stroke-width: 1.5; margin-bottom: 12px; }
.empty b { color: var(--text); display: block; font-size: 18px; margin-bottom: 6px; }

/* ---------- review ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow);
  padding: 28px 20px; text-align: center; margin-top: 12px;
}
.card .lemma { font-size: 34px; }
.card .sentence { font-size: 17px; margin: 16px 0 14px; }
.card .answer { margin-top: 20px; padding-top: 20px; border-top: 1px dashed var(--line); }
.card .translation { text-align: center; font-size: 22px; }
.progress { color: var(--muted); font-size: 14px; text-align: center; margin-top: 8px; }

.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
.grades .btn { flex-direction: column; gap: 0; min-height: 56px; padding: 0 4px; font-size: 15px; }
.grades .btn small { font-size: 11px; color: var(--muted); font-weight: 400; }
.grades .again { color: var(--danger); }

/* ---------- pairing ---------- */
.pair { padding-top: 10vh; }
.code-input {
  text-align: center; font-size: 28px; letter-spacing: .3em; text-transform: uppercase;
  font-family: ui-monospace, "Cascadia Mono", Menlo, monospace; min-height: 64px;
}
.error { color: var(--danger); margin-top: 8px; min-height: 1.4em; }

/* ---------- tabs & toast ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center; gap: 4px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabs a {
  flex: 1; max-width: 160px; position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; border-radius: 12px; font-size: 12px; color: var(--muted); text-decoration: none;
}
.tabs a svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.tabs a[aria-current="page"] { color: var(--accent); background: var(--surface-2); }
.badge {
  position: absolute; top: 2px; left: calc(50% + 8px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: var(--accent-text); font-size: 11px; font-weight: 700; line-height: 18px;
}

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 20;
  max-width: 480px; margin: 0 auto; padding: 12px 16px; border-radius: 14px;
  background: var(--text); color: var(--bg); box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
  animation: rise .25s ease-out;
}
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }

.row { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid var(--line); }
.row span:last-child { color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; }
}
