:root {
  --ink: #1b1035;
  --yellow: #ffd23f;
  --purple: #6c2bd9;
  --pink: #ff3e8a;
  --cyan: #2de1fc;
  --green: #7cf05a;
  --red: #ff3e5a;
  --paper: #fff8e7;
  --display: "Bungee", "Arial Black", Impact, sans-serif;
  --body: "Rubik", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: repeating-linear-gradient(-30deg, #24124d 0 28px, #2b1659 28px 56px);
  color: var(--paper);
  font-family: var(--body);
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

.top {
  width: min(100% - 32px, 960px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0 10px;
}

.logo {
  font-family: var(--display);
  font-size: clamp(18px, 3.4vw, 28px);
  color: var(--yellow);
  text-shadow: 3px 3px 0 var(--ink);
  letter-spacing: 1px;
}
.logo span { color: var(--pink); margin: 0 2px; }

.pips { display: flex; gap: 8px; }
.pip {
  width: 18px; height: 18px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: 3px solid var(--ink);
}
.pip.win { background: var(--green); }
.pip.lose { background: var(--red); }
.pip.now { background: var(--yellow); animation: pulse 0.6s ease-in-out infinite alternate; }

.icon-btn {
  background: var(--paper); border: 3px solid var(--ink); border-radius: 10px;
  font-size: 18px; width: 42px; height: 38px; cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
}

#stage {
  position: relative;
  width: min(100vw - 32px, (100vh - 130px) * 4 / 3, 1280px);
  aspect-ratio: 4 / 3;
  border: 5px solid var(--ink);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 8px 8px 0 var(--ink), 0 0 0 9px var(--yellow);
  background: #000;
}

canvas { display: block; width: 100%; height: 100%; }

footer {
  margin: 22px 0 16px;
  font-size: 13px;
  opacity: 0.7;
  letter-spacing: 0.5px;
}

.overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: safe center;
  padding: 16px;
  overflow: auto;
}
.hidden { display: none !important; }

.card {
  background: var(--paper);
  color: var(--ink);
  border: 5px solid var(--ink);
  border-radius: 20px;
  box-shadow: 8px 8px 0 var(--ink);
  padding: clamp(14px, 3vw, 28px);
  width: min(100%, 520px);
  text-align: center;
  margin: auto;
  transform: rotate(-1deg);
}

.day {
  display: inline-block;
  font-family: var(--display);
  font-size: 13px;
  background: var(--purple);
  color: #fff;
  padding: 4px 12px;
  border-radius: 999px;
  letter-spacing: 0.5px;
}

.title {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(26px, 5vw, 42px);
  line-height: 1.05;
  margin: 12px 0 14px;
}
.title em { font-style: normal; color: var(--pink); }

.mystery { display: flex; gap: 8px; justify-content: center; margin-bottom: 10px; }
.tile {
  width: 72px; height: 72px;
  border: 4px solid var(--ink); border-radius: 14px;
  background: var(--yellow);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: 3px 3px 0 var(--ink);
}
.tile:nth-child(odd) { transform: rotate(-3deg); }
.tile:nth-child(even) { transform: rotate(3deg); }
.tile b { font-family: var(--display); font-size: 26px; line-height: 1; }
.tile small { font-size: 9px; font-weight: 700; margin-top: 4px; padding: 0 3px; line-height: 1.1; }
.tile.win { background: var(--green); }
.tile.lose { background: var(--red); color: #fff; }

.sub { margin: 6px 0 12px; font-size: 14px; opacity: 0.8; }

.legend, .cta-keys { display: flex; gap: 6px; justify-content: center; align-items: center; margin-bottom: 16px; }
.legend span { font-family: var(--display); }

kbd {
  font-family: var(--display);
  font-size: 18px;
  min-width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  background: #fff; color: var(--ink);
  border: 3px solid var(--ink); border-radius: 9px;
  box-shadow: 0 4px 0 var(--ink);
  padding: 0 8px;
}
kbd.wide { min-width: 96px; font-size: 14px; }

.big-btn, .ghost-btn {
  font-family: var(--display);
  font-size: 17px;
  border: 4px solid var(--ink);
  border-radius: 14px;
  padding: 12px 20px;
  cursor: pointer;
  box-shadow: 4px 4px 0 var(--ink);
  transition: transform 0.08s;
}
.big-btn { background: var(--pink); color: #fff; }
.ghost-btn { background: #fff; color: var(--ink); }
.big-btn:hover, .ghost-btn:hover { transform: translate(-1px, -1px); }
.big-btn:active, .ghost-btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
#startBtn { animation: pulse 0.7s ease-in-out infinite alternate; }

/* ---------- call to action ---------- */
#cta { pointer-events: none; gap: 6px; }
.cta-count {
  font-family: var(--display); font-size: 18px; color: #fff;
  background: var(--ink); padding: 4px 14px; border-radius: 999px;
}
.cta-text {
  font-family: var(--display);
  font-size: clamp(34px, 8vw, 78px);
  line-height: 1;
  text-align: center;
  color: var(--yellow);
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 6px 6px 0 var(--ink);
  transform: rotate(-4deg);
  margin: 10px 0 2px;
  max-width: 92%;
}
.cta-name { font-weight: 900; font-size: 16px; color: #fff; text-shadow: 2px 2px 0 var(--ink); text-transform: uppercase; letter-spacing: 2px; }
.cta-keys { margin: 12px 0 0; }
.cta-num {
  font-family: var(--display); font-size: 40px; color: #fff;
  text-shadow: 3px 3px 0 var(--ink);
}
.cta-bar {
  width: min(70%, 420px); height: 16px;
  border: 4px solid var(--ink); border-radius: 999px;
  background: rgba(255, 255, 255, 0.3);
  overflow: hidden;
}
.cta-bar i { display: block; height: 100%; width: 100%; background: var(--yellow); transform-origin: left; }

#cta.go .cta-text { animation: slam 0.45s cubic-bezier(.2, 1.6, .4, 1) both, wobble 1.2s 0.45s ease-in-out infinite; }
#cta.go .cta-count { animation: drop 0.35s ease-out both; }
#cta.go .cta-keys { animation: drop 0.35s 0.25s ease-out both; }
#cta.go .cta-bar i { animation: drain 3s linear both; }

@keyframes slam {
  from { transform: scale(3) rotate(-14deg); opacity: 0; }
  to { transform: scale(1) rotate(-4deg); opacity: 1; }
}
@keyframes wobble {
  0%, 100% { transform: rotate(-4deg) scale(1); }
  50% { transform: rotate(-2deg) scale(1.04); }
}
@keyframes drop {
  from { transform: translateY(-30px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@keyframes drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.06); } }

/* ---------- results ---------- */
.score-row { display: flex; align-items: baseline; justify-content: center; gap: 14px; margin: 8px 0 6px; }
.score { font-family: var(--display); font-size: clamp(44px, 8vw, 64px); line-height: 1; color: var(--purple); }
.grade { font-family: var(--display); font-size: 20px; color: var(--pink); }

.res-list { list-style: none; padding: 0; margin: 8px 0 12px; display: grid; gap: 5px; }
.res-list li {
  display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 10px;
  padding: 6px 12px; border: 3px solid var(--ink); border-radius: 10px;
  font-weight: 700; text-align: left;
}
.res-list li.win { background: #d9fbcc; }
.res-list li.lose { background: #ffd3da; }
.res-list .mark { font-size: 18px; }
.res-list .tm { font-family: var(--display); font-size: 13px; opacity: 0.7; }

.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 14px; }
.stats div { display: flex; flex-direction: column; }
.stats b { font-family: var(--display); font-size: 22px; font-weight: 400; }
.stats span { font-size: 10px; font-weight: 700; text-transform: uppercase; opacity: 0.7; }

.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.next { margin-top: 12px; font-family: var(--display); font-size: 14px; opacity: 0.75; }

/* ---------- admin ---------- */
.pips { flex-wrap: wrap; justify-content: center; }
.pips.many { gap: 4px; max-width: 50%; }
.pips.many .pip { width: 12px; height: 12px; border-width: 2px; }

.card.wide { width: min(100%, 1120px); transform: none; text-align: left; padding: 18px; }
.admin-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.admin-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ghost-btn.sm { font-size: 12px; padding: 6px 12px; border-width: 3px; border-radius: 10px; box-shadow: 3px 3px 0 var(--ink); }
.chk { font-weight: 700; font-size: 14px; display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.chk input { width: 18px; height: 18px; accent-color: var(--pink); }
.card.wide .sub { margin: 10px 0 12px; }

.admin-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 12px; }
.gcard {
  background: #fff; border: 3px solid var(--ink); border-radius: 14px;
  overflow: hidden; cursor: pointer; user-select: none;
  box-shadow: 3px 3px 0 var(--ink);
  transition: transform 0.1s, box-shadow 0.1s, background 0.1s;
}
.gcard:hover { transform: translate(-2px, -2px); box-shadow: 5px 5px 0 var(--ink); }
.gcard.sel { background: var(--yellow); box-shadow: 0 0 0 4px var(--pink), 5px 5px 0 var(--ink); }
.thumb { position: relative; border-bottom: 3px solid var(--ink); aspect-ratio: 4 / 3; }
.thumb canvas { display: block; width: 100%; height: 100%; }
.thumb .order:not(:empty) {
  position: absolute; top: 6px; left: 6px; min-width: 30px; height: 30px; padding: 0 6px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--display); font-size: 16px; color: #fff;
  background: var(--pink); border: 3px solid var(--ink); border-radius: 999px;
}
.thumb .today {
  position: absolute; top: 6px; right: 6px;
  font-family: var(--display); font-size: 10px; color: #fff;
  background: var(--purple); border: 2px solid var(--ink); border-radius: 999px; padding: 2px 8px;
}
.solo {
  position: absolute; right: 6px; bottom: 6px; width: 34px; height: 34px;
  border: 3px solid var(--ink); border-radius: 50%; background: var(--green);
  font-size: 13px; cursor: pointer; box-shadow: 2px 2px 0 var(--ink);
  opacity: 0; transition: opacity 0.1s;
}
.gcard:hover .solo, .solo:focus-visible { opacity: 1; }
.gmeta { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 3px; }
.gmeta b { font-family: var(--display); font-weight: 400; font-size: 14px; }
.gcta { font-size: 12px; font-weight: 700; color: var(--purple); }
.gkeys { display: flex; flex-wrap: wrap; gap: 3px; align-items: center; margin-top: 3px; }
.gkeys em { font-style: normal; font-size: 11px; font-weight: 700; opacity: 0.6; margin-left: auto; }
kbd.mini { font-size: 10px; min-width: 20px; height: 20px; border-width: 2px; border-radius: 5px; box-shadow: 0 2px 0 var(--ink); padding: 0 4px; }
.admin-foot {
  position: sticky; bottom: -18px; margin: 14px -18px -18px; padding: 12px 18px;
  background: linear-gradient(transparent, var(--paper) 30%); display: flex; justify-content: center;
}
.big-btn:disabled { background: #bbb; cursor: default; animation: none; }

@media (max-width: 560px) {
  .tile { width: 54px; height: 54px; }
  .tile small { display: none; }
  .stats b { font-size: 16px; }
  .stats span { font-size: 8px; }
  .pip { width: 14px; height: 14px; }
}

/* ---------- touch controls ---------- */
.playarea { display: contents; }
.pad { display: none; }

body.touch {
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  padding-bottom: env(safe-area-inset-bottom);
}
body.touch .top { padding: 8px 0 6px; width: calc(100% - 20px); }
body.touch footer, body.touch .legend { display: none; }
body.touch .playarea {
  display: grid;
  width: calc(100vw - 20px);
  flex: 1;
  min-height: 0;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: "stage stage" "l r";
  column-gap: 12px;
  row-gap: 14px;
  padding-bottom: 12px;
}
body.touch #stage {
  grid-area: stage;
  justify-self: center;
  width: min(100%, (100dvh - 290px) * 4 / 3);
  box-shadow: 5px 5px 0 var(--ink), 0 0 0 6px var(--yellow);
  touch-action: none;
}
/* menus get the whole screen; the pad only exists while a game is up */
body.touch:not([data-screen="cta"]):not([data-screen="play"]) .pad { display: none; }
body.touch:not([data-screen="cta"]):not([data-screen="play"]) #stage {
  grid-row: 1 / -1; aspect-ratio: auto; width: 100%; height: 100%;
}
body.touch[data-screen="cta"] .pad, body.touch[data-screen="play"] .pad {
  display: flex; align-items: center; gap: 12px; touch-action: none;
}
.pad-l { grid-area: l; justify-content: flex-start; }
.pad-r { grid-area: r; justify-content: flex-end; }
.pad.col { flex-direction: column; align-items: flex-end; justify-content: center; }
.playarea.one .pad-l:empty { display: none !important; }
.playarea.one .pad-r { grid-column: 1 / -1; justify-content: center; }
.playarea.one .pad-r:empty { display: none !important; }
.playarea.one .pad-l:not(:empty) { grid-column: 1 / -1; justify-content: center; }

.tbtn {
  width: 84px; height: 84px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--display); font-size: 30px; color: var(--ink);
  background: var(--paper);
  border: 4px solid var(--ink); border-radius: 20px;
  box-shadow: 0 6px 0 var(--ink);
  touch-action: none;
}
.tbtn.on { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); background: var(--yellow); }
.tbtn.big { width: min(42vw, 170px); height: 120px; font-size: 44px; }
.tbtn.wide { width: 120px; height: 72px; font-size: 22px; }
.tbtn.fire { width: 116px; height: 116px; border-radius: 50%; background: var(--pink); color: #fff; font-size: 18px; text-align: center; }
.tbtn.fire.on { background: #ff7fb0; }
.playarea.one .tbtn.fire { width: min(100%, 420px); height: 130px; border-radius: 26px; font-size: 26px; }

.dpad {
  position: relative; flex: none;
  width: 176px; height: 176px; border-radius: 50%;
  background: var(--paper); border: 4px solid var(--ink);
  box-shadow: 0 6px 0 var(--ink);
  touch-action: none;
}
.dpad i { position: absolute; inset: 38%; border-radius: 50%; background: rgba(27, 16, 53, 0.12); }
.dpad .ar {
  position: absolute; width: 56px; height: 56px; margin: -28px;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; color: var(--purple); border-radius: 14px;
}
.dpad .ar.w { left: 50%; top: 20%; }
.dpad .ar.s { left: 50%; top: 80%; }
.dpad .ar.a { left: 20%; top: 50%; }
.dpad .ar.d { left: 80%; top: 50%; }
.dpad.on-w .ar.w, .dpad.on-a .ar.a, .dpad.on-s .ar.s, .dpad.on-d .ar.d { background: var(--yellow); color: var(--ink); }

body.touch .solo { opacity: 1; }
body.touch .gcard:hover { transform: none; box-shadow: 3px 3px 0 var(--ink); }

/* landscape phones: controls flank the game */
@media (orientation: landscape) {
  body.touch .playarea {
    grid-template-columns: 1fr auto 1fr;
    grid-template-rows: 1fr;
    grid-template-areas: "l stage r";
    align-items: center;
  }
  body.touch #stage { width: min(calc((100dvh - 70px) * 4 / 3), 100vw - 400px); align-self: center; }
  body.touch:not([data-screen="cta"]):not([data-screen="play"]) #stage { grid-column: 1 / -1; grid-row: 1; }
  .pad.pad-l, .pad.pad-r { flex-wrap: wrap; align-content: center; }
  .pad-l { justify-content: center; }
  .pad-r { justify-content: center; }
  .playarea.one .pad-r, .playarea.one .pad-l:not(:empty) { grid-column: auto; }
  .playarea.one .tbtn.fire { width: 150px; height: 150px; border-radius: 50%; }
  body.touch .dpad { width: 150px; height: 150px; }
  body.touch .tbtn.big { width: 120px; }
}

/* the call-to-action scales with the stage, so it fits a phone-sized 4:3 box */
#stage { container-type: size; }
#cta { gap: min(6px, 1.2cqh); padding: 8px; }
.cta-count { font-size: clamp(11px, 4cqh, 18px); }
.cta-text { font-size: clamp(24px, min(13cqh, 10cqw), 78px); margin: min(10px, 2cqh) 0 2px; -webkit-text-stroke-width: clamp(2px, 0.7cqh, 3px); text-shadow: clamp(3px, 1.2cqh, 6px) clamp(3px, 1.2cqh, 6px) 0 var(--ink); }
.cta-name { font-size: clamp(11px, 3.4cqh, 16px); }
.cta-keys { margin-top: min(12px, 2cqh); }
.cta-num { font-size: clamp(22px, 8cqh, 40px); line-height: 1.1; }
.cta-bar { height: clamp(10px, 3cqh, 16px); border-width: clamp(3px, 0.8cqh, 4px); }
#cta kbd { height: clamp(26px, 8cqh, 40px); min-width: clamp(26px, 8cqh, 40px); font-size: clamp(12px, 3.8cqh, 18px); }
#cta kbd.wide { min-width: clamp(64px, 18cqh, 96px); font-size: clamp(10px, 3cqh, 14px); }
body.touch .admin-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
body.touch .card.wide .sub { display: none; }

/* the whole left control area is the D-pad's touch zone */
body.touch .pad-l:has(.dzone) { align-self: stretch; }
body.touch .dzone { flex: 1; align-self: stretch; display: flex; align-items: center; justify-content: center; touch-action: none; }
body.touch .dpad { width: 200px; height: 200px; pointer-events: none; }
body.touch .dpad .ar { width: 62px; height: 62px; margin: -31px; font-size: 34px; }
@media (orientation: landscape) { body.touch .dpad { width: 170px; height: 170px; } }

/* ---------- social share links ---------- */
.social { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; margin-top: 14px; }
.soc {
  font-family: var(--body); font-weight: 900; font-size: 12px;
  color: #fff; background: var(--ink);
  border: 3px solid var(--ink); border-radius: 999px;
  padding: 4px 10px; cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink);
  transition: transform 0.08s;
}
.soc:hover { transform: translate(-1px, -1px); }
.soc:active { transform: translate(2px, 2px); box-shadow: none; }
.soc.x { background: #000; }
.soc.bsky { background: #1185fe; }
.soc.fb { background: #1877f2; }
.soc.reddit { background: #ff4500; }
.soc.wa { background: #25d366; color: var(--ink); }
.soc.copy { background: #fff; color: var(--ink); }

/* ---------- intro splash: what each key does ---------- */
.cta-keys { flex-wrap: wrap; gap: 8px 18px; max-width: 92%; }
.cta-keys .hint { display: flex; align-items: center; gap: 5px; }
.cta-keys .hint em {
  font-style: normal; font-weight: 900; font-size: 15px; color: #fff;
  text-shadow: 2px 2px 0 var(--ink); margin-left: 3px; white-space: nowrap;
}
