:root {
  --bg: #f4f8ff;
  --panel: #ffffff;
  --ink: #0d2742;
  --muted: #4d647d;
  --primary: #006a5b;
  --primary-2: #0a8f7c;
  --line: #d9e3ef;
  --danger: #9b2b2b;
  --ok: #166534;
  --shadow: 0 14px 35px rgba(13, 39, 66, 0.08);
  --radius: 16px;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Trebuchet MS", Arial, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #eaf2ff 0%, #dce9fb 100%);
  min-height: 100vh;
  overflow-x: hidden;
}

.bg-orb {
  position: fixed;
  border-radius: 999px;
  filter: blur(30px);
  z-index: -1;
  opacity: 0.55;
}

.orb-a {
  width: 330px;
  height: 330px;
  background: #c9f0e6;
  top: -110px;
  left: -70px;
}

.orb-b {
  width: 360px;
  height: 360px;
  background: #d5e5ff;
  right: -90px;
  top: 40px;
}

.hero,
.container {
  width: min(1100px, 94vw);
  margin: 0 auto;
}

.hero {
  margin-top: 28px;
  padding: 30px;
  border-radius: 22px;
  background: linear-gradient(120deg, #0d355d 0%, #006a5b 100%);
  color: #fff;
  box-shadow: var(--shadow);
}

.hero-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.8rem;
  opacity: 0.9;
}

.btn-lockout {
  text-decoration: none;
  color: #133454;
  padding: 8px 12px;
}

h1 {
  margin: 10px 0 14px;
  font-size: clamp(2rem, 4.2vw, 3.2rem);
  line-height: 1.08;
  letter-spacing: -0.02em;
}
h2 { margin: 0 0 10px; }
h3 { margin: 0 0 10px; }

.lead {
  margin: 0;
  max-width: 74ch;
  font-size: clamp(1.05rem, 1.5vw, 1.2rem);
  line-height: 1.35;
  font-weight: 600;
  color: #ebf7ff;
}

.meta-grid {
  margin-top: 22px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.meta-card {
  background: linear-gradient(160deg, rgba(12, 41, 68, 0.55), rgba(16, 89, 79, 0.4));
  border: 1px solid rgba(198, 228, 255, 0.22);
  border-radius: 12px;
  padding: 16px 14px;
  min-height: 82px;
  display: grid;
  align-content: start;
  gap: 6px;
  font-size: clamp(1.05rem, 1.35vw, 1.15rem);
  line-height: 1.25;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.meta-card strong {
  display: block;
  font-size: 1.15em;
  color: #ffffff;
}

.meta-value {
  display: block;
  color: #e8f4ff;
  font-weight: 600;
}

.container {
  margin-top: 18px;
  margin-bottom: 36px;
  display: grid;
  gap: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.hint {
  background: #fff7e8;
  color: #7a4d00;
  border-left: 4px solid #d18b1f;
  padding: 10px;
  border-radius: 8px;
}

.progress-row {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 10px;
}

.progress-wrap {
  width: min(380px, 48vw);
  height: 12px;
  border-radius: 999px;
  background: #e7eef8;
  border: 1px solid #d0dceb;
  overflow: hidden;
}

#progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #0a8f7c, #1668dc);
  transition: width 300ms ease;
}

.section-title {
  margin: 22px 0 8px;
  padding: 9px 12px;
  background: #edf5ff;
  color: #163b64;
  border-radius: 10px;
  border: 1px solid #d8e6f8;
}

.question {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
}

.question p {
  margin: 0 0 10px;
}

.question-head {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  justify-content: space-between;
}

.question-head p {
  margin: 0 0 10px;
}

.btn-swap {
  padding: 7px 10px;
  font-weight: 600;
  white-space: nowrap;
}

.options {
  display: grid;
  gap: 8px;
}

.opt {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 8px;
  align-items: start;
  background: #f8fbff;
  border: 1px solid #dce7f5;
  border-radius: 10px;
  padding: 8px;
}

.opt input { margin-top: 4px; }

.audio-wrap {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}

.audio-wrap audio {
  width: min(480px, 100%);
}

.free-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}

.free-meta input[type="number"] {
  width: 100%;
}

textarea {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  border-radius: 10px;
  border: 1px solid #cfdceb;
  padding: 10px;
  font: inherit;
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.eval-loading {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #d6e4f4;
  background: #f3f8ff;
}

.eval-loading p {
  margin: 0;
  color: #1f4469;
}

.spinner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 3px solid #bcd1ea;
  border-top-color: #0b5ca8;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 11px 14px;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(120deg, var(--primary), #0b5ca8);
}

.btn-light {
  color: #133454;
  background: #eaf1fb;
  border: 1px solid #d1dfef;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.score-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: #f8fbff;
}

.score-label {
  margin: 0;
  color: var(--muted);
  word-break: break-word;
}
.score-value { margin: 8px 0; font-size: 1.8rem; font-weight: 800; }

.badge {
  margin: 0;
  display: inline-block;
  padding: 5px 9px;
  border-radius: 999px;
  background: #e8f2ff;
  color: #154e95;
  font-weight: 700;
}

.analysis-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
}

.analysis-grid article,
.sources {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: #fcfdff;
}

#ai-speaking-results {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.small-gap {
  margin: 0 0 10px;
}

.slim {
  margin-top: 10px;
  margin-bottom: 0;
}

.api-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
}

.api-row input {
  border-radius: 8px;
  border: 1px solid #cfdceb;
  padding: 8px 10px;
  font: inherit;
}

input,
textarea,
button,
select {
  font-size: 16px;
}

input,
textarea,
select {
  color: var(--ink);
  background: #ffffff;
}

input::placeholder,
textarea::placeholder {
  color: #5a7089;
}

.mic-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.mic-state {
  display: inline-block;
  padding: 5px 8px;
  border-radius: 999px;
  background: #eef3fa;
  color: #23476e;
  font-size: 0.86rem;
}

.mic-hint {
  margin: 0;
  width: 100%;
  font-size: 0.86rem;
  color: #385778;
}

.ai-card h4 {
  margin: 0 0 8px;
}

.ai-card p {
  margin: 0 0 6px;
}

.ai-mode-block {
  display: grid;
  gap: 8px;
}

.ai-mode-title {
  margin: 4px 0 0;
}

.ai-mode-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.hidden { display: none; }

.good { background: #e8f9ed; color: var(--ok); }
.warn { background: #fff4e8; color: #8a4b00; }
.bad { background: #fdeceb; color: var(--danger); }

.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 22, 38, 0.48);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}

.confirm-overlay.hidden {
  display: none;
}

.confirm-dialog {
  width: min(520px, 100%);
  background: #ffffff;
  border: 1px solid #d5e1ef;
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 20px 45px rgba(6, 27, 49, 0.22);
}

.confirm-dialog h3 {
  margin: 0 0 8px;
  color: #0f2e4c;
}

.confirm-dialog p {
  margin: 0 0 14px;
  color: #35597d;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.theme-toggle {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 60;
  min-width: 108px;
  padding: 8px 10px;
  border-radius: 999px;
  box-shadow: 0 8px 20px rgba(11, 33, 56, 0.2);
}

body.theme-dark {
  --bg: #0f1b2a;
  --panel: #172636;
  --ink: #e8f1fb;
  --muted: #b5c7dc;
  --line: #2b4259;
  --primary: #1a8b79;
  --primary-2: #3cae98;
  --danger: #ff8f8f;
  --ok: #9be6b6;
  background: linear-gradient(180deg, #091321 0%, #0f1d2d 100%);
}

body.theme-dark .hero {
  background: linear-gradient(120deg, #11263f 0%, #165c53 100%);
}

body.theme-dark .btn-lockout {
  background: #24415a;
  border-color: #3f6584;
  color: #e4effb;
}

body.theme-dark .meta-card {
  background: linear-gradient(160deg, rgba(20, 45, 70, 0.7), rgba(24, 68, 61, 0.52));
  border-color: rgba(166, 204, 236, 0.28);
}

body.theme-dark .panel,
body.theme-dark .question,
body.theme-dark .score-card,
body.theme-dark .analysis-grid article,
body.theme-dark .sources {
  background: var(--panel);
  border-color: var(--line);
}

body.theme-dark .section-title {
  background: #1a2f46;
  color: #d7e8fa;
  border-color: #2f4b68;
}

body.theme-dark .opt {
  background: #1a2d40;
  border-color: #30506d;
}

body.theme-dark textarea,
body.theme-dark input,
body.theme-dark select,
body.theme-dark .api-row input {
  background: #122131;
  border-color: #38516b;
  color: #e8f1fb;
}

body.theme-dark input::placeholder,
body.theme-dark textarea::placeholder {
  color: #a6bfd8;
}

body.theme-dark .btn-light {
  background: #20364a;
  border-color: #3d5c78;
  color: #e0ecf9;
}

body.theme-dark .hint {
  background: #3a2f1f;
  color: #ffdca2;
  border-left-color: #d19937;
}

body.theme-dark .progress-wrap {
  background: #172b3f;
  border-color: #2e4a66;
}

body.theme-dark .badge {
  background: #203c58;
  color: #c7e1ff;
}

body.theme-dark .mic-state {
  background: #20374d;
  color: #d2e7fb;
}

body.theme-dark .mic-hint,
body.theme-dark .score-label,
body.theme-dark .confirm-dialog p {
  color: #bfd3e7;
}

body.theme-dark .confirm-dialog {
  background: #172637;
  border-color: #35516d;
}

body.theme-dark .confirm-dialog h3 {
  color: #e6f2ff;
}

@media (max-width: 720px) {
  .hero {
    padding: 20px 16px;
  }
  h1 {
    font-size: clamp(1.7rem, 8.2vw, 2.2rem);
  }
  .lead {
    font-size: 1.02rem;
    font-weight: 500;
  }
  .meta-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .meta-card {
    min-height: 74px;
    font-size: 1rem;
  }
  .panel { padding: 16px; }
  .hero-top {
    align-items: flex-start;
    flex-direction: column;
  }
  .progress-row { align-items: stretch; flex-direction: column; }
  .progress-wrap { width: 100%; }
  .actions {
    flex-direction: column;
  }
  .btn {
    width: 100%;
    min-height: 44px;
  }
  .theme-toggle {
    top: 10px;
    right: 10px;
    min-width: 92px;
    padding: 7px 9px;
    width: auto;
  }
  .opt {
    grid-template-columns: 24px 1fr;
    padding: 10px;
  }
  .question-head {
    flex-direction: column;
    align-items: stretch;
  }
  .btn-swap {
    width: 100%;
  }
  .api-row {
    grid-template-columns: 1fr;
  }
  .ai-mode-grid {
    grid-template-columns: 1fr;
  }
  .confirm-actions {
    flex-direction: column;
  }
}
