:root {
  --yellow: #ffe500;
  --magenta: #ff0a78;
  --black: #000;
  --paper: #0a0a0a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--black);
  color: var(--yellow);
}

body {
  font-family: "Barlow Condensed", Impact, "Arial Narrow", sans-serif;
  font-style: italic;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

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

.straight, input, select, .fine, time {
  font-family: Barlow, "Segoe UI", sans-serif;
  font-style: normal;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-transform: none;
}

.bg-slash {
  position: fixed;
  inset: -30%;
  background: linear-gradient(112deg, var(--yellow) 0 40%, #000 40% 47%, var(--magenta) 47% 100%);
  z-index: -2;
}

.halftone-layer {
  position: fixed;
  inset: 0;
  background-image: radial-gradient(rgba(0, 0, 0, 0.45) 1.15px, transparent 1.25px);
  background-size: 7px 7px;
  z-index: -1;
  pointer-events: none;
}

.screen {
  display: none;
  min-height: 100%;
  height: 100%;
  position: relative;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

#screen-age,
#screen-home {
  background: transparent;
}

#screen-pick,
#screen-attempt,
#screen-result,
#screen-admin {
  background: #000;
}

#screen-pick.active,
#screen-result.active,
#screen-admin.active {
  overflow: auto;
}

#screen-age.active,
#screen-home.active {
  align-items: center;
  justify-content: center;
  padding: max(1.2rem, env(safe-area-inset-top)) 1.1rem max(1.4rem, env(safe-area-inset-bottom));
  gap: 2rem;
}

#screen-home.active {
  justify-content: space-between;
  padding-top: 8vh;
  padding-bottom: 7vh;
}

.brand { text-align: center; }

.mark {
  width: 84px;
  height: 84px;
  border: 3px solid #000;
  box-shadow: 5px 5px 0 var(--magenta);
  transform: rotate(-6deg);
  background: var(--yellow);
}

.eyebrow {
  margin: 0.4rem 0 0;
  color: var(--magenta);
  font-size: 1rem;
  letter-spacing: 0.22em;
}

.logo {
  margin: 0.1rem 0;
  font-size: clamp(6.2rem, 30vw, 11rem);
  line-height: 0.78;
  font-weight: 900;
  color: var(--yellow);
  -webkit-text-stroke: 3px #000;
  text-shadow: 8px 8px 0 var(--magenta);
  transform: skewX(-8deg);
}

.logo-sm {
  font-size: clamp(4.2rem, 22vw, 6.5rem);
  text-shadow: 6px 6px 0 var(--magenta);
}

.panel {
  width: min(28rem, 100%);
  background: #000;
  border: 4px solid var(--yellow);
  box-shadow: 10px 10px 0 var(--magenta);
  padding: 1.2rem 1.15rem 1.3rem;
  transform: skewX(-6deg);
}

.panel > * { transform: skewX(6deg); }

.panel p { margin: 0.3rem 0 0.9rem; line-height: 1.35; }

label { display: block; margin-bottom: 0.35rem; font-size: 0.95rem; }

select, input[type="password"], input[type="number"] {
  width: 100%;
  background: #111;
  border: 3px solid var(--yellow);
  color: var(--yellow);
  padding: 0.7rem 0.75rem;
  margin-bottom: 0.9rem;
  border-radius: 0;
}

.action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--yellow);
  color: #000;
  border: 4px solid #000;
  box-shadow: 6px 6px 0 var(--magenta);
  transform: skewX(-10deg);
  padding: 0.65rem 1.4rem;
  font-size: 1.7rem;
  font-weight: 900;
  cursor: pointer;
  text-transform: uppercase;
}

.action span { transform: skewX(10deg); display: inline-block; }

.action.huge { font-size: clamp(2.2rem, 8vw, 3.2rem); padding: 0.85rem 2.2rem; }

.action.alt {
  background: var(--magenta);
  color: #fff;
  box-shadow: 6px 6px 0 var(--yellow);
}

.action:disabled { opacity: 0.55; cursor: wait; }

.action:active { transform: skewX(-10deg) translate(2px, 2px); box-shadow: 3px 3px 0 var(--magenta); }

.text-btn {
  background: transparent;
  border: 0;
  color: var(--yellow);
  font-size: 1.15rem;
  cursor: pointer;
  text-decoration: none;
  padding: 0.2rem 0.1rem;
}

.alert { color: var(--magenta); min-height: 1.2em; }

.bar-head {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: max(0.7rem, env(safe-area-inset-top)) 0.9rem 0.6rem;
  background: var(--yellow);
  color: #000;
  transform: skewX(-8deg);
  margin: 0.6rem 0.5rem 0.8rem;
  box-shadow: 6px 6px 0 var(--magenta);
}

.bar-head > * { transform: skewX(8deg); }

.bar-head h2 { margin: 0; font-size: 1.8rem; flex: 1; }

.combo-list {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  padding: 0.2rem 0.9rem 1.4rem;
}

.card {
  display: grid;
  grid-template-columns: 108px 1fr;
  min-height: 118px;
  background: #120010;
  color: var(--yellow);
  border: 3px solid var(--yellow);
  text-align: left;
  cursor: pointer;
  padding: 0;
  clip-path: polygon(0 0, 100% 0, 100% 78%, 94% 100%, 0 100%);
  box-shadow: 6px 6px 0 var(--magenta);
}

.card img {
  width: 108px;
  height: 100%;
  object-fit: cover;
  filter: contrast(1.05) saturate(1.1);
  background: #000;
}

.card-body {
  padding: 0.65rem 0.75rem 0.8rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.25rem;
}

.card-name { font-size: 1.55rem; line-height: 0.95; }

.bpm, .dur {
  display: inline-block;
  transform: skewX(-8deg);
  padding: 0.05rem 0.45rem;
  font-size: 1.05rem;
}

.bpm { background: var(--magenta); color: #fff; }
.dur { background: var(--yellow); color: #000; margin-left: 0.35rem; }

.pad { padding: 0 1rem; }

.attempt { background: #000; }

.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0.45rem;
  align-items: end;
  padding: max(0.45rem, env(safe-area-inset-top)) 0.55rem 0.4rem;
  background:
    radial-gradient(rgba(0, 0, 0, 0.25) 1px, transparent 1.1px) 0 0 / 6px 6px,
    var(--yellow);
  color: #000;
}

.hp-block.master { text-align: right; }

.hp-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
}

.hp-block.master .hp-label { flex-direction: row-reverse; }

.hp-track {
  height: 16px;
  background: #111;
  border: 2px solid #000;
  transform: skewX(-14deg);
  overflow: hidden;
}

.hp-fill { height: 100%; width: 100%; }
.hp-fill.you {
  margin-left: auto;
  background: linear-gradient(90deg, #fff4a8, var(--yellow));
}
.hp-fill.master { background: linear-gradient(90deg, var(--magenta), #ff8abf); }

.vs {
  align-self: center;
  background: #000;
  color: var(--yellow);
  padding: 0.15rem 0.4rem;
  transform: skewX(-10deg);
  font-size: 1.15rem;
}

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

#cam {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  pointer-events: none;
}

#skel {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(0, 0, 0, 0.55) 100%);
  z-index: 2;
}

.pip {
  position: absolute;
  right: 10px;
  bottom: 14px;
  width: min(34vw, 168px);
  aspect-ratio: 3 / 4;
  border: 3px solid var(--yellow);
  box-shadow: 4px 4px 0 var(--magenta);
  transform: rotate(-3deg);
  overflow: hidden;
  z-index: 4;
  background: #000;
}

.pip video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.pip-tag {
  position: absolute;
  left: 0;
  top: 0;
  background: var(--magenta);
  color: #fff;
  font-size: 0.8rem;
  padding: 0.05rem 0.35rem;
}

.count-pop {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(6rem, 28vw, 9rem);
  font-weight: 900;
  color: var(--yellow);
  -webkit-text-stroke: 3px #000;
  text-shadow: 8px 8px 0 var(--magenta);
  z-index: 5;
  pointer-events: none;
  transform: skewX(-8deg);
}

.count-pop.go { color: var(--magenta); text-shadow: 8px 8px 0 var(--yellow); }

.count-pop.pop { animation: pop 0.22s ease-out; }

@keyframes pop {
  from { transform: scale(1.35) skewX(-8deg); }
  to { transform: scale(1) skewX(-8deg); }
}

.combo-pop {
  position: absolute;
  left: 10px;
  bottom: 14px;
  z-index: 4;
  min-width: 108px;
  background: #000;
  border: 3px solid var(--yellow);
  padding: 0.25rem 0.45rem 0.35rem;
  transform: skewX(-8deg);
  box-shadow: 4px 4px 0 var(--magenta);
}

.combo-num {
  font-size: 2.4rem;
  line-height: 0.85;
}

.combo-pop.hot .combo-num { color: var(--magenta); }

.combo-track {
  height: 8px;
  background: #222;
  margin: 0.15rem 0;
}

#combo-fill { height: 100%; width: 0; background: var(--magenta); }

.combo-pop span { font-size: 0.85rem; letter-spacing: 0.14em; }

.ready-layer {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  padding: 1rem;
  background:
    radial-gradient(rgba(255, 229, 0, 0.18) 1px, transparent 1.15px) 0 0 / 8px 8px,
    rgba(0, 0, 0, 0.72);
  text-align: center;
}

.ready-layer[hidden] { display: none; }

.attempt-name {
  margin: 0;
  font-size: clamp(2.2rem, 9vw, 3.4rem);
  line-height: 0.9;
  text-shadow: 4px 4px 0 var(--magenta);
}

.attempt-meta, .fine { margin: 0; }

.fine { opacity: 0.8; font-size: 0.85rem; max-width: 18rem; }

#screen-result.active {
  align-items: center;
  padding: max(1rem, env(safe-area-inset-top)) 1rem 1.4rem;
  background:
    radial-gradient(rgba(255, 10, 120, 0.35) 1px, transparent 1.2px) 0 0 / 8px 8px,
    #000;
}

.result-title {
  margin: 0.2rem 0 0;
  font-size: clamp(5rem, 24vw, 8rem);
  line-height: 0.8;
  transform: skewX(-8deg);
  text-shadow: 7px 7px 0 var(--magenta);
}

.result-title.lose { color: #fff; text-shadow: 7px 7px 0 var(--magenta); }

.result-sub {
  margin: 0.2rem 0 0.4rem;
  background: var(--magenta);
  color: #fff;
  padding: 0.1rem 0.7rem;
  transform: skewX(-10deg);
  font-size: 1.6rem;
}

.dpi-wrap {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  margin: 0.4rem 0 0.6rem;
}

.dpi-wrap span { font-size: 1.4rem; letter-spacing: 0.16em; }

.dpi-wrap strong {
  font-size: 4rem;
  line-height: 0.85;
  color: var(--yellow);
}

.stats {
  list-style: none;
  margin: 0;
  padding: 0;
  width: min(28rem, 100%);
}

.stat {
  display: grid;
  grid-template-columns: 7.2rem 1fr 2.6rem;
  gap: 0.45rem;
  align-items: center;
  margin: 0.35rem 0;
  font-size: 1.15rem;
}

.stat .track {
  display: block;
  height: 14px;
  background: #1a1a1a;
  border: 2px solid var(--yellow);
  transform: skewX(-12deg);
  overflow: hidden;
}

.stat .fill { display: block; height: 100%; width: 0; background: var(--magenta); transition: width .6s ease-out; }
.stat .fill.alt { background: var(--magenta); }

.result-combo { margin: 0.4rem 0 0.8rem; }

.result-actions { display: flex; gap: 0.8rem; flex-wrap: wrap; justify-content: center; }

.admin-panel { margin: 0.4rem auto; }

.admin-body {
  padding: 0.4rem 1rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.7rem;
}

.sync-status, .sync-counts { margin: 0; line-height: 1.4; max-width: 36rem; }

:focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: 3px;
}

@media (min-width: 900px) {
  body { background: #050505; }
  .screen.active { width: min(480px, 100%); margin: 0 auto; box-shadow: 0 0 0 3px var(--magenta); }
  .bg-slash, .halftone-layer { width: min(480px, 100%); left: 50%; transform: translateX(-50%); }
}

/* v2: mirror reference, framing guide, quiet performance view */
.pip video { transform: scaleX(-1); }
.no-ref .pip { display: none; }
.frame-layer { position: absolute; left: 0; right: 0; bottom: 18%; z-index: 5; display: flex; flex-direction: column; align-items: center; gap: .5rem; pointer-events: none; }
.frame-msg { margin: 0; background: rgba(0,0,0,.7); color: var(--yellow); font-weight: 900; font-style: italic; padding: .35rem .8rem; font-size: 1.1rem; letter-spacing: .06em; }
.link-btn { pointer-events: auto; background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.6); padding: .3rem .8rem; font-size: .8rem; }
.toggle-btn { background: #000; color: var(--yellow); border: 2px solid var(--yellow); padding: .4rem .9rem; font-weight: 800; letter-spacing: .05em; }
.toggle-btn[aria-pressed="false"] { color: #aaa; border-color: #666; }
.count-pop { inset: auto; top: 10px; left: 10px; width: 2.2rem; height: 2.2rem; font-size: 1.4rem; -webkit-text-stroke: 0; text-shadow: none; background: rgba(0,0,0,.55); border-radius: 50%; transform: none; }
.dancing .stage::after { display: none; }
.dancing .hud { transform: scale(.7); transform-origin: top center; opacity: .75; }
.dancing .combo-pop { transform: scale(.6); transform-origin: bottom left; opacity: .7; }
.dancing .pip { transform: none; border-width: 2px; box-shadow: none; }

.logo, .brand { text-transform: none !important; }

#screen-home .home-brand{display:flex;flex-direction:column;align-items:center;width:min(70vw,320px);margin:0 auto;gap:.6rem}
#screen-home .home-mark{width:100%;height:auto;aspect-ratio:1/1;object-fit:contain}
#screen-home .home-logo{width:100%;text-align:center;font-size:clamp(3rem,22vw,6rem);line-height:1;margin:0}
#screen-home .home-note{width:min(86vw,420px);font-size:.95rem;line-height:1.4;text-align:center;color:#ddd}
#screen-home .home-note p{margin:.4rem 0}

/* ---------- Learn mode ---------- */
.card { cursor: default; }
.card-actions { display: flex; gap: .5rem; margin-top: .45rem; }
.mini {
  font: inherit; font-size: .95rem; letter-spacing: .06em; padding: .45rem .7rem;
  background: #120010; color: var(--yellow); border: 2px solid var(--yellow);
  transform: skewX(-8deg); cursor: pointer; box-shadow: 3px 3px 0 var(--magenta);
}
.mini.on, .seg button.on, .chips button.on { background: var(--magenta); color: #fff; border-color: var(--magenta); box-shadow: 3px 3px 0 var(--yellow); }
.card-actions .battle-btn { background: var(--yellow); color: #000; }
.card-actions .learn-btn { background: var(--magenta); color: #fff; border-color: var(--magenta); box-shadow: 3px 3px 0 var(--yellow); }
#screen-learn { background: #000; }
#screen-learn.active { overflow: auto; }
.learn-name { color: var(--magenta); font-size: .8em; }
.learn-stage { position: relative; flex: 1 1 auto; min-height: 42vh; display: flex; align-items: center; justify-content: center; background: #000; border-bottom: 3px solid var(--magenta); }
.learn-video { width: 100%; height: 100%; max-height: 62vh; object-fit: contain; }
.mirror { transform: scaleX(-1); }
.learn-cam { position: absolute; right: .6rem; bottom: .6rem; width: 32%; max-width: 180px; border: 3px solid var(--yellow); box-shadow: 4px 4px 0 var(--magenta); background: #000; }
.learn-cam video { width: 100%; display: block; }
.learn-cam span { position: absolute; left: 0; bottom: 0; background: var(--magenta); color: #fff; font-size: .7rem; padding: .1rem .3rem; }
.learn-status { position: absolute; top: .5rem; left: 0; right: 0; text-align: center; color: var(--magenta); margin: 0; }
.learn-controls { display: flex; flex-direction: column; gap: .7rem; padding: .8rem .9rem max(1rem, env(safe-area-inset-bottom)); }
.learn-row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; justify-content: space-between; margin: 0; }
.learn-label { color: var(--magenta); }
.learn-meta { font-size: .85rem; }
.seg, .chips { display: flex; gap: .35rem; flex-wrap: wrap; }
.chips { flex: 1; justify-content: center; }
.seg button, .chips button { font: inherit; min-width: 2.4rem; padding: .4rem .5rem; background: #120010; color: var(--yellow); border: 2px solid var(--yellow); cursor: pointer; }
#learn-battle { align-self: center; }
