:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece5;
  --text: #1d1f24;
  --muted: #6b6f78;
  --line: #e2ded4;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --accent-soft: #dcefe8;
  --warn: #b4552d;
  --warn-soft: #f7e3d8;
  --again: #b4552d;
  --hard: #9a7a1f;
  --good: #1f6f5c;
  --easy: #2f5f9e;
  --radius: 16px;
  --tabbar-h: 58px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181d;
    --surface: #1f2228;
    --surface-2: #272b32;
    --text: #eceae4;
    --muted: #9aa0aa;
    --line: #30353d;
    --accent: #5cc0a2;
    --accent-ink: #0f1a16;
    --accent-soft: #1d3a32;
    --warn: #e58a62;
    --warn-soft: #3a2820;
    --again: #e58a62;
    --hard: #d4b34f;
    --good: #5cc0a2;
    --easy: #7fa8e0;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #16181d;
  --surface: #1f2228;
  --surface-2: #272b32;
  --text: #eceae4;
  --muted: #9aa0aa;
  --line: #30353d;
  --accent: #5cc0a2;
  --accent-ink: #0f1a16;
  --accent-soft: #1d3a32;
  --warn: #e58a62;
  --warn-soft: #3a2820;
  --again: #e58a62;
  --hard: #d4b34f;
  --good: #5cc0a2;
  --easy: #7fa8e0;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 20px) 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
  min-height: 100%;
}

h1 { font-size: 26px; line-height: 1.3; margin: 0 0 4px; letter-spacing: 0.01em; }
h2 { font-size: 17px; margin: 28px 0 10px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.stack > * + * { margin-top: 12px; }

button, .btn {
  font: inherit;
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  min-height: 48px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  touch-action: manipulation;
}
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.ghost { background: transparent; border: 1px solid var(--line); }
button:disabled { opacity: 0.5; cursor: default; }
button:focus-visible, a:focus-visible, textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.block { width: 100%; }

/* ---- ホーム */
.hero-progress { display: flex; align-items: center; gap: 16px; }
.ring { width: 96px; height: 96px; flex: none; }
.ring circle { fill: none; stroke-width: 10; }
.ring .track { stroke: var(--surface-2); }
.ring .bar { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset 0.4s; }
.ring text { fill: var(--text); font-size: 22px; font-weight: 700; text-anchor: middle; dominant-baseline: central; }
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.stat b { display: block; font-size: 22px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }

.menu-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; color: inherit; text-decoration: none;
}
.menu-item .step {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
  background: var(--surface-2); color: var(--muted);
}
.menu-item.done .step { background: var(--accent); color: var(--accent-ink); }
.menu-item .body { flex: 1; min-width: 0; }
.menu-item .title { font-weight: 600; }
.menu-item .sub { font-size: 13px; color: var(--muted); }
.menu-item .go { color: var(--muted); font-size: 20px; }
.menu-item.soon { opacity: 0.6; }

/* ---- 復習 */
.flash {
  min-height: 300px; display: flex; flex-direction: column; justify-content: center;
  text-align: center; gap: 14px; padding: 24px 18px;
}
.flash .tag { align-self: center; font-size: 12px; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.flash .tag.new { background: var(--accent-soft); color: var(--accent); }
.flash .tag.err { background: var(--warn-soft); color: var(--warn); }
.flash .prompt { font-size: 20px; font-weight: 600; }
.flash .answer { font-size: 22px; font-weight: 700; font-family: -apple-system, "SF Pro Text", "Helvetica Neue", sans-serif; }
.flash .note { font-size: 14px; color: var(--muted); }
.flash hr { border: 0; border-top: 1px dashed var(--line); width: 60%; margin: 4px auto; }
.ratings { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.ratings button { flex-direction: column; gap: 0; padding: 8px 4px; min-height: 60px; font-size: 14px; font-weight: 600; }
.ratings button small { font-size: 12px; font-weight: 400; opacity: 0.85; }
.ratings .r1 { background: var(--warn-soft); color: var(--again); }
.ratings .r2 { background: var(--surface-2); color: var(--hard); }
.ratings .r3 { background: var(--accent-soft); color: var(--good); }
.ratings .r4 { background: var(--surface-2); color: var(--easy); }
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 8px 0 16px; }
.progress > div { height: 100%; background: var(--accent); transition: width 0.3s; }
.speak { background: transparent; border: 1px solid var(--line); min-height: 40px; padding: 6px 14px; align-self: center; }

/* ---- 会話 */
.scenes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.scenes button { background: var(--surface); border: 1px solid var(--line); min-height: 56px; }
.chat { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.bubble { max-width: 85%; padding: 10px 14px; border-radius: 18px; white-space: pre-wrap; word-wrap: break-word; }
.bubble.ai { background: var(--surface); border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 6px; }
.bubble.me { background: var(--accent); color: var(--accent-ink); align-self: flex-end; border-bottom-right-radius: 6px; }
.bubble.pending { color: var(--muted); }
.bubble .say { margin-left: 6px; background: none; border: 0; min-height: 0; padding: 0 2px; color: var(--muted); font-size: 14px; }
.composer {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px);
  display: flex; gap: 8px; align-items: flex-end;
  background: var(--bg); padding-top: 8px;
}
.composer textarea {
  flex: 1; font: inherit; resize: none; min-height: 48px; max-height: 140px;
  padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text);
}
.chat-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.timer { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; }
.fix { border-left: 4px solid var(--warn); }
.fix .orig { text-decoration: line-through; text-decoration-color: var(--warn); color: var(--muted); }
.fix .corr { font-weight: 700; margin: 2px 0 6px; }
.fix .why { font-size: 14px; }
.fix .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.pill { font-size: 12px; padding: 2px 10px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); }

/* ---- 記録 */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 120px; padding-top: 8px; }
.bars .col { flex: 1; display: flex; flex-direction: column-reverse; min-width: 0; height: 100%; }
.bars .seg { width: 100%; }
.bars .seg.review { background: var(--accent); border-radius: 0 0 3px 3px; }
.bars .seg.chat { background: var(--easy); border-radius: 3px 3px 0 0; }
.bars .goal { position: relative; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.typelist { list-style: none; padding: 0; margin: 0; }
.typelist li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }

.notice { background: var(--warn-soft); color: var(--text); border-radius: 12px; padding: 12px 14px; font-size: 14px; }
.empty { text-align: center; padding: 40px 12px; color: var(--muted); }

/* ---- タブバー */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 11px;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.tabbar a.active { color: var(--accent); }

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