:root {
  --bg: #f6f3ec; --card: #ffffff; --text: #1d1b18; --muted: #6b665e; --border: #e0dacd;
  --accent: #b8382b; --accent-text: #ffffff;
  --today: #fff4d6; --today-border: #d9a520;
  --noun: #2f6db5; --verb: #b8382b; --adj: #2f8a57;
  --ok: #1e7d4f; --ok-bg: #e2f3e9; --bad: #b3261e; --bad-bg: #fbe8e6;
  --miss-bg: #f8c9c4; --extra-bg: #fbd9b4;
  --scale: 1;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151412; --card: #201f1c; --text: #f1ede6; --muted: #a39d93; --border: #38352f;
    --accent: #e5675a; --accent-text: #1a0f0d;
    --today: #33290f; --today-border: #d9a520;
    --noun: #7fb0ec; --verb: #f08a7e; --adj: #6fd39d;
    --ok: #62d39c; --ok-bg: #16301f; --bad: #ff8f85; --bad-bg: #3a1c1a;
    --miss-bg: #6b2621; --extra-bg: #5c3a17;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
}

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; flex-shrink: 0; background: var(--card); border-right: 1px solid var(--border);
  padding: 20px 12px; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 6px;
}
.brand { font-weight: 700; font-size: 1.25rem; padding: 4px 12px 16px; }
.brand small { display: block; font-weight: 400; font-size: 0.85rem; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: block; padding: 11px 14px; border-radius: 10px; color: var(--text);
  text-decoration: none; font-size: 1.05rem;
}
.nav a:hover { background: var(--bg); }
.nav a.active { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.scalebox { margin-top: auto; display: flex; gap: 8px; align-items: center; padding: 0 12px; color: var(--muted); font-size: 0.9rem; }
main { flex: 1; min-width: 0; }
.page { max-width: 1000px; margin: 0 auto; padding: 24px 16px 40px; }

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: auto; height: auto; z-index: 10; flex-direction: row; flex-wrap: wrap; align-items: center;
    border-right: 0; border-bottom: 1px solid var(--border); padding: 8px 12px;
  }
  .brand { padding: 0 8px 0 0; font-size: 1.05rem; }
  .brand small { display: none; }
  .nav { flex-direction: row; }
  .nav a { padding: 8px 10px; font-size: 0.95rem; }
  .scalebox { margin: 0 0 0 auto; padding: 0; }
  .scalebox span { display: none; }
}

/* ---------- common ---------- */
h1 { font-size: 1.6rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; margin: 30px 0 12px; }
.sub { color: var(--muted); margin: 6px 0 14px; }
button, select, label.tog {
  font: inherit; font-size: 1rem; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--card); color: var(--text); cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.toast { color: var(--ok); font-weight: 600; }
ruby rt { font-size: 0.42em; color: var(--muted); }

/* ---------- daily words ---------- */
.day {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 14px 16px; margin-bottom: 14px;
}
.day.today { background: var(--today); border: 2px solid var(--today-border); }
.day.future { opacity: 0.55; }
.daynum { font-weight: 700; font-size: 1.05rem; margin-bottom: 8px; }
.daynum small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.cells { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 900px) { .cells { grid-template-columns: 1fr; } }
.cell { border-radius: 12px; padding: 10px 12px; border: 1px solid var(--border); background: var(--bg); cursor: pointer; }
.today .cell { background: var(--card); }
.kind { font-size: 0.85rem; font-weight: 700; letter-spacing: .02em; }
.kind.noun { color: var(--noun); } .kind.verb { color: var(--verb); } .kind.adj { color: var(--adj); }
.tag { font-size: 0.8rem; border: 1px solid var(--border); border-radius: 6px; padding: 0 6px; margin-left: 6px; color: var(--muted); font-weight: 400; }
.word { font-size: calc(2.4rem * var(--scale)); line-height: 1.2; margin: 6px 0 8px; }
.meaning { font-size: calc(1.15rem * var(--scale)); }
.extra { font-size: calc(1rem * var(--scale)); color: var(--muted); margin-top: 2px; }
.toggles { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
body.hide-furi .cell:not(.reveal) rt { visibility: hidden; }
body.hide-furi .cell:not(.reveal) .kf { visibility: hidden; }
body.hide-km .cell:not(.reveal) .km { visibility: hidden; }

/* furigana above + kanji meaning below (js/common.js annotated) */
.kw { display: inline-flex; align-items: flex-start; flex-wrap: wrap; line-height: 1; }
.word > .kw, .furi > .kw { display: flex; }
.flash .furi > .kw { justify-content: center; }
.kg { display: inline-flex; flex-direction: column; align-items: center; }
.kf { font-size: 0.42em; line-height: 1.4; height: 1.4em; color: var(--muted); white-space: nowrap; }
.kr { display: flex; }
.kc { display: flex; flex-direction: column; align-items: center; }
.kch { line-height: 1.2; }
.km {
  font-size: 0.34em; line-height: 1.25; min-height: 1.25em; max-width: 3.2em; padding: 1px 0.15em 0;
  text-align: center; color: var(--accent); font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}
body.hide-mean .cell:not(.reveal) .meaning { visibility: hidden; }

.flash { background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 20px; text-align: center; }
.flash .big { font-size: calc(3.4rem * var(--scale)); line-height: 1.9; min-height: 1.9em; }
.flash .answer { min-height: 3.4em; }
.flash .answer.hidden { visibility: hidden; }
.flash .furi { font-size: calc(2.2rem * var(--scale)); line-height: 1.2; margin-bottom: 6px; }
.flash .btns { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.stats { color: var(--muted); margin-top: 10px; }

/* ---------- hiragana exercise ---------- */
.drillbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.score { font-size: 1.3rem; font-weight: 700; margin: 8px 0 16px; min-height: 1.6em; }
.line {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 18px 20px; margin: 0 0 16px;
}
.line.ok { border-color: var(--ok); background: var(--ok-bg); }
.line.bad { border-color: var(--bad); background: var(--bad-bg); }
.num { color: var(--muted); font-size: 1rem; font-weight: 600; }
.jp {
  font-size: calc(2.4rem * var(--scale)); line-height: 1.5; letter-spacing: 0.06em;
  margin: 4px 0 12px; overflow-wrap: anywhere;
}
.line textarea {
  width: 100%; resize: none; overflow: hidden;
  font: inherit; font-size: calc(2.9rem * var(--scale)); line-height: 1.3; font-weight: 500;
  padding: 10px 14px; border-radius: 12px; border: 2px solid var(--border);
  background: var(--bg); color: var(--text);
}
.line textarea:focus { outline: none; border-color: var(--accent); }
.result { margin-top: 12px; font-size: calc(1.35rem * var(--scale)); line-height: 1.6; }
.result .label { font-size: 0.95rem; color: var(--muted); display: inline-block; min-width: 5.5em; }
.verdict { font-weight: 700; }
.ok .verdict { color: var(--ok); }
.bad .verdict { color: var(--bad); }
.miss { background: var(--miss-bg); border-radius: 4px; font-weight: 700; text-decoration: underline; }
.wrong { background: var(--extra-bg); border-radius: 4px; text-decoration: line-through; }
.note, .result .meaning { font-size: calc(1.1rem * var(--scale)); margin-top: 6px; }
.result .meaning { color: var(--muted); }
.actionbar {
  position: sticky; bottom: 0; background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 12px 14px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
