:root {
  color-scheme: light;
  --bg: #f5f4ed;
  --surface: #faf9f5;
  --surface-strong: color-mix(in oklch, var(--surface) 82%, white);
  --surface-muted: color-mix(in oklch, var(--border) 42%, var(--surface));
  --fg: #141413;
  --muted: #5e5d59;
  --border: #e8e6dc;
  --accent: #c96442;
  --danger: #a23d35;
  --shadow-ring: 0 0 0 1px color-mix(in oklch, var(--fg) 8%, transparent);
  --shadow-soft: 0 22px 56px color-mix(in oklch, var(--fg) 8%, transparent);
  --font-display: "Songti SC", "Noto Serif CJK SC", "Iowan Old Style", Georgia, serif;
  --font-body: -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, monospace;
  --radius: 12px;
  --radius-lg: 20px;
  --container: 1180px;
  --gutter: clamp(18px, 4vw, 36px);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 8% 0%, color-mix(in oklch, var(--surface) 72%, transparent), transparent 32rem),
    var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  letter-spacing: 0;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

button,
input,
video,
audio,
a {
  font: inherit;
}

button {
  cursor: pointer;
}

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

a {
  color: inherit;
  text-decoration: none;
}

p,
h1,
h2,
h3,
figure {
  margin: 0;
}

h1,
h2,
h3 {
  color: var(--fg);
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: 0;
  text-wrap: balance;
}

h1 {
  font-size: clamp(34px, 4.6vw, 58px);
  line-height: 1.12;
}

h2 {
  font-size: clamp(22px, 2.4vw, 34px);
  line-height: 1.16;
}

.shell {
  width: min(100%, var(--container));
  margin-inline: auto;
  padding: clamp(18px, 3vw, 34px) var(--gutter) clamp(54px, 7vw, 96px);
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: clamp(20px, 4vw, 40px);
  align-items: end;
  padding: 0 0 clamp(14px, 2.5vw, 24px);
  border-bottom: 1px solid var(--border);
}

.app-topbar {
  display: block;
}

.app-topbar:has(.status-strip:not(.hidden)) {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 520px);
  gap: clamp(18px, 4vw, 52px);
}

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

.eyebrow {
  margin: 0 0 12px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.lead {
  max-width: 64ch;
  margin-top: 10px;
  color: var(--muted);
  font-size: clamp(15px, 1.3vw, 18px);
  line-height: 1.6;
  text-wrap: pretty;
}

.label,
.hint,
.save-state,
.platform-name,
.meta {
  color: var(--muted);
  font-size: 13px;
}

.label,
.meta {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.intake-state,
.status-strip,
.result-band,
.table-section,
.done-state,
.error-state,
.reference-block {
  margin-top: clamp(22px, 3vw, 34px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-ring);
}

.intake-state {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(320px, 420px);
  gap: clamp(20px, 4vw, 42px);
  align-items: center;
  padding: clamp(20px, 3vw, 30px);
}

.intake-copy p {
  max-width: 62ch;
  margin-top: 12px;
  color: var(--muted);
  line-height: 1.7;
  text-wrap: pretty;
}

.name-form {
  display: grid;
  gap: 12px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in oklch, var(--surface) 74%, var(--bg));
}

.name-form label {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 13px;
}

.name-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.entry-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: stretch;
}

.entry-actions {
  display: flex;
  gap: 10px;
}

input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--fg);
  padding: 10px 13px;
  box-shadow: var(--shadow-ring);
}

input::placeholder {
  color: color-mix(in oklch, var(--muted) 82%, white);
}

.hint {
  line-height: 1.55;
}

.status-strip {
  display: grid;
  grid-template-columns: auto minmax(150px, 1fr);
  gap: clamp(12px, 2.2vw, 22px);
  align-items: center;
  padding: clamp(14px, 2.1vw, 20px);
}

.app-topbar .status-strip {
  margin-top: 0;
  align-self: end;
}

.status-strip strong,
.metric strong,
.result-row strong {
  display: block;
  font-family: var(--font-display);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.status-strip strong {
  margin-top: 2px;
  font-size: 30px;
}

.progress-note {
  grid-column: 2;
  color: var(--muted);
  font-size: 13px;
  text-align: left;
  white-space: nowrap;
}

.progress-track,
.share-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-muted);
  box-shadow: inset 0 0 0 1px color-mix(in oklch, var(--fg) 4%, transparent);
}

.progress-bar,
.share-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  transition: width 0.2s ease;
}

.progress-bar,
.share-bar.niwa,
.share-bar.feiying {
  background: var(--fg);
}

.test-state {
  margin-top: clamp(16px, 2.6vw, 26px);
}

.sample-line,
.section-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  margin-bottom: 12px;
}

.sample-line {
  color: var(--muted);
  font-family: var(--font-display);
  font-size: clamp(19px, 2vw, 26px);
  line-height: 1.25;
}

.save-state {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  width: fit-content;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-ring);
  white-space: nowrap;
}

.save-state::before {
  content: "";
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 999px;
  background: currentColor;
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(18px, 3vw, 34px);
  align-items: stretch;
}

.single-video-grid {
  display: grid;
  place-items: center;
}

.video-panel {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-ring);
}

.single-video-panel {
  width: min(100%, 560px);
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 62px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in oklch, var(--surface) 74%, var(--bg));
  font-weight: 700;
}

.option-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--fg);
  color: var(--surface);
  font-family: var(--font-display);
  font-size: 18px;
  line-height: 1;
}

video {
  display: block;
  width: min(100%, 360px);
  margin: clamp(14px, 3vw, 28px) auto 10px;
  aspect-ratio: 16 / 9;
  border-radius: 18px;
  background: var(--fg);
  box-shadow: var(--shadow-soft);
}

#videoA,
#videoB,
#originVideo,
#ratingVideo,
.modal-video {
  aspect-ratio: 9 / 16;
  object-fit: contain;
}

audio {
  width: 100%;
}

.choice-button,
.secondary-button,
.ghost-link {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0;
  transition:
    transform 0.08s ease,
    background 0.16s ease,
    border-color 0.16s ease,
    color 0.16s ease;
  white-space: nowrap;
}

.choice-button {
  width: calc(100% - 36px);
  margin: 10px 18px 18px;
  border: 1px solid var(--fg);
  background: var(--fg);
  color: var(--surface);
  font-weight: 700;
}

.start-button {
  width: auto;
  min-height: 46px;
  margin: 0;
  border-color: var(--accent);
  background: var(--accent);
}

.alt-start {
  border-color: var(--border);
  background: var(--surface);
  color: var(--fg);
}

.rating-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 10px 18px 18px;
}

.rating-button {
  width: 100%;
  margin: 0;
}

.choice-button:hover,
.choice-button.selected {
  background: color-mix(in oklch, var(--fg) 90%, var(--surface));
  border-color: color-mix(in oklch, var(--fg) 90%, var(--surface));
}

.start-button:hover {
  background: color-mix(in oklch, var(--accent) 88%, var(--fg));
  border-color: color-mix(in oklch, var(--accent) 88%, var(--fg));
}

.choice-button:active,
.secondary-button:active,
.ghost-link:active {
  transform: translateY(1px);
}

.secondary-button,
.ghost-link {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  padding: 10px 16px;
  box-shadow: var(--shadow-ring);
}

.ghost-link:hover,
.secondary-button:hover {
  border-color: color-mix(in oklch, var(--fg) 22%, var(--border));
}

.ghost-link:focus-visible,
.secondary-button:focus-visible,
.choice-button:focus-visible,
input:focus-visible {
  outline: 3px solid color-mix(in oklch, var(--accent) 35%, transparent);
  outline-offset: 2px;
}

.nav-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: clamp(22px, 3vw, 34px);
}

.reference-block {
  overflow: hidden;
  margin-top: clamp(22px, 3vw, 34px);
  padding: 0;
}

.reference-block summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  cursor: pointer;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 500;
}

.reference-grid {
  display: grid;
  grid-template-columns: minmax(220px, 360px) minmax(260px, 1fr);
  gap: 18px;
  padding: 20px;
  border-top: 1px solid var(--border);
  background: color-mix(in oklch, var(--surface) 75%, var(--bg));
}

.done-state,
.error-state,
.table-section {
  padding: clamp(18px, 3vw, 26px);
}

.done-state p {
  margin: 8px 0 16px;
  color: var(--muted);
}

.error-state {
  color: var(--danger);
  border-color: color-mix(in oklch, var(--danger) 42%, var(--border));
  background: color-mix(in oklch, var(--danger) 7%, var(--surface));
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 24px;
}

.metric {
  min-height: 94px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-ring);
}

.metric strong {
  margin-top: 5px;
  font-size: 34px;
}

.compact-metric-grid {
  margin: 0 0 14px;
}

.result-band {
  display: grid;
  gap: 22px;
  padding: clamp(18px, 3vw, 26px);
}

.result-row {
  display: grid;
  grid-template-columns: 90px minmax(140px, 1fr) 54px;
  gap: 14px;
  align-items: center;
}

.result-row strong {
  margin-top: 2px;
  font-size: 28px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  background: var(--surface);
}

.recent-table {
  min-width: 820px;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
  vertical-align: middle;
}

th {
  background: color-mix(in oklch, var(--surface) 74%, var(--bg));
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
}

td {
  font-variant-numeric: tabular-nums;
}

.text-cell {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

tr:last-child td {
  border-bottom: 0;
}

.compact-button {
  min-height: 36px;
  padding: 6px 13px;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

.pager-state {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.video-dialog {
  width: min(900px, calc(100vw - 28px));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--fg);
  padding: 0;
  box-shadow: var(--shadow-soft);
}

.video-dialog::backdrop {
  background: color-mix(in oklch, var(--fg) 58%, transparent);
}

.dialog-shell {
  margin: 0;
  padding: 22px;
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.dialog-video-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.dialog-video-grid figcaption {
  margin-bottom: 8px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 13px;
}

.modal-video {
  width: min(100%, 360px);
  margin: 0 auto;
  border: 1px solid var(--border);
}

.hidden {
  display: none !important;
}

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

@media (max-width: 920px) {
  .app-topbar:has(.status-strip:not(.hidden)) {
    grid-template-columns: 1fr;
  }

  .topbar,
  .intake-state,
  .status-strip,
  .video-grid,
  .reference-grid,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .progress-note {
    text-align: left;
    white-space: normal;
  }
}

@media (max-width: 600px) {
  body {
    background: var(--bg);
  }

  .shell {
    padding-top: 24px;
  }

  h1 {
    font-size: clamp(32px, 11vw, 44px);
  }

  .name-row,
  .entry-row,
  .sample-line,
  .section-head,
  .dialog-video-grid {
    grid-template-columns: 1fr;
  }

  .entry-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .start-button,
  .choice-button {
    width: 100%;
  }

  .choice-button {
    margin-inline: 0;
  }

  .rating-actions {
    grid-template-columns: 1fr;
    padding-inline: 0;
  }

  .video-panel {
    padding-inline: 14px;
  }

  .panel-head {
    margin-inline: -14px;
  }

  video {
    width: min(100%, 330px);
    border-radius: 16px;
  }

  .dialog-head {
    flex-direction: column;
  }

  .pager {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .result-row {
    grid-template-columns: 76px 1fr 54px;
  }
}
