/* Blue-led palette: one hue for identity, neutrals carry the rest. */
:root {
  --brand-50: #eff6ff;
  --brand-100: #dbeafe;
  --brand-200: #bfdbfe;
  --brand-300: #93c5fd;
  --brand-400: #60a5fa;
  --brand-500: #3b82f6;
  --brand-600: #2563eb;
  --brand-700: #1d4ed8;
  --brand-900: #1e3a8a;

  --surface: #fff;
  --canvas: #f6f8fc;
  --ink: #0f172a;
  --ink-muted: #64748b;
  --line: #e2e8f0;

  /* Score bands — green / blue / amber / rose, kept low-saturation. */
  --score-excellent: #059669;
  --score-good: #2563eb;
  --score-fair: #d97706;
  --score-poor: #e11d48;

  --font-sans: ui-sans-serif, system-ui, "Segoe UI", "Hiragino Kaku Gothic ProN",
    "Noto Sans JP", "Yu Gothic", sans-serif;
  --font-jp: "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic Medium",
    "Meiryo", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  border-color: var(--line);
}

/* The browser's own [hidden] rule loses to any author `display`, so restate it
   here — otherwise `display: flex` below would keep hidden panels on screen. */
[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Subtle blue wash behind the page, so the cards read as floating. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(60rem 30rem at 50% -10%, var(--brand-100), transparent 70%),
    radial-gradient(40rem 24rem at 100% 0%, #e0f2fe, transparent 65%);
}

:focus-visible {
  outline: 2px solid var(--brand-600);
  outline-offset: 2px;
}

p,
h1,
h2 {
  margin: 0;
}

button {
  font: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.icon {
  width: 1.25rem;
  height: 1.25rem;
  flex: none;
}
.icon--sm { width: 0.875rem; height: 0.875rem; }
.icon--xs { width: 0.75rem; height: 0.75rem; }

.jp { font-family: var(--font-jp); }

.muted { color: var(--ink-muted); }
.muted--soft { color: color-mix(in srgb, var(--ink-muted) 80%, transparent); }

.label svg {
  vertical-align: -0.1em;
  margin-right: 0.25rem;
}

.label {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
}

/* ---------- Layout ---------- */

.page {
  width: 100%;
  max-width: 48rem;
  margin: 0 auto;
  padding: 2rem 1rem;
}

.page__header {
  margin-bottom: 2rem;
  text-align: center;
}

.page__header h1 {
  margin-top: 1rem;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.lead {
  max-width: 28rem;
  margin: 0.5rem auto 0;
  color: var(--ink-muted);
  line-height: 1.6;
}

.page__footer {
  margin-top: 2.5rem;
  text-align: center;
  font-size: 12px;
  color: color-mix(in srgb, var(--ink-muted) 70%, transparent);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.75rem;
  border: 1px solid var(--brand-200);
  border-radius: 9999px;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.05);
  font-size: 12px;
  font-weight: 500;
  color: var(--brand-700);
}

/* ---------- Card ---------- */

.card {
  border: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
  border-radius: 1rem;
  background: var(--surface);
  box-shadow: 0 1px 2px rgb(15 23 42 / 0.05);
}

.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1.25rem 1.25rem 0;
}

.card__title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 0.5rem;
  background: var(--brand-100);
  color: var(--brand-700);
  font-size: 11px;
  font-weight: 700;
}

.card__body {
  padding: 1rem 1.25rem 1.25rem;
}

.link-btn,
.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.5rem;
  border: 0;
  border-radius: 0.5rem;
  background: none;
  color: var(--brand-700);
  font-size: 12px;
  font-weight: 500;
  transition: background-color 0.15s;
}

.link-btn:hover,
.ghost-btn:hover:not(:disabled) {
  background: var(--brand-50);
}

.ghost-btn {
  padding: 0.375rem 0.75rem;
  color: var(--ink-muted);
}

.solid-btn,
.outline-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  gap: 0.375rem;
  height: 2.5rem;
  padding: 0 1rem;
  border: 1px solid var(--brand-600);
  border-radius: 0.625rem;
  background: var(--brand-600);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.solid-btn:hover:not(:disabled) {
  background: var(--brand-700);
  border-color: var(--brand-700);
}

.outline-btn {
  border-color: var(--line);
  background: var(--surface);
  color: var(--brand-700);
}

.outline-btn:hover:not(:disabled) {
  border-color: var(--brand-300);
  background: var(--brand-50);
}

.solid-btn:disabled,
.outline-btn:disabled {
  opacity: 0.55;
}

/* ---------- Target sentence ---------- */

.target {
  font-family: var(--font-jp);
  font-size: 1.5rem;
  line-height: 1.7;
  letter-spacing: 0.02em;
}

#target-reading { margin-top: 0.75rem; }
#target-meaning { margin-top: 0.25rem; }

.divider {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  max-width: 100%;
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 9999px;
  background: var(--surface);
  color: var(--ink-muted);
  font-size: 12px;
  transition: all 0.15s;
}

.chip:hover:not(:disabled):not(.chip--active) {
  border-color: var(--brand-300);
  color: var(--brand-700);
}

.chip--active {
  border-color: var(--brand-600);
  background: var(--brand-600);
  color: #fff;
}

.chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip__check { display: none; }
.chip--active .chip__check { display: block; }

/* ---------- Custom sentence ---------- */

.compose {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.compose__input {
  width: 100%;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: var(--surface);
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.6;
  resize: vertical;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.compose__input::placeholder {
  color: color-mix(in srgb, var(--ink-muted) 70%, transparent);
}

.compose__input:focus {
  outline: 0;
  border-color: var(--brand-400);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-500) 15%, transparent);
}

.compose__input:disabled {
  background: var(--canvas);
  opacity: 0.7;
}

/* ---------- Recorder ---------- */

.recorder {
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Also the drop target for uploaded audio (see .is-dropping). */
  border-radius: 0.75rem;
  transition: background-color 0.15s;
}

.recorder__dial {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 8rem;
  height: 8rem;
}

.recorder__pulse,
.recorder__level {
  position: absolute;
  inset: 0;
  border-radius: 9999px;
  display: none;
}

.recorder__pulse {
  background: color-mix(in srgb, var(--brand-400) 30%, transparent);
  animation: pulse-ring 1.8s cubic-bezier(0.24, 0.88, 0.36, 1) infinite;
}

.recorder__level {
  background: color-mix(in srgb, var(--brand-500) 20%, transparent);
  /* Scale is driven from JS by the live mic level. */
  transform: scale(1);
  transition: transform 75ms linear;
}

.is-recording .recorder__pulse,
.is-recording .recorder__level { display: block; }

.mic {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 6rem;
  height: 6rem;
  border: 0;
  border-radius: 9999px;
  background: var(--brand-600);
  color: #fff;
  box-shadow: 0 10px 15px -3px color-mix(in srgb, var(--brand-600) 30%, transparent);
  transition: background-color 0.15s, transform 0.1s, box-shadow 0.15s;
}

.mic:hover:not(:disabled) { background: var(--brand-700); }
.mic:active:not(:disabled) { transform: scale(0.95); }

.is-recording .mic {
  background: #e11d48;
  box-shadow: 0 10px 15px -3px rgb(225 29 72 / 0.3);
}
.is-recording .mic:hover { background: #be123c; }

.mic__icon { width: 2.5rem; height: 2.5rem; }

.is-busy .mic__icon {
  width: 2.25rem;
  height: 2.25rem;
  animation: spin 1s linear infinite;
}

.status {
  margin-top: 1.25rem;
  text-align: center;
  color: var(--ink-muted);
}

.timer {
  width: 100%;
  max-width: 20rem;
  margin-top: 1rem;
}

.timer__row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--ink-muted);
}

.timer__now { color: #e11d48; }

.timer__track {
  height: 4px;
  margin-top: 0.375rem;
  border-radius: 9999px;
  background: var(--line);
  overflow: hidden;
}

.timer__bar {
  height: 100%;
  width: 0;
  border-radius: 9999px;
  background: #f43f5e;
  transition: width 0.1s linear;
}

.upload {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  max-width: 24rem;
  margin-top: 1.25rem;
}

/* "hoặc" centred on a hairline, so the two input paths read as alternatives. */
.upload__or {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  font-size: 12px;
  color: var(--ink-muted);
}

.upload__or::before,
.upload__or::after {
  content: "";
  flex: 1;
  height: 1px;
  background: color-mix(in srgb, var(--line) 70%, transparent);
}

.upload__hint {
  font-size: 11px;
  color: var(--ink-muted);
  text-align: center;
}

/* Drop target feedback — the whole recorder body accepts the file. */
.recorder.is-dropping {
  background: var(--brand-50);
  outline: 2px dashed var(--brand-300);
  outline-offset: -4px;
}

.recorder.is-dropping > * {
  pointer-events: none;
}

.playback {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  max-width: 24rem;
  margin-top: 1.25rem;
}

.playback audio {
  width: 100%;
  height: 2.5rem;
}

/* ---------- Alert ---------- */

.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  padding: 0.75rem 1rem;
  border: 1px solid #fecdd3;
  border-radius: 1rem;
  background: #fff1f2;
  color: #9f1239;
}

.alert .icon { margin-top: 0.125rem; }

/* ---------- Result ---------- */

.result__top {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

.ring {
  position: relative;
  flex: none;
  width: 8rem;
  height: 8rem;
}

.ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring__track {
  fill: none;
  stroke: var(--line);
  stroke-width: 10;
}

.ring__value {
  fill: none;
  stroke: var(--score-good);
  stroke-width: 10;
  stroke-linecap: round;
  transition: stroke-dasharray 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

.ring__label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.ring__score {
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--score-good);
}

.ring__max {
  margin-top: 0.25rem;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
}

.result__summary {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  border: 1px solid;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 600;
}

#feedback {
  margin-top: 0.75rem;
  line-height: 1.6;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
  margin-top: 1rem;
}

.metric {
  padding: 0.625rem 0.75rem;
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  border-radius: 0.75rem;
  background: color-mix(in srgb, var(--canvas) 60%, transparent);
  text-align: left;
}

.metric__value {
  margin-top: 0.25rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.readings {
  display: grid;
  gap: 1rem;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}

.reading {
  margin-top: 0.5rem;
  font-size: 1.25rem;
  line-height: 2;
  letter-spacing: 0.02em;
}

.reading--heard { color: var(--brand-700); }

/* Characters the model did not hear as expected. */
.reading mark {
  border-radius: 0.25rem;
  padding: 0 1px;
  background: #ffe4e6;
  color: #be123c;
}

.diffs {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}

.diffs__list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0 0;
  padding: 0;
  list-style: none;
}

.diffs__list li {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.625rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: color-mix(in srgb, var(--canvas) 60%, transparent);
}

.diffs__list .to { color: var(--ink-muted); }
.diffs__list .heard { color: #e11d48; font-weight: 500; }
.diffs__list .pos { font-size: 10px; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.diffs__list .more { border: 0; background: none; font-size: 12px; color: var(--ink-muted); }

.note {
  margin-top: 1.25rem;
  padding: 0.625rem 0.875rem;
  border-radius: 0.75rem;
  background: color-mix(in srgb, var(--brand-50) 70%, transparent);
  font-size: 12px;
  line-height: 1.6;
  color: color-mix(in srgb, var(--brand-900) 70%, transparent);
}

/* ---------- Animation ---------- */

@keyframes pulse-ring {
  0% { transform: scale(0.95); opacity: 0.55; }
  70%, 100% { transform: scale(1.35); opacity: 0; }
}

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

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.rise:not([hidden]) { animation: rise 0.35s ease-out both; }

@media (prefers-reduced-motion: reduce) {
  .recorder__pulse,
  .rise:not([hidden]) { animation: none; }
}

/* ---------- Responsive ---------- */

@media (min-width: 640px) {
  .page { padding: 3rem 1.5rem; }
  .page__header { margin-bottom: 2.5rem; }
  .page__header h1 { font-size: 1.875rem; }
  .stack { gap: 1.25rem; }

  .card__head { padding: 1.5rem 1.5rem 0; }
  .card__body { padding: 1.25rem 1.5rem 1.5rem; }

  .target { font-size: 1.875rem; }
  .reading { font-size: 1.5rem; }

  .compose { flex-direction: row; align-items: flex-start; }
  /* Fixed height, pinned to the top: the textarea can grow, the button must not. */
  .compose .solid-btn { align-self: flex-start; }

  .recorder__dial { width: 9rem; height: 9rem; }
  .mic { width: 7rem; height: 7rem; }

  .result__top { flex-direction: row; gap: 1.75rem; }
  .result__summary { text-align: left; }
  .ring { width: 9rem; height: 9rem; }
  .ring__score { font-size: 3rem; }
  .metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .readings { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
