:root {
  color-scheme: light;
  --ink: #16201d;
  --muted: #63736d;
  --line: #d9e3dd;
  --panel: #ffffff;
  --soft: #f2f6f3;
  --accent: #146b49;
  --accent-strong: #0b4a32;
  --warn: #b95b14;
  --danger: #a83232;
  --blue: #285d89;
  --shadow: 0 18px 60px rgba(22, 32, 29, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #edf4ef 0%, #f8faf8 48%, #eef3f6 100%);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Hiragino Sans", "Yu Gothic", sans-serif;
}

button,
select,
.file-button {
  font: inherit;
}

button,
.file-button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 0 16px;
  cursor: pointer;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease;
}

button:hover:not(:disabled),
.file-button:hover {
  transform: translateY(-1px);
  border-color: #a7b9af;
}

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

button.primary {
  border-color: #c92828;
  background: #d92d20;
  color: #fff;
}

button.primary:hover:not(:disabled) {
  border-color: #a91f1f;
  background: #c32118;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 20px;
}

.workbench {
  min-height: calc(100vh - 190px);
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.65rem, 3.5vw, 3rem);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 12px;
  font-size: 1rem;
  letter-spacing: 0;
}

.status-pill {
  flex: 0 0 auto;
  min-width: 132px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  padding: 8px 14px;
  color: var(--muted);
  text-align: center;
  font-size: 0.9rem;
}

.status-stack {
  display: none;
  gap: 8px;
  justify-items: end;
}

.mode-pill {
  min-width: 132px;
  border: 1px solid rgba(40, 93, 137, 0.28);
  border-radius: 999px;
  background: rgba(40, 93, 137, 0.09);
  padding: 8px 14px;
  color: var(--blue);
  text-align: center;
  font-size: 0.86rem;
}

.mode-pill.active {
  border-color: rgba(20, 107, 73, 0.36);
  background: rgba(20, 107, 73, 0.1);
  color: var(--accent-strong);
}

.mode-pill.error {
  border-color: rgba(168, 50, 50, 0.3);
  background: rgba(168, 50, 50, 0.1);
  color: var(--danger);
}

.status-pill.ready {
  border-color: rgba(20, 107, 73, 0.35);
  background: rgba(20, 107, 73, 0.1);
  color: var(--accent-strong);
}

.status-pill.recording {
  border-color: rgba(185, 91, 20, 0.35);
  background: rgba(185, 91, 20, 0.11);
  color: var(--warn);
}

.stage-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  align-items: stretch;
}

.camera-panel,
.control-panel,
.result-band,
.detail-panel,
.loop-panel,
.notice-band {
  border: 1px solid rgba(217, 227, 221, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.camera-panel {
  display: grid;
  grid-template-rows: minmax(380px, 1fr) auto;
  overflow: hidden;
}

.video-shell {
  position: relative;
  min-height: 380px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    #101915;
  background-size: 56px 56px;
  overflow: hidden;
}

.media-view,
.overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.media-view {
  display: none;
  object-fit: contain;
  background: #101915;
}

.media-view.active {
  display: block;
}

.overlay {
  pointer-events: none;
}

.analysis-canvas {
  display: none;
}

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: clamp(4rem, 16vw, 11rem);
  font-weight: 900;
  text-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.transport {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 0 16px 12px;
  background: #f8fbf9;
}

.action-hint {
  margin: 0;
  padding: 14px 16px 10px;
  background: #f8fbf9;
  color: var(--accent-strong);
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.45;
  text-align: center;
}

.transport button {
  min-height: 60px;
  font-size: 1rem;
  font-weight: 800;
}

.file-button {
  display: grid;
  place-items: center;
  text-align: center;
}

#uploadVideo {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.advanced-controls {
  background: #f8fbf9;
  border-top: 1px solid var(--line);
  padding: 0 16px 16px;
}

.advanced-controls summary {
  min-height: 44px;
  display: grid;
  align-items: center;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

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

.control-panel {
  padding: 16px;
}

.panel-section + .panel-section {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.segmented.compact {
  margin-bottom: 0;
}

.segmented label {
  position: relative;
}

.segmented input {
  position: absolute;
  opacity: 0;
}

.segmented span {
  display: grid;
  min-height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: var(--muted);
  font-weight: 700;
}

.segmented input:checked + span {
  border-color: var(--accent);
  background: rgba(20, 107, 73, 0.1);
  color: var(--accent-strong);
}

.field-row {
  display: grid;
  grid-template-columns: 86px 1fr;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
}

.field-row label,
.field-label {
  color: var(--muted);
  font-size: 0.9rem;
}

select {
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
}

.checkline {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 9px;
  align-items: start;
  margin: 10px 0;
  color: #26332f;
  line-height: 1.45;
}

.checkline input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--accent);
}

.meter-section {
  display: grid;
  gap: 10px;
}

.meter-row {
  display: grid;
  grid-template-columns: 70px 1fr 48px;
  gap: 10px;
  align-items: center;
  font-size: 0.9rem;
}

meter {
  width: 100%;
  height: 14px;
}

.result-band {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 300px;
  gap: 18px;
  align-items: stretch;
  margin-top: 18px;
  padding: 18px;
}

.score-block {
  display: grid;
  align-content: center;
  gap: 6px;
  border-right: 1px solid var(--line);
  padding-right: 18px;
}

.score-label,
.score-block span,
.tips-block li {
  color: var(--muted);
}

#scoreValue {
  font-size: 3.2rem;
  line-height: 1;
  letter-spacing: 0;
}

.advice-block p {
  margin-bottom: 0;
  color: #26332f;
  font-size: 1.05rem;
  line-height: 1.7;
}

.tips-block ul {
  margin: 0;
  padding-left: 20px;
}

.tips-block li + li {
  margin-top: 8px;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr) 280px;
  gap: 18px;
  margin-top: 18px;
}

.detail-panel {
  padding: 16px;
}

.evidence-list {
  margin: 0;
  padding-left: 20px;
  color: #26332f;
  line-height: 1.6;
}

.evidence-list li + li {
  margin-top: 6px;
}

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

.quality-grid span {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfb;
  padding: 10px;
  color: #26332f;
  line-height: 1.4;
}

.report-actions {
  display: grid;
  gap: 10px;
}

.loop-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr) minmax(0, 0.9fr);
  gap: 18px;
  margin-top: 18px;
}

.loop-panel {
  padding: 16px;
}

.agent-list {
  display: grid;
  gap: 10px;
}

.agent-card {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 10px;
  align-items: center;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfb;
  padding: 10px;
}

.agent-card strong {
  font-size: 0.92rem;
}

.agent-card span {
  color: var(--muted);
  line-height: 1.45;
}

.agent-card.done {
  border-color: rgba(20, 107, 73, 0.3);
  background: rgba(20, 107, 73, 0.07);
}

.agent-card.working {
  border-color: rgba(185, 91, 20, 0.28);
  background: rgba(185, 91, 20, 0.08);
}

.practice-list {
  margin: 0;
  padding-left: 22px;
  color: #26332f;
  line-height: 1.65;
}

.history-list {
  display: grid;
  gap: 8px;
  min-height: 72px;
  color: var(--muted);
  line-height: 1.5;
}

.history-item {
  border-left: 3px solid var(--accent);
  padding: 4px 0 4px 10px;
  color: #26332f;
}

#clearHistoryBtn {
  width: 100%;
  margin-top: 12px;
}

.notice-band {
  margin-top: 18px;
  padding: 14px 16px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.6;
}

.notice-band p {
  margin-bottom: 6px;
}

.notice-band p:last-child {
  margin-bottom: 0;
}

@media (max-width: 1020px) {
  .stage-grid,
  .result-band,
  .detail-grid,
  .loop-grid {
    grid-template-columns: 1fr;
  }

  .score-block {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding-right: 0;
    padding-bottom: 14px;
  }

  .control-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }

  .panel-section + .panel-section {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 12px;
  }

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

  .status-stack {
    display: none;
  }

  .camera-panel {
    grid-template-rows: minmax(310px, 58vh) auto;
  }

  .transport,
  .advanced-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .transport button:first-child,
  .transport button:nth-child(4) {
    grid-column: 1 / -1;
  }

  .control-panel {
    grid-template-columns: 1fr;
  }

  .agent-card {
    grid-template-columns: 1fr;
  }

  .field-row,
  .meter-row,
  .quality-grid {
    grid-template-columns: 1fr;
  }
}
