:root {
  --bg: #120e24;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-strong: rgba(255, 255, 255, 0.1);
  --line: rgba(255, 255, 255, 0.14);
  --text: #f4f1ff;
  --muted: #a69fc9;
  --accent: #ff4f9a;
  --accent2: #36d6ff;
  --good: #7cf29c;
  --bad: #ff6b7d;
  --gold: #ffd25e;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(120% 60% at 50% -10%, #3a2a85 0%, transparent 60%),
    radial-gradient(80% 50% at 100% 100%, #4a1846 0%, transparent 60%),
    var(--bg);
}

button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }
button:disabled { cursor: default; }

#app {
  max-width: 520px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  position: relative;
}

.screen { display: none; height: 100%; }
.screen.active { display: flex; flex-direction: column; }
.screen > * { flex-shrink: 0; }
.hidden { display: none !important; }

#screen-title, #screen-result {
  overflow-y: auto;
  gap: 18px;
  padding: max(20px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

/* ===== タイトル ===== */
.logo { text-align: center; padding-top: 8px; }
.logo-sub { font-size: 13px; letter-spacing: 0.2em; color: var(--accent2); }
.logo h1 {
  margin: 4px 0 6px;
  font-size: 44px;
  font-weight: 900;
  letter-spacing: 0.06em;
  background: linear-gradient(90deg, var(--accent), #b98bff 50%, var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline { margin: 0; font-size: 14px; color: var(--muted); }

.group { display: flex; flex-direction: column; gap: 10px; }
.group-label { font-size: 13px; font-weight: 700; color: var(--muted); }
.hint { margin: 0; font-size: 12.5px; line-height: 1.6; color: var(--muted); }

.seg { display: flex; padding: 4px; gap: 4px; border-radius: var(--radius); background: var(--panel); }
.seg button {
  flex: 1;
  min-width: 0;
  padding: 10px 2px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-weight: 700;
  font-size: 13.5px;
  color: var(--muted);
  white-space: nowrap;
}
.seg button[aria-pressed="true"] { background: var(--panel-strong); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.tabs button { font-size: 14px; position: relative; }
.tabs button[aria-pressed="true"] { background: var(--accent); color: #fff; box-shadow: none; }
.badge {
  display: inline-block;
  min-width: 18px;
  margin-left: 3px;
  padding: 0 5px;
  border-radius: 99px;
  background: var(--gold);
  color: #3a2600;
  font-size: 11px;
  line-height: 18px;
}

.chip-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.chip-group-name { font-size: 12px; font-weight: 800; color: var(--accent2); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 8px 12px;
  border: 1.5px solid transparent;
  border-radius: 999px;
  background: var(--panel);
  font-size: 13.5px;
  font-weight: 700;
}
.chip[aria-pressed="true"] { border-color: var(--accent); background: rgba(255, 79, 154, 0.16); }
.chip.mix { color: var(--gold); }

.level-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.level-list.one-col { grid-template-columns: 1fr; }
.level {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 12px 14px;
  text-align: left;
  border: 2px solid transparent;
  border-radius: var(--radius);
  background: var(--panel);
}
.level[aria-pressed="true"] { border-color: var(--accent); background: rgba(255, 79, 154, 0.12); }
.level-name { font-size: 15px; font-weight: 800; }
.level-desc { font-size: 12px; color: var(--muted); }
.course-best { margin: 0; font-size: 12px; font-weight: 700; color: var(--gold); }

.explain, .howto { padding: 12px 14px; border-radius: var(--radius); background: var(--panel); font-size: 14px; }
.explain summary, .howto summary { font-weight: 700; cursor: pointer; }
.explain-body p { margin: 8px 0 0; line-height: 1.7; }
.howto ol { margin: 10px 0; padding-left: 1.3em; line-height: 1.7; }

.settings .setting-row { display: flex; flex-direction: column; gap: 6px; }
.settings .toggle-row { flex-direction: row; align-items: center; justify-content: space-between; }
.setting-name { font-size: 13px; font-weight: 700; }

.toggle {
  min-width: 64px;
  padding: 8px 14px;
  border: 0;
  border-radius: 999px;
  background: var(--panel-strong);
  font-weight: 800;
  color: var(--muted);
}
.toggle[aria-pressed="true"] { background: var(--accent2); color: #08243a; }

.primary, .secondary {
  padding: 14px 18px;
  border: 0;
  border-radius: var(--radius);
  font-weight: 800;
  font-size: 16px;
}
.primary {
  background: linear-gradient(90deg, var(--accent), #a35cff);
  color: #fff;
  box-shadow: 0 8px 24px rgba(255, 79, 154, 0.35);
}
.primary:disabled { opacity: 0.4; box-shadow: none; }
.primary.big { padding: 18px; font-size: 20px; letter-spacing: 0.1em; }
.primary:active, .secondary:active { transform: scale(0.98); }
.secondary { background: var(--panel-strong); }

.ad-slot {
  display: grid;
  place-items: center;
  min-height: 100px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--muted);
}
body.no-ad-placeholder .ad-slot { display: none; }

.title-footer { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 16px; font-size: 13px; }
.title-footer a { color: var(--muted); }

/* ===== プレイ画面 ===== */
#screen-game { position: relative; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }

.hud {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 12px 6px;
}
.hud-score { display: flex; flex-direction: column; min-width: 70px; }
.hud-label { font-size: 10px; letter-spacing: 0.15em; color: var(--muted); }
#score { font-size: 20px; font-weight: 900; font-variant-numeric: tabular-nums; }
.hud-progress { flex: 1; height: 6px; border-radius: 99px; background: var(--panel-strong); overflow: hidden; }
#progress-bar { width: 0; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); }
.hud-btn {
  height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 12px;
  background: var(--panel-strong);
  font-size: 13px;
  font-weight: 800;
}
.hud-btn[aria-pressed="true"] { background: var(--accent2); color: #08243a; }
.icon-btn {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border: 0; border-radius: 12px;
  background: var(--panel-strong);
}

.stage-wrap { position: relative; flex: 1 1 auto; min-height: 0; }
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* 判定ラインのすぐ下に置く（タップはパネルを通り抜けてレーンに届く） */
.sentence-panel {
  position: absolute;
  left: 10px;
  right: 10px;
  min-height: 104px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: rgba(14, 10, 32, 0.9);
  box-shadow: inset 0 0 0 1px var(--line);
  pointer-events: none;
}
.ja-line { font-size: 15px; font-weight: 700; line-height: 1.5; }
.ja-line .count { margin-right: 6px; font-size: 11px; color: var(--accent2); font-variant-numeric: tabular-nums; }
.en-line { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; font-size: 16px; font-weight: 700; }
.en-line .w { padding: 1px 6px; border-radius: 6px; line-height: 1.5; }
.en-line .blank { height: 1.5em; background: var(--panel-strong); }
.en-line .blank.focus { box-shadow: inset 0 -3px 0 var(--gold); }
.en-line .blank.next { box-shadow: inset 0 0 0 2px var(--accent2); animation: blink 0.8s ease-in-out infinite alternate; }
.en-line .ok { background: rgba(124, 242, 156, 0.16); color: var(--good); }
.en-line .ng { background: rgba(255, 107, 125, 0.18); color: var(--bad); text-decoration: underline wavy; text-underline-offset: 3px; }
@keyframes blink { from { opacity: 0.55; } to { opacity: 1; } }

.explain-box {
  position: absolute;
  top: 6px;
  left: 10px;
  right: 10px;
  overflow: hidden;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: rgba(14, 10, 32, 0.88);
  box-shadow: inset 0 0 0 1px rgba(54, 214, 255, 0.4);
  font-size: 13px;
  line-height: 1.6;
  pointer-events: none;
}
.explain-box .eb-title { font-size: 11px; font-weight: 800; color: var(--accent2); }
.explain-box p { margin: 4px 0 0; }

.overlay {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(10, 6, 24, 0.75);
  backdrop-filter: blur(4px);
}
.overlay-box { display: flex; flex-direction: column; gap: 12px; width: min(280px, 80%); text-align: center; }
.overlay-box h2 { margin: 0 0 8px; }

/* ===== リザルト ===== */
.result-head { text-align: center; }
.result-level { font-size: 13px; color: var(--muted); }
.rank {
  font-size: 96px;
  font-weight: 900;
  line-height: 1.1;
  background: linear-gradient(180deg, var(--gold), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.rank-msg { font-size: 15px; font-weight: 700; }
.r-score { margin-top: 6px; font-size: 30px; font-weight: 900; font-variant-numeric: tabular-nums; }
.new { margin-left: 8px; font-size: 13px; color: var(--gold); vertical-align: middle; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats div {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 4px;
  border-radius: 12px;
  background: var(--panel);
}
.stats span { font-size: 11px; color: var(--muted); }
.stats b { font-size: 18px; font-variant-numeric: tabular-nums; }

.btn-col { display: flex; flex-direction: column; gap: 10px; }
.btn-row { display: flex; gap: 10px; }
.btn-row > * { flex: 1; }

.list-title { margin: 6px 0 0; font-size: 16px; }
.list-title small { display: block; margin-top: 2px; font-size: 12px; font-weight: 400; color: var(--muted); }
.sentence-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.sentence-list li {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--panel);
  border-left: 3px solid var(--good);
}
.sentence-list li.has-miss { border-left-color: var(--bad); }
.sentence-list li > div { flex: 1; min-width: 0; }
.speak { flex-shrink: 0; width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--panel-strong); font-size: 18px; }
.s-en { font-weight: 700; line-height: 1.5; }
.s-en mark { padding: 0 3px; border-radius: 4px; background: rgba(255, 107, 125, 0.22); color: var(--bad); }
.s-ja { font-size: 13px; color: var(--muted); }
.s-note { margin-top: 6px; font-size: 13px; }
.s-note summary { color: var(--accent2); font-weight: 700; cursor: pointer; }
.s-note p { margin: 4px 0 0; line-height: 1.6; }
