:root {
  --bg: #f4f4f4;
  --surface: #ffffff;
  --ink: #1a1a1a;
  --ink-2: #555555;
  --muted: #8a8a8a;
  --line: #e6e6e6;
  --accent: #ffd400;
  --accent-ink: #1a1a1a;
  --blue: #2b5ca8;
  --blue-bg: #e9eef7;
  --green: #217a3c;
  --red: #b3261e;
  /* グラフの棒（記録画面） */
  --bar: #f6d447;
  --bar-strong: #f2b800;
  --radius: 18px;
  --tabbar-h: 64px;
  font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", system-ui, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}
body.no-tabbar { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
#app { max-width: 640px; margin: 0 auto; padding: 0 16px; padding-top: env(safe-area-inset-top); }
button, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4, p { margin: 0; }
p { line-height: 1.7; }
.muted { color: var(--muted); font-size: 0.9em; }
[hidden] { display: none !important; }

/* ---- 共通パーツ ---- */
.card {
  display: block;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
  margin: 14px 0;
}
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-title { font-weight: 700; }
.card-head .muted, .card-head .link { margin-left: auto; }
.row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 0 20px;
  border: none; border-radius: 999px;
  background: #ececec; font-weight: 700;
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: var(--surface); border: 1px solid var(--line); }
.btn-small { min-height: 36px; padding: 0 14px; font-size: 0.9em; }
.btn-wide { width: 100%; margin-top: 14px; }
.link { border: none; background: none; color: var(--ink-2); font-size: 0.9em; }
.icon-btn { border: none; background: none; color: var(--muted); font-size: 1.1em; padding: 4px 8px; min-width: 36px; min-height: 36px; }
.pill { border: 1px solid var(--line); background: #f7f7f7; border-radius: 999px; padding: 8px 16px; }

.tags { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.tag { background: #ececec; border-radius: 8px; padding: 3px 10px; font-size: 0.85em; }
.tag-level { background: var(--surface); border: 1px solid var(--line); color: var(--blue); }

.verdict { display: inline-block; border-radius: 8px; padding: 3px 10px; font-size: 0.85em; font-weight: 700; white-space: nowrap; }
.verdict.small { font-size: 0.75em; padding: 2px 8px; }
.v-correct { background: var(--accent); color: var(--accent-ink); }
.v-improvable { background: var(--blue); color: #fff; }
.v-incorrect { background: var(--red); color: #fff; }

.toast {
  position: fixed; left: 50%; bottom: calc(110px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #333; color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 50; max-width: 90vw;
}

/* ---- 下部タブ ---- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255, 255, 255, 0.95); border-top: 1px solid var(--line);
}
.tabbar a { flex: 1; display: flex; align-items: center; justify-content: center; gap: 4px; color: var(--muted); font-weight: 700; }
.tabbar a.active { color: var(--ink); box-shadow: inset 0 3px 0 var(--accent); }
.badge { background: var(--red); color: #fff; border-radius: 999px; font-size: 0.7em; padding: 1px 7px; }

/* ---- ホーム ---- */
.top-tabs { display: flex; gap: 22px; border-bottom: 1px solid var(--line); padding-top: 14px; overflow-x: auto; }
.top-tabs a { padding: 10px 2px; color: var(--muted); font-weight: 700; white-space: nowrap; border-bottom: 4px solid transparent; }
.top-tabs a.active { color: var(--ink); border-color: var(--accent); }
.progress-row { display: flex; align-items: center; gap: 14px; }
.meter { position: relative; flex: 1; height: 28px; border-radius: 999px; background: #efefef; overflow: hidden; }
.meter-fill { height: 100%; background: var(--accent); border-radius: 999px; }
.meter-text { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-weight: 700; }
.review-callout { display: flex; justify-content: space-between; font-weight: 700; border: 2px solid var(--accent); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.filter { border: none; background: #ececec; border-radius: 999px; padding: 8px 12px; max-width: 100%; }
.list-row {
  display: flex; align-items: center; gap: 10px; width: 100%;
  border: none; background: none; text-align: left;
  padding: 14px 0; border-bottom: 1px solid var(--line);
}
.list-row:last-child { border-bottom: none; }
.list-row.static { cursor: default; justify-content: space-between; }
.list-main { flex: 1; min-width: 0; display: grid; gap: 6px; }
.list-main .tags { justify-content: flex-start; }
.resume {
  position: fixed; right: 16px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px); z-index: 15;
  display: flex; align-items: center; gap: 6px;
}
.resume-spacer { height: 64px; }
.resume .btn { box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15); }
.resume .icon-btn { background: var(--surface); border-radius: 999px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12); }
/* 場面別（ジャンル一覧） */
.group-title { font-size: 1.05rem; margin: 22px 2px 10px; }
.scene-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.scene-card { background: var(--surface); border-radius: var(--radius); padding: 14px 12px; display: flex; flex-direction: column; gap: 6px; }
.scene-card.empty { opacity: 0.6; }
.scene-name { font-weight: 800; font-size: 1rem; text-align: center; }
.scene-desc { color: var(--muted); font-size: 0.72rem; line-height: 1.5; min-height: 3em; }
.level-rows { display: grid; gap: 6px; margin-top: 2px; }
.level-row { display: grid; grid-template-columns: 3.3em 1fr; align-items: center; gap: 6px; border: none; background: none; padding: 2px 0; min-height: 30px; }
.level-row:disabled { cursor: default; }
.level-name { font-weight: 700; font-size: 0.8rem; text-align: left; }
.lv1 { color: var(--blue); }
.lv2 { color: #b35c00; }
.lv3 { color: var(--red); }
.lv4 { color: #7a1fa2; }
.level-track { position: relative; height: 22px; background: #ececec; border-radius: 999px; overflow: hidden; }
.level-fill { position: absolute; inset: 0 auto 0 0; background: var(--accent); }
.level-count { position: relative; display: flex; align-items: center; justify-content: center; height: 100%; font-size: 0.78rem; font-weight: 700; font-variant-numeric: tabular-nums; }
@media (min-width: 560px) {
  .scene-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.level-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #f7f7f7; border-radius: 999px; padding: 8px 14px; }
.chip-on { background: var(--accent); border-color: var(--accent); font-weight: 700; }

/* ---- 出題・添削 ---- */
.quiz-head { text-align: center; padding: 12px 0 16px; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.quiz-nav { display: flex; align-items: center; justify-content: center; position: relative; }
.back {
  position: absolute; left: 0; width: 44px; height: 44px; border-radius: 999px; background: var(--surface);
  display: flex; align-items: center; justify-content: center; font-size: 1.6em; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}
.pager { display: flex; align-items: center; gap: 12px; background: var(--surface); border-radius: 999px; padding: 6px 10px; font-size: 1.1em; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08); }
.pager-btn { border: none; background: none; color: var(--ink-2); font-size: 0.8em; min-width: 32px; min-height: 32px; }
.pager-btn:disabled { opacity: 0.25; }
.ja { font-size: 1.35rem; line-height: 1.5; }
.hint { color: var(--muted); font-style: italic; }
.answer-area { display: grid; gap: 12px; padding-top: 16px; }
.answer-area .btn-small { justify-self: start; }
.answer-input {
  width: 100%; min-height: 160px; border: none; background: transparent; resize: vertical;
  font-size: 1.4rem; line-height: 1.5; outline: none; padding: 4px 0;
}
.examples { background: var(--surface); border-radius: 12px; padding: 12px 14px; display: grid; gap: 4px; }
.examples-title { font-weight: 700; font-size: 0.85em; color: var(--muted); }
.action-bar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(12px + env(safe-area-inset-bottom) + var(--kb, 0px)); z-index: 20;
  width: min(608px, calc(100% - 32px));
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: rgba(240, 240, 240, 0.96); border-radius: 26px; padding: 8px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.1);
}
.action-bar .btn { flex: 1; padding: 0 10px; }
.action-bar .btn-primary { flex: 1.2; }
.mic {
  width: 64px; height: 64px; flex: none; border: none; border-radius: 999px; background: var(--accent); font-size: 1.5em;
  margin-top: -24px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.mic.on { outline: 4px solid rgba(255, 212, 0, 0.45); animation: pulse 1s infinite alternate; }
@keyframes pulse { to { transform: scale(1.06); } }

.result { padding-top: 4px; }
.sentence { display: flex; align-items: flex-start; gap: 6px; font-size: 1.35rem; line-height: 1.5; margin: 6px 0 12px; }
.speak-row { display: flex; gap: 8px; margin-bottom: 12px; }
.summary { border-top: 1px solid var(--line); padding-top: 12px; }
.good h3 { color: var(--green); margin: 18px 0 8px; }
.good ul { margin: 0; padding-left: 1.2em; line-height: 1.7; }
.improve h3 { color: var(--blue); margin: 20px 0 8px; }
.point { margin: 10px 0 14px; }
.point h4 { color: var(--blue); margin-bottom: 4px; }
.say { background: var(--blue-bg); border-radius: 12px; padding: 10px 14px; margin-top: 8px; font-size: 1.1em; }
.say-label { color: var(--blue); font-weight: 700; font-size: 0.85em; }
.alt + .alt { border-top: 1px solid var(--line); padding-top: 12px; }
.ask-input { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; resize: vertical; }
.ask-log { display: grid; gap: 8px; margin-bottom: 10px; }
.ask-q { justify-self: end; background: #f1f1f1; border-radius: 12px; padding: 8px 12px; }
.ask-a { background: var(--blue-bg); border-radius: 12px; padding: 10px 12px; line-height: 1.7; white-space: pre-wrap; }

.page-head { padding: 20px 0 4px; }
.page-head h1 { font-size: 1.4rem; }
.summary-counts { display: flex; justify-content: space-around; text-align: center; }
.big { font-size: 2rem; font-weight: 800; }
.big-line { display: flex; align-items: baseline; gap: 6px; margin-bottom: 8px; }

/* ---- タイムアタック ---- */
.ta-head { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 14px 0 8px; position: relative; }
.ta-head .back { top: 12px; }
.ta-time { font-size: 2.4rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.ta-bar { height: 8px; background: #e4e4e4; border-radius: 999px; overflow: hidden; }
.ta-bar-fill { height: 100%; width: 100%; background: var(--accent); }
.ta-question { display: grid; gap: 10px; text-align: center; padding-top: 18px; }
.ta-play { display: grid; gap: 10px; }
.ta-input { min-height: 110px; text-align: left; background: var(--surface); border-radius: 14px; padding: 12px; }
.ta-detail { padding-bottom: 8px; }
.ta-detail .card { background: #fafafa; margin: 8px 0; }

/* ---- 記録 ---- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 14px; }
.tile { background: var(--surface); border-radius: var(--radius); padding: 14px 16px; }
.tile-label { color: var(--ink-2); font-size: 0.85em; }
.tile-value { font-size: 1.8rem; font-weight: 800; margin: 2px 0; font-variant-numeric: tabular-nums; }
.tile-sub { color: var(--muted); font-size: 0.8em; }
/* 回答数の推移（棒グラフ） */
.trend {
  display: flex; align-items: flex-end; gap: 6px;
  height: 200px; padding-top: 12px; border-bottom: 2px solid #d9d9d9;
}
.trend-col { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; }
.trend-val { font-weight: 800; font-size: 1.05rem; margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.trend-bar { width: 58%; max-width: 40px; background: var(--bar); border-radius: 6px 6px 0 0; }
.trend-labels { display: flex; gap: 6px; margin-top: 10px; }
.trend-labels div { flex: 1; min-width: 0; text-align: center; font-size: 0.85rem; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; letter-spacing: -0.02em; }
.trend-labels .current { color: var(--ink); font-weight: 700; }
.trend-total { text-align: right; margin-top: 10px; }
.seg { display: flex; background: #ececec; border-radius: 999px; padding: 5px; margin-top: 14px; }
.seg button { flex: 1; border: none; background: none; border-radius: 999px; padding: 10px 0; color: var(--muted); font-weight: 700; font-size: 1.05rem; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12); }
.bars { display: grid; gap: 12px; }
.bar-row { display: grid; grid-template-columns: 3em 1fr 7.5em; align-items: center; gap: 10px; }
.bar-track { height: 14px; background: #efefef; border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--bar-strong); border-radius: 0 4px 4px 0; }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: 0.9em; }

@media (min-width: 560px) {
  .tiles { grid-template-columns: repeat(4, 1fr); }
}
