:root {
  --bg: #eef8ff;
  --surface: #ffffff;
  --surface-soft: #f7fbff;
  --primary: #0879d7;
  --primary-dark: #075ca3;
  --accent: #20b8d8;
  --ink: #10243f;
  --muted: #60738d;
  --border: #d8e9f7;
  --danger: #d44264;
  --success: #0b8f74;
  --shadow: 0 20px 60px rgba(28, 95, 153, 0.14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(32, 184, 216, 0.18), transparent 32rem),
    linear-gradient(135deg, #f9fdff 0%, var(--bg) 100%);
  min-height: 100dvh;
}

button,
textarea,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 1000;
  padding: 10px 14px;
  color: #fff;
  background: var(--primary);
  border-radius: 8px;
  transform: translateY(-140%);
}

.skip-link:focus {
  transform: translateY(0);
}

.app-shell {
  min-height: 100dvh;
  display: flex;
}

.sidebar {
  width: 248px;
  padding: 20px;
  background: rgba(255, 255, 255, 0.84);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(18px);
  transition: width 180ms ease, padding 180ms ease, opacity 180ms ease;
}

.sidebar.is-hidden {
  width: 0;
  padding: 0;
  overflow: hidden;
  opacity: 0;
  border: 0;
}

.brand,
.topbar,
.topbar-left,
.topbar-actions,
.controls,
.form-actions,
.drawer-header {
  display: flex;
  align-items: center;
}

.brand {
  gap: 10px;
  margin-bottom: 28px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  font-weight: 800;
}

nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  width: 100%;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  text-align: left;
}

.nav-item.is-active,
.nav-item:hover {
  color: var(--primary-dark);
  background: #e8f5ff;
  border-color: #cae6fb;
}

svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.workspace {
  width: calc(100% - 248px);
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px;
  transition: width 180ms ease;
}

.workspace.wide {
  width: 100%;
}

.topbar {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.topbar-left,
.topbar-actions {
  gap: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.08;
  letter-spacing: 0;
}

.icon-button,
.ghost-button,
.soft-button,
.primary-button {
  min-width: 44px;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--border);
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  color: var(--primary-dark);
  background: rgba(255, 255, 255, 0.78);
}

.ghost-button,
.soft-button {
  padding: 0 16px;
  color: var(--primary-dark);
  background: #fff;
}

.soft-button {
  width: 100%;
  margin-top: 28px;
}

.primary-button {
  padding: 0 20px;
  color: #fff;
  border-color: var(--primary);
  background: linear-gradient(135deg, var(--primary), var(--accent));
  font-weight: 700;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 26px rgba(8, 121, 215, 0.16);
}

button:focus-visible,
textarea:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(8, 121, 215, 0.32);
  outline-offset: 3px;
}

.dictation-main {
  display: grid;
  gap: 18px;
}

.compare-grid {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr);
  gap: 18px;
}

.player-panel,
.input-panel,
.result-panel {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.dictation-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.dictation-heading .eyebrow {
  margin-bottom: 6px;
}

.history-score {
  display: inline-flex;
  margin-left: 8px;
  padding: 2px 7px;
  color: #ffffff;
  border: 1px solid #10b981;
  border-radius: 999px;
  background: #10b981;
  box-shadow: 0 8px 18px rgba(16, 185, 129, 0.24);
  font-weight: 800;
  text-transform: none;
}

.sentence-counter {
  display: inline-flex;
  padding: 5px 8px;
  border: 1px solid #cbe7fb;
  border-radius: 6px;
  color: var(--primary-dark);
  background: #eaf6ff;
  font-size: 12px;
  font-weight: 700;
}

.shortcut-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  max-width: 440px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.player-assist {
  display: grid;
  justify-items: end;
  gap: 4px;
  max-width: min(540px, 52vw);
}

.shortcut-strip span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

kbd {
  min-height: 22px;
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border: 1px solid #c7dfef;
  border-bottom-color: #a8c9df;
  border-radius: 5px;
  color: var(--primary-dark);
  background: #ffffff;
  box-shadow: inset 0 -1px 0 rgba(8, 121, 215, 0.08);
  font: 600 11px/1.2 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.playback-row {
  display: grid;
  grid-template-columns: 48px minmax(160px, 1fr) 48px 44px auto;
  align-items: center;
  gap: 12px;
}

.playback-row [data-action='toggle-play-mode'] {
  color: #087963;
  border-color: #a8ead6;
  background: #dff8ef;
}

.time-elapsed,
.time-total {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

.time-total {
  text-align: right;
}

.timeline {
  accent-color: var(--primary);
  min-height: 30px;
}

.controls {
  justify-content: center;
  gap: 8px;
  margin: 0;
  flex-wrap: wrap;
}

.hint-box {
  max-width: 420px;
  min-height: calc(12px * 1.35 * 2);
  color: var(--primary-dark);
  font-size: 12px;
  line-height: 1.35;
  text-align: right;
  visibility: hidden;
}

.hint-box.open {
  visibility: visible;
}

.empty-state {
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
}

.input-panel label,
.upload-form label {
  display: grid;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
}

textarea,
input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--ink);
}

textarea {
  min-height: 320px;
  margin-top: 8px;
  padding: 16px;
  line-height: 1.65;
  resize: vertical;
}

.answer-review {
  width: 100%;
  min-height: 320px;
  margin-top: 8px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--ink);
  line-height: 1.8;
  white-space: normal;
}

.review-token {
  display: inline;
  padding: 1px 3px;
  border-radius: 4px;
}

.review-token.is-error {
  color: #b42345;
  background: #ffe6ec;
  box-shadow: inset 0 -1px 0 #ffb7c6;
}

.review-token.is-missing-space {
  display: inline-block;
  width: var(--missing-width, 2.4em);
  height: 1.2em;
  padding: 0;
  vertical-align: baseline;
  background: #ffe6ec;
  border-bottom: 2px solid #d92d50;
  border-radius: 0;
}

.review-token.is-correction {
  color: #087963;
  background: #dff8ef;
  box-shadow: inset 0 -1px 0 #a8ead6;
}

input {
  min-height: 46px;
  padding: 0 12px;
}

.form-actions {
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.submit-status {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid #10b981;
  border-radius: 8px;
  color: #ffffff;
  background: #10b981;
  box-shadow: 0 10px 22px rgba(16, 185, 129, 0.22);
  font-weight: 800;
}

.result-panel {
  margin-top: 18px;
}

.result-score {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 18px;
}

.result-score strong {
  font-size: 34px;
  color: var(--primary-dark);
}

.result-score small {
  color: var(--muted);
}

.compare-grid {
  align-items: start;
}

.token-flow {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  line-height: 1.7;
}

.token {
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid transparent;
}

.token.ok {
  background: #e9fbf6;
  color: #087963;
}

.token.bad {
  background: #fff0f4;
  color: #b12345;
  border-color: #ffd0dc;
}

.token.key {
  background: #eaf5ff;
  color: var(--primary-dark);
  border-color: #cbe7fb;
}

.drawer-scrim {
  position: fixed;
  inset: 0;
  z-index: 30;
  pointer-events: none;
  background: rgba(16, 36, 63, 0);
  transition: background 180ms ease;
}

.drawer-scrim.open {
  pointer-events: auto;
  background: rgba(16, 36, 63, 0.36);
}

.right-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 40;
  width: min(420px, 100vw);
  height: 100dvh;
  padding: 16px;
  overflow: auto;
  background: #f8fcff;
  border-left: 1px solid var(--border);
  box-shadow: -22px 0 70px rgba(16, 36, 63, 0.18);
  transform: translateX(100%);
  transition: transform 220ms ease;
}

.right-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.account-close-row {
  justify-content: flex-end;
}

.drawer-header h2 {
  margin-bottom: 0;
}

.library-section {
  margin-bottom: 18px;
}

.library-section h3 {
  margin-bottom: 8px;
  font-size: 19px;
  line-height: 1.2;
}

details {
  border-top: 1px solid var(--border);
  padding: 8px 0;
}

summary {
  min-height: 36px;
  display: flex;
  align-items: center;
  color: var(--primary-dark);
  font-weight: 800;
  cursor: pointer;
}

.series {
  margin-bottom: 8px;
  padding: 6px 0;
}

.series-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  min-height: 32px;
}

.series-heading p {
  margin-bottom: 0;
  color: var(--muted);
  font-weight: 700;
  font-size: 14px;
  line-height: 1.25;
}

.series-heading small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.dictation-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-height: 38px;
  padding: 5px 6px 5px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  margin-top: 6px;
}

.dictation-select {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  min-height: 30px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.2;
  text-align: left;
  cursor: pointer;
}

.dictation-select > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dictation-row small {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
  justify-content: flex-end;
  color: var(--muted);
}

.menu-score {
  display: inline-flex;
  padding: 1px 6px;
  color: #087963;
  border: 1px solid #a8ead6;
  border-radius: 999px;
  background: #dff8ef;
  font-size: 12px;
  font-weight: 850;
}

.row-actions {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 4px;
}

.dictation-row .icon-button {
  min-width: 32px;
  min-height: 32px;
}

.dictation-row .icon-button svg {
  width: 17px;
  height: 17px;
}

.danger-button {
  flex: 0 0 auto;
  color: #c24141;
  background: #fff5f5;
}

.danger-button:hover {
  border-color: #fecaca;
  background: #fee2e2;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  width: min(560px, calc(100vw - 28px));
  margin: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  background: #fff;
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(16, 36, 63, 0.42);
}

.upload-form,
.account-card {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.file-upload-control {
  display: grid;
  gap: 8px;
}

.file-upload-control input[type='file'] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  pointer-events: none;
}

.file-upload-button {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.file-upload-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.file-upload-control small {
  color: var(--muted);
  font-weight: 700;
}

.signed-in-card {
  display: grid;
  gap: 4px;
  padding: 14px;
  border: 1px solid #cbe7fb;
  border-radius: 8px;
  background: #f1f9ff;
}

.signed-in-card p,
.signed-in-card small {
  margin: 0;
  color: var(--muted);
}

.modal.compact {
  width: min(640px, calc(100vw - 28px));
  border-radius: 28px;
}

.parent-code-modal {
  width: min(380px, calc(100vw - 28px));
}

.parent-code-card {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.parent-code-card p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.55;
}

.parent-code-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(48px, 1fr));
  gap: 10px;
}

.parent-code-input {
  min-height: 58px;
  padding: 0;
  text-align: center;
  color: var(--primary-dark);
  background: #f1f9ff;
  font-size: 24px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.field-error {
  color: var(--danger) !important;
  font-weight: 700;
}

.account-card p {
  color: var(--muted);
  line-height: 1.6;
}

.auth-card-heading {
  text-align: center;
}

.auth-card-heading h3 {
  margin: 6px 0 10px;
  color: var(--ink);
  font-size: 30px;
  line-height: 1.15;
}

.auth-card-heading p {
  margin-bottom: 0;
  font-size: 15px;
  font-weight: 650;
}

.auth-segmented {
  display: inline-flex;
  justify-self: start;
  gap: 4px;
  margin-top: 2px;
  padding: 5px;
  border-radius: 18px;
  background: #f2f5f9;
}

.auth-segmented button {
  min-width: 86px;
  min-height: 46px;
  padding: 0 18px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 800;
}

.auth-segmented button.is-active {
  color: #fff;
  background: var(--primary);
  box-shadow: 0 10px 24px rgba(34, 127, 245, 0.25);
}

.auth-form {
  display: grid;
  gap: 18px;
  margin-top: 4px;
}

.auth-field {
  display: grid;
  gap: 9px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
}

.auth-field input {
  width: 100%;
  min-height: 56px;
  padding: 0 18px;
  color: var(--ink);
  border: 1px solid #d3dbe6;
  border-radius: 14px;
  background: #fff;
  font: inherit;
  font-weight: 650;
}

.auth-field input::placeholder {
  color: #9aa7b7;
}

.auth-field small,
.auth-note {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.auth-password-row {
  position: relative;
  display: block;
}

.auth-password-row input {
  padding-right: 56px;
}

.auth-password-row .icon-button {
  position: absolute;
  right: 8px;
  top: 50%;
  min-width: 40px;
  min-height: 40px;
  color: #8d9aaa;
  border: 0;
  background: transparent;
  transform: translateY(-50%);
}

.auth-code-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(42px, 1fr));
  gap: 10px;
}

.auth-code-input {
  min-height: 56px !important;
  padding: 0 !important;
  text-align: center;
  font-size: 22px !important;
  font-weight: 850 !important;
}

.auth-submit {
  width: 100%;
  min-height: 58px;
  margin-top: 4px;
  border-radius: 999px;
  font-size: 16px;
}

.profile-form {
  display: grid;
  gap: 20px;
}

.profile-hero {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 28px;
  margin-bottom: 18px;
}

.profile-hero h3 {
  margin: 0;
  color: var(--ink);
  font-size: 34px;
  line-height: 1.12;
}

.profile-avatar-wrap {
  position: relative;
  width: 118px;
  height: 118px;
}

.profile-avatar {
  display: grid;
  width: 118px;
  height: 118px;
  place-items: center;
  overflow: hidden;
  color: #fff;
  border: 7px solid #dfeeff;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  font-size: 38px;
  font-weight: 850;
  box-shadow: 0 14px 30px rgba(16, 90, 150, 0.12);
}

.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-picker {
  position: absolute;
  right: -6px;
  bottom: 2px;
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  color: var(--ink);
  border: 1px solid #cfd8e3;
  border-radius: 999px;
  background: #eef2f7;
  box-shadow: 0 8px 20px rgba(22, 36, 54, 0.14);
  cursor: pointer;
}

.avatar-picker svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.avatar-picker input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.auth-field input[readonly] {
  color: #5f6b7a;
  background: #fafcff;
}

.profile-actions {
  display: grid;
  gap: 12px;
  margin-top: 4px;
}

.field-success {
  margin: 0;
  color: #14825f;
  font-weight: 750;
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.link-button {
  justify-self: center;
  color: var(--primary-dark);
  background: transparent;
  border: 0;
  font-weight: 750;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 80;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 28px));
  padding: 12px 16px;
  color: #fff;
  background: var(--ink);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

@media (max-width: 820px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    width: 100%;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .workspace,
  .workspace.wide {
    width: 100%;
    padding: 16px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .compare-grid {
    grid-template-columns: 1fr;
  }

  .dictation-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .player-assist,
  .shortcut-strip {
    max-width: 100%;
    justify-content: flex-start;
    justify-items: start;
  }

  .playback-row {
    grid-template-columns: 42px minmax(0, 1fr) 42px;
  }

  .controls {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .hint-box {
    text-align: left;
  }
}

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