:root {
  --bg: #0f1115; --card: #181b22; --line: #272b34;
  --fg: #e8eaed; --dim: #8b93a1; --accent: #ff6b35; --good: #3ddc84; --bad: #ff5568;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 3rem;
}
main { max-width: 720px; margin: 0 auto; padding: 1rem; }
h1 { font-size: 1.3rem; margin: .5rem 0 1rem; }
h2 { font-size: 1rem; color: var(--dim); margin: 1.5rem 0 .5rem; font-weight: 600; }
a { color: var(--accent); }

nav {
  display: flex; gap: .25rem; padding: .5rem; background: var(--card);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
  overflow-x: auto; scrollbar-width: none;
}
nav::-webkit-scrollbar { display: none; }
nav a {
  padding: .45rem .7rem; border-radius: 8px; text-decoration: none;
  color: var(--dim); white-space: nowrap;
}
nav a.on { background: var(--accent); color: #fff; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 1rem; margin-bottom: 1rem;
}
.row { display: flex; gap: 1rem; flex-wrap: wrap; }
.row > .card { flex: 1 1 140px; }
.big { font-size: 2.2rem; font-weight: 700; line-height: 1.1; }
.dim { color: var(--dim); font-size: .85rem; }

/* progress bar */
.track { height: 10px; background: var(--line); border-radius: 6px; overflow: hidden; }
.track > div { height: 100%; background: var(--accent); width: 0; transition: width .35s; }

/* --- camera --------------------------------------------------------- */
.stage { position: relative; background: #000; border-radius: 14px; overflow: hidden; }
.stage video, .stage canvas { width: 100%; display: block; }
.stage canvas { position: absolute; inset: 0; height: 100%; }
/* Front camera is shown like a mirror; the skeleton has to flip with it. */
.stage.mirrored video, .stage.mirrored canvas { transform: scaleX(-1); }

.count {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  font-size: 22vw; font-weight: 800; color: #fff;
  text-shadow: 0 4px 24px rgba(0, 0, 0, .8); pointer-events: none;
}
@media (min-width: 720px) { .count { font-size: 150px; } }

/* the combo kicks in at rep 10: bigger, coloured, and it pops on every rep */
.count.combo { font-size: 30vw; }
@media (min-width: 720px) { .count.combo { font-size: 200px; } }
.count.tier-white  { color: #fff; }
.count.tier-yellow { color: #ffd93d; text-shadow: 0 0 30px rgba(255, 217, 61, .6); }
.count.tier-orange { color: #ff9f1c; text-shadow: 0 0 36px rgba(255, 159, 28, .7); }
.count.tier-red    { color: #ff3b3b; text-shadow: 0 0 44px rgba(255, 59, 59, .85);
                     animation: pulse .9s ease-in-out infinite; }

.count.pop { animation: pop .32s cubic-bezier(.2, 1.6, .4, 1); }
.count.tier-red.pop { animation: pop .32s cubic-bezier(.2, 1.6, .4, 1), pulse .9s .32s ease-in-out infinite; }

@keyframes pop {
  0%   { transform: translate(-50%, -50%) scale(1)   rotate(0deg); }
  45%  { transform: translate(-50%, -50%) scale(1.4) rotate(-3deg); }
  100% { transform: translate(-50%, -50%) scale(1)   rotate(0deg); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .72; }
}
@media (prefers-reduced-motion: reduce) {
  .count, .count.pop, .count.tier-red.pop { animation: none !important; }
}

.hint {
  position: absolute; left: 50%; bottom: 1rem; transform: translateX(-50%);
  background: rgba(0, 0, 0, .75); padding: .5rem 1rem; border-radius: 14px;
  font-size: .95rem; opacity: 0; transition: opacity .25s;
  /* errors can be long - wrap them instead of running off both edges */
  max-width: 92%; text-align: center; overflow-wrap: anywhere;
}
.hint.show { opacity: 1; }
.hint.bad { color: var(--bad); }
.hint.good { color: var(--good); }

.debug {
  position: absolute; left: 0; right: 0; top: 0; padding: .35rem .6rem;
  background: rgba(0, 0, 0, .65); font: 600 .8rem/1.3 ui-monospace, monospace;
  color: #7ee787; text-align: center;
}

button {
  font: inherit; font-weight: 600; padding: .8rem 1.2rem; border: 0;
  border-radius: 12px; background: var(--accent); color: #fff; cursor: pointer;
}
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: var(--line); color: var(--fg); }
.controls { display: flex; gap: .5rem; align-items: center; margin-top: 1rem; }
.controls button:first-child { flex: 1; }

input[type=text], input[type=password], input[type=number], select {
  font: inherit; width: 100%; padding: .7rem; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--fg);
}
label { display: block; margin: .75rem 0 .25rem; color: var(--dim); font-size: .9rem; }

/* --- heatmap -------------------------------------------------------- */
.heatmap {
  display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 12px);
  gap: 3px; overflow-x: auto; padding-bottom: .5rem;
}
.heatmap i { width: 12px; height: 12px; border-radius: 3px; background: var(--line); }
.heatmap i.l1 { background: #4a2a1a; }
.heatmap i.l2 { background: #8a441f; }
.heatmap i.l3 { background: #d1622a; }
.heatmap i.l4 { background: var(--accent); }
.heatmap i.frozen { background: #2b4a6b; }

/* --- awards --------------------------------------------------------- */
.awards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; }
.award {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: .8rem; text-align: center; opacity: .45; filter: grayscale(1);
}
.award.on { opacity: 1; filter: none; border-color: var(--accent); }
.award .icon { font-size: 2rem; display: block; }
.award b { display: block; margin: .3rem 0; font-size: .9rem; }

#toasts { position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%); z-index: 50; }
.toast {
  display: flex; gap: .7rem; align-items: center; margin-top: .5rem;
  background: var(--card); border: 1px solid var(--accent); border-radius: 12px;
  padding: .7rem 1rem; animation: rise .3s ease-out;
}
.toast .icon { font-size: 1.8rem; }
@keyframes rise { from { transform: translateY(20px); opacity: 0; } }

table { width: 100%; border-collapse: collapse; }
td { padding: .4rem 0; border-bottom: 1px solid var(--line); }
td:last-child { text-align: right; font-weight: 600; }
