:root {
  --bg: #0d1b0f;
  --panel: #14251a;
  --panel-2: #1a3022;
  --ink: #e8f2ea;
  --muted: #93ab99;
  --accent: #4cd964;
  --accent-2: #ffd166;
  --bad: #ff6b6b;
  --good: #4cd964;
  --warn: #ffd166;
  --radius: 14px;
  font-size: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid #2a4433;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 0.5rem; }
.brand-icon { font-size: 1.4rem; }
.brand h1 { font-size: 1.15rem; letter-spacing: 0.03em; }

.view-toggle { display: flex; border: 1px solid #2a4433; border-radius: 999px; overflow: hidden; }
.toggle-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 0.45rem 0.9rem;
  font-size: 0.85rem;
  cursor: pointer;
}
.toggle-btn.active { background: var(--accent); color: #06230d; font-weight: 700; }

.profile-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid #2a4433;
  flex-wrap: wrap;
}
.profile-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}
.profile-bar select {
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid #2a4433;
  border-radius: 8px;
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
  max-width: 40vw;
}
.mini-btn {
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid #2a4433;
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  font-size: 0.75rem;
  cursor: pointer;
}
.mini-btn.danger { color: var(--bad); border-color: var(--bad); }
a.mini-btn { display: inline-block; text-decoration: none; }

main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 1fr);
  gap: 1rem;
  padding: 1rem;
  width: 100%;
  max-width: 1300px;
  margin: 0 auto;
}

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
}

.stage {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 9 / 14;
  max-height: 82dvh;
}

@media (min-width: 901px) {
  .stage { aspect-ratio: auto; min-height: 560px; }
}

#video, #overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
#overlay { z-index: 2; pointer-events: none; }

.loading {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  background: rgba(8, 16, 10, 0.85);
  text-align: center;
  padding: 1rem;
}
.loading[hidden] { display: none; }
.spinner {
  width: 42px; height: 42px;
  border: 4px solid #2a4433;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.stage-hud {
  position: absolute;
  top: 0.6rem;
  left: 0.6rem;
  right: 0.6rem;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}
.phase-badge {
  background: rgba(13, 27, 15, 0.75);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-weight: 800;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
}
.phase-badge.recording { border-color: var(--bad); color: var(--bad); }
.fps-badge {
  background: rgba(13, 27, 15, 0.6);
  color: var(--muted);
  font-size: 0.7rem;
  padding: 0.3rem 0.55rem;
  border-radius: 999px;
  align-self: flex-start;
}

.stage-controls {
  position: absolute;
  bottom: 0.7rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  justify-content: center;
  width: calc(100% - 1rem);
}

.ctl-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(20, 37, 26, 0.9);
  color: var(--ink);
  border: 1px solid #2a4433;
  border-radius: 999px;
  padding: 0.5rem 0.8rem;
  font-size: 0.8rem;
  cursor: pointer;
  user-select: none;
}
.ctl-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.ctl-btn.primary { background: var(--accent); color: #06230d; font-weight: 700; border-color: var(--accent); }
.ctl-btn.toggle.on { border-color: var(--accent); color: var(--accent); }
.ctl-btn.recording { background: var(--bad); border-color: var(--bad); color: #fff; font-weight: 700; }
.ctl-icon { font-size: 0.95rem; }

.video-scrub {
  position: absolute;
  bottom: 3.6rem;
  left: 0.7rem;
  right: 0.7rem;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(13, 27, 15, 0.8);
  border-radius: 999px;
  padding: 0.35rem 0.6rem;
}
.video-scrub[hidden] { display: none; }
.scrub-btn {
  background: none; border: none; color: var(--ink);
  font-size: 1rem; cursor: pointer; line-height: 1;
}
#scrubBar { flex: 1; accent-color: var(--accent); }
.speed-select {
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid #2a4433;
  border-radius: 8px;
  font-size: 0.75rem;
  padding: 0.2rem 0.3rem;
}

.panels { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }

.panel {
  background: var(--panel);
  border: 1px solid #2a4433;
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
}
.panel h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin-bottom: 0.7rem;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.55rem;
}
.metric {
  background: var(--panel-2);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  border-left: 3px solid var(--muted);
}
.metric.ok { border-left-color: var(--good); }
.metric.warn { border-left-color: var(--warn); }
.metric.bad { border-left-color: var(--bad); }
.metric .m-label { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.metric .m-value { font-size: 1.25rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.metric .m-range { font-size: 0.65rem; color: var(--muted); }

.feedback-list { display: flex; flex-direction: column; gap: 0.55rem; }
.feedback-item {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  background: var(--panel-2);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  font-size: 0.85rem;
  line-height: 1.4;
}
.feedback-item .fi-icon { font-size: 1rem; margin-top: 0.05rem; }
.feedback-item.good { border-left: 3px solid var(--good); }
.feedback-item.warn { border-left: 3px solid var(--warn); }
.feedback-item.bad { border-left: 3px solid var(--bad); }
.feedback-item b { display: block; margin-bottom: 0.15rem; }
.muted { color: var(--muted); font-size: 0.85rem; line-height: 1.45; }

.score-banner {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}
.score-banner .score { font-size: 2rem; font-weight: 900; color: var(--accent); }
.score-banner .score-label { color: var(--muted); font-size: 0.8rem; }

.keyframes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 0.5rem;
}
.keyframe { text-align: center; }
.keyframe img {
  width: 100%;
  border-radius: 10px;
  border: 1px solid #2a4433;
  display: block;
}
.keyframe span { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

.help-list { padding-left: 1.1rem; display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.82rem; color: var(--muted); line-height: 1.45; }
.help-list b { color: var(--ink); }

.consistency-report { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 0.8rem; }
.consistency-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  background: var(--panel-2);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  font-size: 0.78rem;
  border-left: 3px solid var(--muted);
}
.consistency-row.good { border-left-color: var(--good); }
.consistency-row.warn { border-left-color: var(--warn); }
.consistency-row.bad { border-left-color: var(--bad); }
.cr-label { color: var(--muted); }
.cr-value { font-variant-numeric: tabular-nums; font-weight: 700; }

.history-list { display: flex; flex-direction: column; gap: 0.45rem; }
.history-item { background: var(--panel-2); border-radius: 10px; overflow: hidden; }
.hi-summary {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.7rem;
  cursor: pointer;
}
.hi-score {
  font-weight: 800;
  font-size: 1rem;
  min-width: 2.2em;
  color: var(--accent);
}
.hi-date { flex: 1; font-size: 0.78rem; color: var(--muted); }
.hi-delete {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.1rem 0.3rem;
}
.hi-delete:hover { color: var(--bad); }
.hi-details { display: none; padding: 0 0.7rem 0.6rem; }
.history-item.open .hi-details { display: block; }
.hi-thumbs { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.hi-thumbs img { width: 70px; border-radius: 8px; border: 1px solid #2a4433; display: block; }
.history-actions { margin-top: 0.7rem; text-align: right; }

.foot {
  text-align: center;
  color: var(--muted);
  font-size: 0.72rem;
  padding: 0.6rem 1rem 1rem;
}
