:root {
  --navy-deep: #0a1018;
  --navy-base: #121c2a;
  --navy-band: #162233;
  --navy-surface: #1a2738;
  --navy-surface-alt: #243448;
  --blue-border: #2e4a6e;
  --bg: var(--navy-base);
  --surface: var(--navy-surface);
  --surface-2: var(--navy-surface-alt);
  --border: var(--blue-border);
  --text: #f7f8fa;
  --text-muted: #b8c0cc;
  --accent: #2563eb;
  --accent-bright: #60a5fa;
  --accent-soft: rgba(37, 99, 235, 0.2);
  --accent-glow: rgba(37, 99, 235, 0.28);
  --success: #66bb6a;
  --warn: #ffb300;
  --error: #ef5350;
  --recording: #e53935;
  --glass: rgba(26, 39, 56, 0.9);
  --radius: 16px;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.32), 0 0 0 1px rgba(37, 99, 235, 0.12);
  --page-max: 720px;
  --tab-h: 64px;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --touch-min: 44px;
  --motion: 220ms ease;
  --focus-ring: 0 0 0 2px var(--navy-deep), 0 0 0 4px var(--accent-bright);
}

*, *::before, *::after { box-sizing: border-box; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "DM Sans", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: -0.01em;
  color: var(--text);
  background:
    radial-gradient(ellipse 90% 55% at 50% -18%, rgba(37, 99, 235, 0.22), transparent 60%),
    linear-gradient(160deg, var(--navy-deep), var(--navy-base) 38%, var(--navy-band) 55%, var(--navy-deep));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

.speaking-app.page {
  max-width: var(--page-max);
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
}

.speaking-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.speaking-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-bottom: calc(var(--tab-h) + 12px + env(safe-area-inset-bottom, 0px));
}

.speaking-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 0.85rem 1rem 0.65rem;
  position: sticky;
  top: 0;
  z-index: 5;
  background: linear-gradient(180deg, rgba(10, 16, 24, 0.92), rgba(10, 16, 24, 0.72) 70%, transparent);
  backdrop-filter: blur(10px);
}

.speaking-topbar h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.speaking-topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.quota-chip {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-bright);
  background: var(--accent-soft);
  border: 1px solid rgba(37, 99, 235, 0.45);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  white-space: nowrap;
}

.icon-btn {
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { border-color: var(--accent-bright); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.speaking-content {
  flex: 1;
  padding: 0 1rem 1.25rem;
  overflow: auto;
}

.part-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.part-chip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  min-height: var(--touch-min);
}
.part-chip.is-active {
  background: var(--accent);
  border-color: var(--accent-bright);
  color: #fff;
}
.part-chip:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.card-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.surface-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.9rem 1rem;
  cursor: pointer;
  transition: transform var(--motion), border-color var(--motion);
  animation: speak-rise 280ms ease both;
}
.surface-card:hover { border-color: var(--accent-bright); transform: translateY(-1px); }
.surface-card:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.surface-card.static { cursor: default; }
.surface-card.static:hover { transform: none; }

.topic-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.topic-index {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent-bright);
  display: grid;
  place-items: center;
  font-weight: 700;
  flex-shrink: 0;
}
.topic-meta { color: var(--text-muted); font-size: 0.85rem; margin: 0.15rem 0 0; }
.topic-title { margin: 0; font-weight: 650; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--accent-bright);
  background: transparent;
  border: 0;
  font-weight: 600;
  cursor: pointer;
  min-height: var(--touch-min);
  padding: 0;
  margin-bottom: 0.35rem;
}
.back-link:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: 8px; }

.step-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin: 0.5rem 0 1rem;
}
.step-item { text-align: center; }
.step-track {
  height: 4px;
  border-radius: 2px;
  background: var(--surface-2);
  margin-bottom: 0.4rem;
}
.step-item.is-active .step-track,
.step-item.is-done .step-track { background: var(--accent); }
.step-label {
  font-size: 0.7rem;
  color: var(--text-muted);
}
.step-item.is-active .step-label {
  color: var(--accent-bright);
  font-weight: 650;
}

.q-text {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  line-height: 1.4;
}
.cue-list {
  margin: 0.65rem 0 0;
  padding-left: 1.1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.85rem 0;
}

.btn {
  min-height: var(--touch-min);
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  padding: 0.55rem 0.95rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.btn:hover { border-color: var(--accent-bright); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent-bright);
  color: #fff;
  width: 100%;
  justify-content: center;
}
.btn-danger {
  background: var(--recording);
  border-color: #ff6b6b;
  color: #fff;
}

.record-row {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin: 0.75rem 0 1rem;
}
.mic-btn {
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  position: relative;
  z-index: 1;
}
.mic-btn.is-recording {
  background: var(--recording);
  animation: mic-pulse 700ms ease-in-out infinite alternate;
}
.mic-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.mic-hint { color: var(--text-muted); font-size: 0.85rem; margin: 0.15rem 0 0; }
.mic-hint.is-live { color: var(--recording); font-weight: 600; }

.field-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}
.transcript-input {
  width: 100%;
  min-height: 7rem;
  resize: vertical;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.75rem;
  font: inherit;
  margin-bottom: 0.85rem;
}
.transcript-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.error-text { color: var(--error); font-size: 0.9rem; margin: 0.5rem 0; }
.ideas-card ul { margin: 0; padding-left: 1.1rem; color: var(--text-muted); }

.score-card {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid rgba(37, 99, 235, 0.45);
  background: var(--surface);
  animation: speak-rise 320ms ease both;
}
.score-overall {
  text-align: center;
  margin-bottom: 1rem;
}
.score-overall .label { color: var(--text-muted); font-size: 0.8rem; }
.score-overall .value {
  font-size: 2.5rem;
  font-weight: 750;
  letter-spacing: -0.03em;
  line-height: 1.1;
  animation: score-pop 420ms cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}
.band-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.45rem;
  margin-bottom: 0.9rem;
}
.band-cell {
  background: var(--surface-2);
  border: 1px solid rgba(155, 92, 255, 0.25);
  border-radius: 12px;
  padding: 0.55rem 0.25rem;
  text-align: center;
  animation: speak-rise 280ms ease both;
}
.band-cell .v { font-weight: 700; font-size: 1.05rem; }
.band-cell .l { font-size: 0.65rem; color: var(--text-muted); }
.band-good { color: var(--success); }
.band-ok { color: var(--accent-bright); }
.band-warn { color: var(--warn); }
.band-low { color: var(--error); }

.score-section { margin-top: 0.75rem; }
.score-section h3 {
  margin: 0 0 0.3rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: none;
}
.score-section p, .score-section li {
  margin: 0;
  font-size: 0.92rem;
}
.score-section ul { margin: 0; padding-left: 1.1rem; }
.tip-text { color: var(--success); }

.empty-history {
  flex: 1;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 1.5rem 1.5rem 3rem;
  color: var(--text-muted);
  line-height: 1.45;
  min-height: 40vh;
}

.history-band {
  flex-shrink: 0;
  border-radius: 12px;
  padding: 0.45rem 0.7rem;
  text-align: center;
  border: 1px solid transparent;
}
.history-band .v { font-weight: 750; font-size: 1.1rem; display: block; }
.history-band .l { font-size: 0.65rem; color: var(--text-muted); }

.bottom-tabs {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: var(--page-max);
  height: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--glass);
  border-top: 0.5px solid rgba(37, 99, 235, 0.4);
  backdrop-filter: blur(14px);
  z-index: 10;
}
.tab-slot {
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: #8496ad;
  cursor: pointer;
  min-height: var(--tab-h);
}
.tab-pill {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
}
.tab-slot.is-active .tab-pill {
  background: #2a1f45;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.55), 0 0 16px var(--accent-glow);
  color: var(--accent-bright);
}
.tab-slot:focus-visible { outline: none; }
.tab-slot:focus-visible .tab-pill { box-shadow: var(--focus-ring); }

.settings-sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 40;
  display: grid;
  place-items: end center;
}
.settings-panel {
  width: 100%;
  max-width: var(--page-max);
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  border: 1px solid var(--border);
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
}
.settings-panel h2 { margin: 0 0 0.75rem; font-size: 1.05rem; }

@keyframes speak-rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes score-pop {
  from { opacity: 0; transform: scale(0.86); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes mic-pulse {
  from { transform: scale(1); box-shadow: 0 0 0 0 rgba(229, 57, 53, 0.35); }
  to { transform: scale(1.06); box-shadow: 0 0 0 10px rgba(229, 57, 53, 0); }
}

@media (max-width: 420px) {
  .band-grid { grid-template-columns: repeat(2, 1fr); }
}
