:root {
  --felt-900: #06170f;
  --felt-800: #0a2418;
  --felt-700: #0f3322;
  --felt-600: #15452e;
  --line: #24563d;
  --gold: #d9b45a;
  --gold-bright: #f0cf7a;
  --text: #eef3ee;
  --muted: #a9bfb0;
  --good: #5fd08a;
  --bad: #ff7a6b;
  --radius: 12px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

/* The hidden attribute wins over any display rule below. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 50% -10%, #1b5a3b 0%, transparent 60%),
    var(--felt-900);
  color: var(--text);
  font:
    15px/1.5 system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    sans-serif;
}

h1,
h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  letter-spacing: 0.02em;
}

h1 {
  font-size: 1.5rem;
  color: var(--gold-bright);
}

h2 {
  font-size: 1.05rem;
  color: var(--gold);
  margin-bottom: 12px;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Header and levels */
.top {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 32px;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 8px;
  max-width: 1240px;
  margin: 0 auto;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  color: var(--gold-bright);
  font-family: Georgia, serif;
  font-weight: 700;
}

.sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.levels {
  flex: 1 1 420px;
  max-width: 640px;
}

.levels-head,
.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.level-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.level {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--felt-800);
}

.level.passed {
  border-color: var(--gold);
}

.level.locked {
  opacity: 0.55;
}

.level-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  color: var(--gold-bright);
}

.level-name svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.level-desc {
  color: var(--muted);
  font-size: 0.8rem;
}

.level button {
  padding: 6px 8px;
  font-size: 0.85rem;
}

/* Layout */
/* One stacked column: New exercise on top, then a full-width player. */
.layout {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 12px 24px 24px;
  max-width: 1240px;
  margin: 0 auto;
}

.panel {
  background: linear-gradient(180deg, var(--felt-700), var(--felt-800));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.35);
}

.banner {
  max-width: 1192px;
  margin: 8px auto 0;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: #4a1a14;
  border: 1px solid var(--bad);
  color: #ffd9d3;
}

/* Forms */
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
  min-width: 0;
}

label {
  color: var(--muted);
  font-size: 0.85rem;
}

input,
select {
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--felt-900);
}

input:disabled {
  opacity: 0.5;
}

input[aria-invalid="true"] {
  border-color: var(--bad);
}

.inline {
  display: flex;
  gap: 8px;
}

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

button {
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--gold);
  padding: 9px 16px;
  background: transparent;
  white-space: nowrap;
}

/* A link that looks like a button (Download MP4). */
a.button {
  display: inline-block;
  border-radius: 8px;
  border: 1px solid var(--gold);
  padding: 9px 16px;
  text-decoration: none;
  white-space: nowrap;
}

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

.primary {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #1c1405;
  font-weight: 700;
  border-color: var(--gold-bright);
}

.secondary {
  color: var(--gold-bright);
}

.danger {
  color: var(--bad);
  border-color: var(--bad);
}

.link {
  border: none;
  padding: 2px 4px;
  color: var(--gold);
  text-decoration: underline;
}

.help {
  margin: 0 0 12px;
  padding: 10px 12px 10px 28px;
  border-radius: 8px;
  background: var(--felt-900);
  color: var(--muted);
  font-size: 0.82rem;
}

.help li + li {
  margin-top: 4px;
}

.help strong {
  color: var(--gold);
}

.note {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.85rem;
  min-height: 1.3em;
}

.note.warn {
  color: var(--gold-bright);
}

.note.bad,
.error {
  color: var(--bad);
}

.error {
  white-space: pre-wrap;
  margin: 10px 0 0;
  font-size: 0.85rem;
}

/* Exercise card */
.meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
  margin: 0 0 14px;
}

.meta div {
  background: var(--felt-900);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
}

.meta dt {
  color: var(--muted);
  font-size: 0.75rem;
}

.meta dd {
  margin: 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.render-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.progress {
  flex: 1 1 200px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.bar {
  flex: 1;
  height: 10px;
  border-radius: 5px;
  background: var(--felt-900);
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--gold), var(--gold-bright));
  transition: width 0.3s;
}

.progress-text {
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

/* Player */
.video-frame {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.video-frame video {
  width: 100%;
  height: 100%;
  display: block;
}

/* The live Player fills the same 16:9 box and scales 1280x720 to fit. */
.live-host,
.live-host > div {
  position: absolute;
  inset: 0;
}

/* Mounted ahead of time: laid out and decoded, but invisible and inert. */
.live-host.preparing {
  visibility: hidden;
  pointer-events: none;
}

.live-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
}

.live-badge {
  color: var(--muted);
  font-size: 0.85rem;
}

/* The MP4 status next to the Player: it changes on its own, live play doesn't. */
.mp4-row {
  margin-top: 10px;
}

.mp4-row + .error {
  margin-top: 8px;
}

.gen-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
}

.video-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 16px;
  text-align: center;
  color: var(--muted);
}

/* Playback modes: one segmented control, three equal buttons. */
.modes {
  margin-bottom: 12px;
}

.modes-label {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--gold);
  border-radius: 8px;
  overflow: hidden;
}

.segmented button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 0;
  padding: 7px 6px;
  border: none;
  border-radius: 0;
  color: var(--gold-bright);
}

.segmented button + button {
  border-left: 1px solid var(--gold);
}

.segmented button:focus-visible {
  outline-offset: -3px;
}

.segmented button[aria-checked="true"] {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #1c1405;
}

.mode-name {
  font-weight: 700;
}

.mode-time {
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}

.mode-note {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.answer {
  margin-top: 16px;
}

.answer input {
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
  max-width: 200px;
  font-variant-numeric: tabular-nums;
}

.answer button {
  font-size: 1.05rem;
}

.hint {
  color: var(--muted);
  margin: 6px 0 0;
  font-size: 0.85rem;
}

.dev-tools {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.dev-out {
  flex-basis: 100%;
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

/* Result */
.verdict {
  margin: 0 0 12px;
  font-family: Georgia, serif;
  font-size: 2rem;
  font-weight: 700;
}

.verdict.correct {
  color: var(--good);
}

.verdict.wrong {
  color: var(--bad);
}

/* History */
.table-wrap {
  overflow-x: auto;
}

.history {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.history th,
.history td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.history th {
  color: var(--muted);
  font-weight: 600;
}

.history tr.active td {
  background: rgb(217 180 90 / 0.08);
}

.history td:first-child {
  white-space: normal;
  overflow-wrap: anywhere;
}

.history-id {
  display: block;
  font-weight: 600;
}

.history-sub {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.history .actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.history .actions button {
  padding: 4px 8px;
  font-size: 0.8rem;
}

.ok {
  color: var(--good);
}

.no {
  color: var(--bad);
}

.empty {
  color: var(--muted);
  margin: 8px 0 0;
}

.foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 24px 24px;
  color: var(--muted);
  font-size: 0.8rem;
}

.switch {
  display: flex;
  gap: 8px;
  align-items: center;
}

.switch input {
  width: auto;
}

@media (max-width: 900px) {
  .layout {
    padding: 8px 16px 16px;
  }

  .top {
    padding: 16px 16px 4px;
  }

  .foot {
    padding: 0 16px 16px;
  }
}

@media (max-width: 520px) {
  .grid-4,
  .level-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .answer input {
    max-width: none;
  }

  .verdict {
    font-size: 1.6rem;
  }
}
