/* Phone-first. This page is held in a hand, or propped on a TV stand two metres
   away, by someone who may be mid-star-jump. Big targets, high contrast, no
   scrolling during play. */

:root {
  color-scheme: dark;
  --bg: #0d1117;
  --panel: #161b22;
  --line: #30363d;
  --text: #e6edf3;
  --dim: #8b949e;
  --accent: #58a6ff;
  --good: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

.view { display: none; height: 100%; }
.view.active { display: flex; flex-direction: column; }

/* ── join / loading ─────────────────────────────────────────────────────── */

#join, #loading {
  padding: max(24px, env(safe-area-inset-top)) 22px 28px;
  gap: 14px;
  justify-content: center;
  max-width: 520px;
  margin: 0 auto;
  width: 100%;
}

h1 { font-size: 30px; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 22px; margin: 0; }
.sub { color: var(--dim); margin: 0; }
.note { color: var(--dim); font-size: 13px; margin: 8px 0 0; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 13px; color: var(--dim); text-transform: uppercase; letter-spacing: .1em; }

input {
  font: 600 24px/1 ui-monospace, "Cascadia Mono", Menlo, monospace;
  padding: 16px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  width: 100%;
}
#room { text-transform: uppercase; letter-spacing: .35em; text-align: center; font-size: 34px; }
#name { font-family: inherit; font-size: 20px; }
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  font: 600 17px/1 system-ui, sans-serif;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: 14px 18px;
  cursor: pointer;
}
button.big { padding: 20px; font-size: 19px; background: #238636; border-color: #2ea043; }
button.big:disabled { opacity: .5; }
button.ghost { background: transparent; }

.error { color: var(--bad); margin: 0; font-weight: 600; }

.progress {
  height: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.progress > i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width .15s linear;
}
.progress.indeterminate > i {
  width: 35%;
  animation: slide 1.1s ease-in-out infinite alternate;
}
@keyframes slide { from { transform: translateX(-30%); } to { transform: translateX(200%); } }

/* ── play ───────────────────────────────────────────────────────────────── */

#play { background: #000; }

#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

#video, #overlay, #ghost {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
#video.mirror, #overlay.mirror, #ghost.mirror { transform: scaleX(-1); }

#topbar {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  left: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  pointer-events: none;
}
.pill {
  font: 600 12px/1 ui-monospace, monospace;
  padding: 6px 9px;
  border-radius: 999px;
  background: rgba(13, 17, 23, .78);
  border: 1px solid var(--line);
  color: var(--dim);
}
.pill.ok { color: var(--good); border-color: #2ea043; }
.pill.bad { color: var(--bad); border-color: var(--bad); }

/* §5: the player is often twisted away from the TV, so the match percentage has
   to be readable off the phone itself at a glance. */
#matchWrap {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12px;
  text-align: center;
  pointer-events: none;
  text-shadow: 0 2px 10px rgba(0, 0, 0, .9);
}
#matchPct {
  font: 800 88px/1 system-ui, sans-serif;
  letter-spacing: -0.04em;
  color: var(--dim);
}
#matchPct small { font-size: 32px; font-weight: 700; opacity: .8; }
#matchPct.bad { color: var(--bad); }
#matchPct.warn { color: var(--warn); }
#matchPct.good { color: var(--good); }
#matchPhase { font: 600 15px/1 system-ui; text-transform: uppercase; letter-spacing: .18em; color: var(--text); }
#matchMeta { font: 600 14px/1.6 ui-monospace, monospace; color: var(--dim); }

/* M5: the round's instruction, at the top of the camera view. The pose NAME is
   not enough on its own — §7 learned that the hard way, where poses recorded
   from names alone came out as different shapes. So the written description
   rides along. */
#poseBar {
  position: absolute;
  top: 44px;
  left: 8px;
  right: 8px;
  text-align: center;
  pointer-events: none;
  text-shadow: 0 2px 10px rgba(0, 0, 0, .9);
}
#poseName { font: 800 26px/1.1 system-ui, sans-serif; }
#poseHow { font: 500 14px/1.35 system-ui, sans-serif; color: var(--text); margin-top: 4px; }

/* Verdicts and countdowns, big enough to read from across the room while you
   are bent into a shape. */
#bigMsg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font: 900 92px/1 system-ui, sans-serif;
  pointer-events: none;
  text-shadow: 0 4px 24px rgba(0, 0, 0, .95);
}
#bigMsg.pass { color: var(--good); font-size: 54px; }
#bigMsg.fail { color: var(--bad); font-size: 54px; }
#bigMsg.wait { color: var(--dim); font-size: 34px; }

#visWarn {
  position: absolute;
  top: 50%;
  left: 12px;
  right: 12px;
  transform: translateY(-50%);
  text-align: center;
  font: 700 20px/1.3 system-ui;
  color: #fff;
  background: rgba(248, 81, 73, .88);
  padding: 14px;
  border-radius: 12px;
}

#panel {
  flex: 0 0 auto;
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 10px 12px max(10px, env(safe-area-inset-bottom));
}
.angles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px 8px;
  font: 600 13px/1.3 ui-monospace, monospace;
}
.angles div { display: flex; justify-content: space-between; gap: 4px; }
.angles span { color: var(--dim); font-weight: 400; }
.panelRow { display: flex; gap: 8px; margin-top: 10px; }
.panelRow button { flex: 1 1 auto; padding: 12px; font-size: 15px; }

@media (min-width: 700px) {
  .angles { grid-template-columns: repeat(8, 1fr); }
}

/* ── M3 capture tool (?capture=1) ───────────────────────────────────────── */

.capture { margin-bottom: 12px; }
.capHead { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.capTag {
  font: 700 10px/1 ui-monospace, monospace;
  letter-spacing: .18em;
  padding: 5px 7px;
  border-radius: 4px;
  background: #6e40c9;
  color: #fff;
}
#capProgress { font: 600 12px/1 ui-monospace, monospace; color: var(--dim); }
#capPose { font: 700 24px/1.2 system-ui; }
#capPose small { font-size: 12px; color: var(--dim); letter-spacing: .1em; margin-left: 6px; }
#capPose b { color: var(--good); }
.capHint { font-size: 13px; color: var(--dim); margin: 4px 0 0; }

/* The drawn target next to the written instruction: a stick figure cannot say
   "hand on hip", and the words alone were what went wrong the first time. */
.capHow { display: flex; gap: 12px; align-items: flex-start; margin: 8px 0 12px; }
#capFigure {
  flex: 0 0 auto;
  width: 110px;
  height: 140px;
  background: #010409;
  border: 1px solid var(--line);
  border-radius: 8px;
}
#capDesc { font-size: 14px; line-height: 1.45; }
.capRow { display: flex; gap: 8px; align-items: stretch; }
.capRow button.big { flex: 1 1 auto; padding: 16px; }
.capRow button.ghost { flex: 0 0 52px; font-size: 22px; }

.capResult {
  margin-top: 10px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0d1117;
}
.capResult.good { border-color: #2ea043; }
.capResult.bad { border-color: var(--bad); }
.capMsg { font-size: 13px; margin-bottom: 8px; }
.capResult.bad .capMsg { color: var(--bad); }

.capKotlin {
  font: 500 11px/1.5 ui-monospace, "Cascadia Mono", monospace;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0 0 8px;
  color: #7ee787;
  user-select: all;
}
.capDelta {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px 8px;
  font: 600 12px/1.3 ui-monospace, monospace;
}
.capDelta > div { display: flex; gap: 3px; align-items: baseline; }
.capDelta span { color: var(--dim); font-weight: 400; }
.capDelta em { color: var(--dim); font-style: normal; font-size: 11px; }
.capDelta .off em { color: var(--warn); }
.capMeta { font-size: 11px; color: var(--dim); margin-top: 8px; }

#capAll { margin-top: 10px; font-size: 13px; color: var(--dim); }
#capAll summary { cursor: pointer; padding: 6px 0; }
#capAll .capKotlin { max-height: 30vh; overflow: auto; }

/* The countdown must be readable from across the room, over the video. */
#capCountdown {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font: 800 34vw/1 system-ui;
  color: #fff;
  text-shadow: 0 4px 30px rgba(0, 0, 0, .95);
  pointer-events: none;
  z-index: 10;
}
/* A word needs to be much smaller than a single digit to still fit. */
#capCountdown.word { font-size: 15vw; letter-spacing: .06em; }
#capCountdown:not([hidden]) { display: flex; }
