:root {
  color-scheme: light dark;
  --bg: #f5f5f3;
  --surface: #ffffff;
  --surface-2: #ececea;
  --text: #171819;
  --muted: #65686c;
  --line: #d7d8d8;
  --accent: #24272b;
  --accent-text: #ffffff;
  --l1: #eaf0f4;
  --l2: #f2eee5;
  --l3: #edf2e9;
  --danger: #8d3030;
  --warn: #7a5b19;
  --good: #295f44;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.04);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
}
:root[data-theme="dark"] {
  --bg: #111214;
  --surface: #191b1e;
  --surface-2: #23262a;
  --text: #f1f2f3;
  --muted: #a3a6aa;
  --line: #34383d;
  --accent: #f1f2f3;
  --accent-text: #151618;
  --l1: #202b34;
  --l2: #302b22;
  --l3: #243026;
  --danger: #f0a1a1;
  --warn: #e6c475;
  --good: #8dd1ac;
  --shadow: none;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111214;
    --surface: #191b1e;
    --surface-2: #23262a;
    --text: #f1f2f3;
    --muted: #a3a6aa;
    --line: #34383d;
    --accent: #f1f2f3;
    --accent-text: #151618;
    --l1: #202b34;
    --l2: #302b22;
    --l3: #243026;
    --danger: #f0a1a1;
    --warn: #e6c475;
    --good: #8dd1ac;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin:0; min-height:100%; background:var(--bg); color:var(--text); }
body { min-width: 280px; overflow-x:hidden; -webkit-text-size-adjust:100%; }
button, input, select { font: inherit; }
button { color: inherit; }
a { color: inherit; }
.app-shell { min-height:100dvh; max-width:720px; margin:0 auto; }
.topbar {
  position:sticky; top:0; z-index:20;
  padding: calc(env(safe-area-inset-top) + 12px) 18px 10px;
  min-height:72px; display:flex; align-items:flex-end; justify-content:space-between;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-bottom:1px solid color-mix(in srgb, var(--line) 70%, transparent);
}
.topbar h1 { margin:2px 0 0; font-size:22px; line-height:1.2; letter-spacing:-.02em; }
.eyebrow { color:var(--muted); font-size:12px; font-weight:700; letter-spacing:.08em; }
.main { padding:18px 16px calc(92px + env(safe-area-inset-bottom)); outline:none; }
.bottom-nav {
  position:fixed; z-index:30; left:50%; transform:translateX(-50%); bottom:0;
  width:min(100%,720px); display:grid; grid-template-columns:repeat(5,1fr);
  padding:7px 6px calc(7px + env(safe-area-inset-bottom));
  background:color-mix(in srgb, var(--surface) 94%, transparent); border-top:1px solid var(--line);
  backdrop-filter:blur(20px); -webkit-backdrop-filter:blur(20px);
}
.nav-item { min-height:52px; border:0; background:transparent; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:2px; color:var(--muted); font-size:11px; border-radius:12px; }
.nav-item.active { color:var(--text); font-weight:700; background:var(--surface-2); }
.nav-icon { font-size:20px; line-height:1; }
.card, .mode-card, .answer-card, .reader-card, .metric-card, .search-result, .settings-card {
  background:var(--surface); border:1px solid var(--line); border-radius:var(--radius); box-shadow:var(--shadow);
}
.card { padding:16px; margin-bottom:14px; }
.hero-card { padding:18px; margin-bottom:16px; background:var(--surface); border:1px solid var(--line); border-radius:20px; }
.hero-top { display:flex; justify-content:space-between; gap:12px; align-items:flex-start; }
.hero-card h2 { margin:3px 0 5px; font-size:24px; }
.subtle { color:var(--muted); font-size:14px; line-height:1.55; }
.metrics { display:grid; grid-template-columns:1fr 1fr; gap:10px; margin:12px 0 18px; }
.metric-card { padding:14px; min-height:86px; }
.metric-value { font-size:24px; font-weight:800; letter-spacing:-.03em; }
.metric-label { margin-top:4px; color:var(--muted); font-size:13px; }
.section-title { display:flex; align-items:center; justify-content:space-between; margin:22px 2px 10px; }
.section-title h2 { margin:0; font-size:18px; }
.mode-grid { display:grid; grid-template-columns:1fr; gap:10px; }
.mode-card { padding:15px 16px; width:100%; text-align:left; border:1px solid var(--line); min-height:70px; }
.mode-card:active { transform:translateY(1px); }
.mode-title { font-weight:800; font-size:17px; }
.mode-desc { margin-top:4px; color:var(--muted); font-size:13px; line-height:1.4; }
.primary, .secondary, .ghost, .rating, .chip, .icon-button {
  min-height:44px; border-radius:12px; border:1px solid var(--line); padding:10px 14px; font-weight:700;
}
.primary { background:var(--accent); color:var(--accent-text); border-color:var(--accent); }
.secondary { background:var(--surface-2); color:var(--text); }
.ghost { background:transparent; color:var(--text); }
.icon-button { width:44px; padding:0; background:var(--surface); display:grid; place-items:center; }
.button-row { display:flex; gap:8px; flex-wrap:wrap; }
.button-row > button { flex:1 1 auto; }
.full { width:100%; }
.hidden { display:none !important; }
.study-wrap { min-height:calc(100dvh - 180px); display:flex; flex-direction:column; gap:12px; }
.progress-line { display:flex; justify-content:space-between; align-items:center; color:var(--muted); font-size:13px; }
.progress-track { height:5px; background:var(--surface-2); border-radius:99px; overflow:hidden; }
.progress-fill { height:100%; background:var(--accent); width:0%; transition:width .2s; }
.study-card { flex:1; min-height:330px; background:var(--surface); border:1px solid var(--line); border-radius:20px; padding:20px 18px; box-shadow:var(--shadow); display:flex; flex-direction:column; }
.card-kicker { display:flex; align-items:center; justify-content:space-between; gap:8px; color:var(--muted); font-size:13px; font-weight:700; }
.theme-id { display:inline-flex; align-items:center; min-height:30px; padding:4px 8px; border-radius:8px; background:var(--surface-2); color:var(--text); font-weight:800; }
.study-card h2 { margin:16px 0 8px; font-size:21px; line-height:1.45; }
.prompt { margin:16px 0; font-size:17px; line-height:1.8; }
.level-box { border-radius:14px; padding:14px; margin:12px 0; line-height:1.8; overflow-wrap:anywhere; }
.level1 { background:var(--l1); }
.level2 { background:var(--l2); }
.level3 { background:var(--l3); }
.answer-text { font-family:"Hiragino Mincho ProN", "Yu Mincho", serif; font-size:18px; line-height:1.9; letter-spacing:.01em; overflow-wrap:anywhere; }
.answer-actions { display:flex; gap:8px; margin-top:12px; }
.spacer { flex:1; }
.rating-row { display:grid; grid-template-columns:repeat(4,1fr); gap:7px; margin-top:10px; }
.rating { min-height:58px; padding:6px 3px; background:var(--surface); font-size:12px; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:2px; }
.rating strong { font-size:18px; }
.rating[data-rating="forgot"] strong { color:var(--danger); }
.rating[data-rating="vague"] strong { color:var(--warn); }
.rating[data-rating="almost"] strong { color:var(--good); }
.rating[data-rating="perfect"] strong { color:var(--text); }
.nav-row { display:grid; grid-template-columns:1fr 1fr; gap:8px; }
.timer { display:flex; align-items:center; justify-content:space-between; gap:10px; padding:10px 12px; border-radius:12px; background:var(--surface-2); }
.timer-value { font-variant-numeric:tabular-nums; font-size:22px; font-weight:800; min-width:64px; }
.timer-controls { display:flex; gap:6px; }
.timer-controls button { min-height:44px; border:1px solid var(--line); border-radius:10px; background:var(--surface); }
.sheet-backdrop { position:fixed; z-index:100; inset:0; background:rgba(0,0,0,.42); display:flex; align-items:flex-end; }
.sheet { width:min(100%,720px); margin:0 auto; max-height:86dvh; overflow:auto; background:var(--surface); border-radius:20px 20px 0 0; padding:18px 16px calc(18px + env(safe-area-inset-bottom)); }
.sheet h2 { margin:2px 0 4px; }
.session-grid { display:grid; grid-template-columns:repeat(2,1fr); gap:8px; margin:14px 0; }
.session-grid button { min-height:50px; border:1px solid var(--line); border-radius:12px; background:var(--surface-2); font-weight:700; }
.chips { display:flex; gap:8px; overflow:auto; padding-bottom:4px; scrollbar-width:none; }
.chips::-webkit-scrollbar { display:none; }
.chip { min-height:38px; padding:7px 11px; white-space:nowrap; background:var(--surface); font-size:13px; }
.chip.active { background:var(--accent); color:var(--accent-text); border-color:var(--accent); }
.reader-chapter { margin-bottom:12px; }
.reader-chapter > button { width:100%; min-height:54px; text-align:left; border:1px solid var(--line); border-radius:14px; padding:12px 14px; background:var(--surface); font-weight:800; font-size:16px; }
.reader-theme { border:1px solid var(--line); border-radius:14px; background:var(--surface); margin:10px 0; overflow:hidden; }
.reader-theme summary { min-height:54px; padding:14px; display:flex; align-items:center; gap:8px; font-weight:800; cursor:pointer; }
.reader-body { padding:0 14px 16px; border-top:1px solid var(--line); }
.reader-body h4 { margin:18px 0 6px; font-size:14px; color:var(--muted); }
.reader-answer { margin:8px 0 12px; padding:12px; border-radius:12px; background:var(--l2); font-family:"Hiragino Mincho ProN", "Yu Mincho", serif; line-height:1.8; }
.causal-flow { margin:10px 0; display:flex; flex-direction:column; align-items:stretch; gap:4px; }
.causal-step { text-align:center; padding:11px; border:1px solid var(--line); border-radius:10px; background:var(--surface-2); line-height:1.55; }
.causal-arrow { text-align:center; color:var(--muted); font-size:20px; }
.search-bar { position:sticky; top:82px; z-index:10; background:var(--bg); padding:0 0 10px; }
.search-input { width:100%; min-height:48px; border:1px solid var(--line); border-radius:14px; padding:10px 14px; background:var(--surface); color:var(--text); font-size:16px; }
.search-result { padding:14px; margin:10px 0; }
.search-result h3 { margin:4px 0 8px; font-size:16px; }
.search-result p { margin:5px 0; line-height:1.65; overflow-wrap:anywhere; }
.result-type { color:var(--muted); font-size:12px; font-weight:700; }
.source-page { color:var(--muted); font-size:12px; }
.settings-card { padding:15px; margin-bottom:12px; }
.settings-card h2 { margin:0 0 12px; font-size:17px; }
.field { display:grid; grid-template-columns:1fr 110px; align-items:center; gap:10px; margin:10px 0; }
.field input, .field select { min-height:44px; width:100%; border:1px solid var(--line); border-radius:10px; background:var(--surface-2); color:var(--text); padding:8px 10px; }
.stat-list { display:grid; gap:8px; }
.stat-row { display:flex; justify-content:space-between; gap:10px; padding:10px 0; border-bottom:1px solid var(--line); }
.stat-row:last-child { border-bottom:0; }
.chapter-progress { margin:10px 0 14px; }
.chapter-progress-head { display:flex; justify-content:space-between; gap:8px; font-size:14px; margin-bottom:5px; }
.toast { position:fixed; z-index:200; left:50%; transform:translate(-50%,12px); bottom:calc(86px + env(safe-area-inset-bottom)); background:var(--accent); color:var(--accent-text); padding:10px 14px; border-radius:12px; opacity:0; pointer-events:none; transition:.2s; max-width:calc(100% - 32px); font-size:14px; }
.toast.show { opacity:1; transform:translate(-50%,0); }
.cloze { display:inline-block; min-width:3.4em; border-bottom:2px solid currentColor; color:transparent; user-select:none; }
.onboarding-step { padding:14px 0; border-bottom:1px solid var(--line); display:flex; gap:12px; align-items:flex-start; }
.onboarding-step:last-child { border-bottom:0; }
.step-no { flex:0 0 30px; height:30px; border-radius:50%; background:var(--accent); color:var(--accent-text); display:grid; place-items:center; font-weight:800; }
.empty { text-align:center; padding:34px 18px; color:var(--muted); }
.pdf-link { display:flex; align-items:center; justify-content:space-between; gap:10px; text-decoration:none; min-height:50px; padding:10px 12px; border:1px solid var(--line); border-radius:12px; background:var(--surface-2); }
.small { font-size:12px; color:var(--muted); }
hr { border:0; border-top:1px solid var(--line); margin:18px 0; }
@media (min-width:560px) {
  .mode-grid { grid-template-columns:1fr 1fr; }
  .metrics { grid-template-columns:repeat(4,1fr); }
}
@media (max-width:390px) {
  .main { padding-left:14px; padding-right:14px; }
  .study-card { padding-left:16px; padding-right:16px; }
  .answer-text { font-size:17px; }
  .rating { font-size:11px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior:auto !important; transition:none !important; } }
.filter-selects { display:grid; grid-template-columns:1fr 1fr; gap:8px; margin-top:8px; }
.filter-selects select { width:100%; min-height:44px; border:1px solid var(--line); border-radius:12px; padding:8px 10px; background:var(--surface); color:var(--text); min-width:0; }
