:root {
  --bg: #FBF7EF;
  --card: #FFFFFF;
  --ink: #1E1A16;
  --sub: #4E453B;
  --line: #8A7E70;
  --accent: #8E2A1E;
  --on-accent: #FFFFFF;
  --soft: #F1E8D8;
  --mask: #D9CDB9;
  --lv0: #FFFFFF;
  --lv1: #F6DFA8;
  --lv2: #BFE0C2;
  --lv3: #2E6B3C;
  --on-lv3: #FFFFFF;
  --miss: #F3C9C1;
  --text-size: 30px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17140F; --card: #231F18; --ink: #F7F1E6; --sub: #D8CDBC; --line: #8F8474;
    --accent: #F0B7A6; --on-accent: #2A0F09; --soft: #2F2920; --mask: #4A4235;
    --lv0: #231F18; --lv1: #6B5420; --lv2: #2F5C39; --lv3: #A9E0B3; --on-lv3: #10260F; --miss: #6E2B22;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Hiragino Sans", "BIZ UDPGothic", "Yu Gothic UI", "Noto Sans JP", sans-serif;
  font-size: 20px; line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}
main {
  max-width: 640px; margin: 0 auto; outline: none;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
}
h1 { font-size: 30px; line-height: 1.3; margin: 8px 0 12px; }
h2 { font-size: 24px; line-height: 1.4; margin: 28px 0 10px; }
p { margin: 0 0 12px; }
.sub { color: var(--sub); }

button {
  font: inherit; font-weight: 700; color: var(--ink); background: var(--card);
  border: 2px solid var(--line); border-radius: 14px;
  min-height: 64px; width: 100%; padding: 12px 16px; cursor: pointer;
  touch-action: manipulation;
}
button:active { transform: translateY(1px); }
button:focus-visible { outline: 4px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-size: 24px; min-height: 80px; }
button .small { display: block; font-size: 18px; font-weight: 400; }
button.big-menu { text-align: left; }
.stack { display: grid; gap: 14px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.back {
  width: auto; min-width: 120px; min-height: 60px; margin-bottom: 8px; background: transparent;
}

/* 点数 */
.score-card { background: var(--card); border: 2px solid var(--line); border-radius: 16px; padding: 18px; margin-bottom: 16px; }
.score-num { font-size: 64px; font-weight: 800; line-height: 1.1; }
.score-num small { font-size: 26px; font-weight: 700; margin-left: 4px; }
.meter { height: 22px; background: var(--soft); border: 2px solid var(--line); border-radius: 11px; overflow: hidden; margin: 10px 0; }
.meter i { display: block; height: 100%; background: var(--accent); }

/* 本文 */
.koujou { font-size: var(--text-size); line-height: 2.15; word-break: break-all; }
.koujou rt { font-size: .5em; font-weight: 400; color: var(--sub); }
.no-ruby rt { display: none; }
.no-ruby .koujou { line-height: 1.7; }
.mask { background: var(--mask); border-radius: 4px; }
.passage { background: var(--card); border: 2px solid var(--line); border-radius: 16px; padding: 16px; margin-bottom: 14px; }
.tag { font-size: 18px; font-weight: 700; color: var(--sub); margin-bottom: 4px; }
.reading { padding: 8px 12px; border-left: 8px solid transparent; border-radius: 6px; margin-bottom: 8px; }
.reading.now { border-left-color: var(--accent); background: var(--soft); }
.note { background: var(--soft); border-radius: 12px; padding: 14px; font-size: 21px; margin-bottom: 14px; }
.draft { font-size: 18px; color: var(--sub); }

/* 下に固定の操作 */
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  background: var(--bg); border-top: 2px solid var(--line);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}
.bar > div { max-width: 640px; margin: 0 auto; display: grid; gap: 10px; }

/* 覚え具合の地図 */
.map { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.cell { min-height: 64px; padding: 2px; line-height: 1.2; font-size: 18px; border-radius: 10px; background: var(--lv0); }
.cell b { display: block; font-size: 24px; }
.cell.miss { background: var(--miss); }
.cell.lv1 { background: var(--lv1); }
.cell.lv2 { background: var(--lv2); }
.cell.lv3 { background: var(--lv3); color: var(--on-lv3); }
.legend { display: grid; gap: 6px; font-size: 19px; margin: 12px 0; }
.legend span { display: inline-block; min-width: 2em; text-align: center; font-weight: 800; }

.chart { display: flex; align-items: flex-end; gap: 4px; height: 150px; border-bottom: 2px solid var(--line); }
.chart div { flex: 1; min-width: 0; background: var(--accent); border-radius: 4px 4px 0 0; }
.choice[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

/* ホーム */
.hdr { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.hdr h1 { font-size: 26px; margin: 4px 0; }
.hdr-btn { width: auto; min-height: 60px; padding: 8px 14px; font-size: 18px; flex-shrink: 0; }
.score-row { display: flex; align-items: center; gap: 16px; padding: 14px 16px; margin: 8px 0 14px; }
.score-row .score-num { font-size: 52px; }
.score-side { flex: 1; min-width: 0; }
.score-side p { margin: 0; font-size: 18px; line-height: 1.5; }
.score-side .meter { margin-top: 0; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0; }
.tile { min-height: 100px; font-size: 22px; }
.tile .small { font-size: 17px; margin-top: 4px; }

/* 一言ガイド */
.guide {
  background: var(--soft); border-radius: 12px; padding: 12px 14px; margin: 0 0 16px;
  font-size: 19px; line-height: 1.6;
}
.guide b { display: block; font-size: 16px; color: var(--accent); letter-spacing: .1em; }

/* 下の操作 */
.bar .row, .bar .row3, .bar .stack { gap: 10px; }
.bar button { min-height: 60px; padding: 8px 10px; }
.primary-soft { border-color: var(--accent); border-width: 3px; }
.grade { min-height: 84px; padding: 6px 4px; font-size: 18px; line-height: 1.3; }
.grade b { display: block; font-size: 30px; line-height: 1.1; }
.grade.said { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

/* 案内と使い方 */
.tour { background: var(--card); border: 2px solid var(--line); border-radius: 16px; padding: 20px; margin: 8px 0 20px; }
.tour p { font-size: 22px; line-height: 1.8; margin: 0; }
.steps { padding-left: 1.4em; margin: 0 0 12px; }
.steps li { margin-bottom: 8px; }
.defs dt { font-weight: 800; margin-top: 12px; }
.defs dd { margin: 2px 0 0; }

/* ========== 見た目：モダン（若い人・現役世代向け） ========== */
.streak { display: none; }
:root[data-theme="modern"] {
  --bg: #0E0D0C; --card: #1A1817; --ink: #F5F1EA; --sub: #B9B1A6; --line: #34302C;
  --accent: #FF6A4D; --on-accent: #1A0904; --gold: #E9B949; --soft: #221F1C; --mask: #3A3530;
  --lv0: #1A1817; --lv1: #6B5420; --lv2: #24573A; --lv3: #E9B949; --on-lv3: #1A1205; --miss: #5E2318;
}
[data-theme="modern"] body { background: var(--bg); font-size: 17px; letter-spacing: .02em; }
[data-theme="modern"] h1 { font-size: 26px; letter-spacing: .04em; }
[data-theme="modern"] h2 { font-size: 15px; letter-spacing: .2em; color: var(--sub); margin-top: 28px; }
[data-theme="modern"] .hdr h1 {
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "BIZ UDPMincho", serif; font-size: 24px; letter-spacing: .12em;
}
[data-theme="modern"] button {
  border: 1px solid var(--line); border-radius: 18px; min-height: 52px; background: var(--card);
  transition: transform .12s, border-color .12s;
}
[data-theme="modern"] button:active { transform: scale(.98); }
[data-theme="modern"] button .small { font-size: 14px; color: var(--sub); }
[data-theme="modern"] button.primary {
  background: linear-gradient(135deg, #FF7A52, #E8452C); color: var(--on-accent); border: 0;
  min-height: 76px; font-size: 21px; box-shadow: 0 8px 24px rgba(232, 69, 44, .28);
}
[data-theme="modern"] button.primary .small { color: var(--on-accent); opacity: .85; }
[data-theme="modern"] .back { min-height: 44px; min-width: 0; padding: 6px 14px; border-radius: 999px; font-size: 15px; }
[data-theme="modern"] .hdr-btn { min-height: 44px; border-radius: 999px; font-size: 14px; }

[data-theme="modern"] .score-card { border: 1px solid var(--line); border-radius: 22px; background: var(--card); }
[data-theme="modern"] .score-row { gap: 18px; }
[data-theme="modern"] .ring {
  width: 116px; height: 116px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center; text-align: center;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--soft) 0);
  position: relative;
}
[data-theme="modern"] .ring::before { content: ""; position: absolute; inset: 9px; border-radius: 50%; background: var(--card); }
[data-theme="modern"] .ring > div { position: relative; }
[data-theme="modern"] .ring .sub { font-size: 12px; letter-spacing: .15em; }
[data-theme="modern"] .ring .score-num { font-size: 40px; }
[data-theme="modern"] .ring .score-num small { font-size: 15px; }
[data-theme="modern"] .score-side .meter { display: none; }
[data-theme="modern"] .score-side p { font-size: 15px; color: var(--sub); }
[data-theme="modern"] .score-side b { color: var(--ink); }
[data-theme="modern"] .streak {
  display: inline-block; margin-bottom: 8px; padding: 4px 12px; border-radius: 999px;
  background: rgba(233, 185, 73, .14); color: var(--gold); font-weight: 800; font-size: 14px;
}
[data-theme="modern"] .meter { height: 8px; border: 0; background: var(--soft); }

[data-theme="modern"] .tiles { gap: 10px; }
[data-theme="modern"] .tile { min-height: 112px; text-align: left; padding: 14px 16px; font-size: 19px; position: relative; }
[data-theme="modern"] .tile::before {
  content: attr(data-n); display: block; margin-bottom: 6px;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", serif; font-size: 14px; color: var(--gold); letter-spacing: .1em;
}

[data-theme="modern"] .guide {
  background: transparent; border-left: 3px solid var(--accent); border-radius: 0; padding: 4px 0 4px 12px; font-size: 15px; color: var(--sub);
}
[data-theme="modern"] .guide b { font-size: 12px; }
[data-theme="modern"] .passage, [data-theme="modern"] .tour { border: 1px solid var(--line); border-radius: 20px; }
[data-theme="modern"] .koujou rt { color: var(--gold); }
[data-theme="modern"] .reading.now { background: var(--soft); border-left-color: var(--accent); }
[data-theme="modern"] .note { font-size: 16px; border-radius: 14px; }
[data-theme="modern"] .bar { background: rgba(14, 13, 12, .88); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); }
[data-theme="modern"] .bar button { min-height: 52px; }
[data-theme="modern"] .grade { min-height: 72px; font-size: 15px; }
[data-theme="modern"] .grade.said { background: linear-gradient(135deg, #FF7A52, #E8452C); border: 0; }
[data-theme="modern"] .primary-soft { border-color: var(--accent); border-width: 1px; color: var(--accent); }
[data-theme="modern"] .choice[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
[data-theme="modern"] .cell { min-height: 56px; border-radius: 12px; font-size: 14px; }
[data-theme="modern"] .cell b { font-size: 20px; }
[data-theme="modern"] .legend { font-size: 15px; color: var(--sub); }
[data-theme="modern"] .chart div { background: linear-gradient(180deg, #FF7A52, #E8452C); }
[data-theme="modern"] .tag { font-size: 13px; letter-spacing: .15em; color: var(--gold); }

/* もどる＋速さ */
.topline { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.topline .back { margin-bottom: 0; }
.speed-chip { width: auto; min-height: 60px; padding: 8px 16px; border-color: var(--accent); color: var(--accent); white-space: nowrap; }
.sheet-shade {
  position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 640px; background: var(--bg); color: var(--ink);
  border-radius: 20px 20px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  display: grid; gap: 12px;
}
.sheet h2 { margin: 12px 0 0; }
.sheet .row3 { grid-template-columns: repeat(3, 1fr); }
[data-theme="modern"] .speed-chip { min-height: 44px; border-radius: 999px; font-size: 15px; }
[data-theme="modern"] .sheet { background: var(--card); }

/* もどる・速さは、スクロールしても上に残す */
.topline {
  position: sticky; top: 0; z-index: 4; background: var(--bg);
  margin: -8px -16px 8px; padding: max(8px, env(safe-area-inset-top)) 16px 8px;
  border-bottom: 1px solid transparent;
}
[data-theme="modern"] .topline { background: rgba(14, 13, 12, .9); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
