:root {
  --navy: #13208F;
  --deep: #0B1466;
  --blue: #2347C9;
  --sky: #5BB8F5;
  --teal: #2BB89A;
  --orange: #F07A2A;
  --red: #E2552B;
  --yellow: #F6B93B;
  --cream: #F2E9D8;
  --ink: #16205C;
}

* { box-sizing: border-box; margin: 0; }

html, body {
  height: 100%;
  background: var(--deep);
  overflow: hidden;
  font-family: 'Montserrat', system-ui, sans-serif;
  color: var(--cream);
  user-select: none;
  -webkit-user-select: none;
}

body { display: grid; place-items: center; }

#stage {
  position: relative;
  width: min(100vw, 177.78vh);
  aspect-ratio: 16 / 9;
  container-type: inline-size;
  touch-action: manipulation;
  cursor: pointer;
  overflow: hidden;
}

#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.4cqw;
  text-align: center;
  background: rgba(11, 20, 102, 0.9);
  transition: opacity 0.3s;
}
.overlay.hidden { opacity: 0; pointer-events: none; }

.eyebrow { font-weight: 800; font-size: 1.2cqw; letter-spacing: 0.3em; text-transform: uppercase; color: var(--yellow); }

.title {
  font-weight: 900;
  font-size: 9cqw;
  line-height: 0.95;
  letter-spacing: 0.02em;
  color: var(--cream);
  text-shadow: 0.45cqw 0.45cqw 0 var(--orange);
}
.title.small { font-size: 6.5cqw; }

.lead { font-weight: 600; font-size: 1.9cqw; }
.hint { font-weight: 600; font-size: 1.1cqw; opacity: 0.85; }

.ready-row, .score-row { display: flex; gap: 2cqw; margin: 1cqw 0; }

.ready-card, .score {
  width: 20cqw;
  padding: 1.4cqw;
  border: 0.35cqw solid var(--cream);
  border-radius: 0.6cqw;
  background: var(--navy);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4cqw;
  transition: transform 0.15s, background 0.15s;
}
.ready-card strong { font-size: 1.7cqw; font-weight: 800; }
.ready-card small, .score small { font-size: 1cqw; font-weight: 600; opacity: 0.8; }
.ready-card em { font-style: normal; font-weight: 800; font-size: 1.1cqw; color: var(--yellow); margin-top: 0.4cqw; }
.ready-card.is-ready.p1 { background: var(--teal); transform: translateY(-0.4cqw); }
.ready-card.is-ready.p2 { background: var(--orange); transform: translateY(-0.4cqw); }
.ready-card.is-ready em { color: var(--deep); }

/* ---------- Start screen: arcade-style join pads ---------- */
#idle { background: rgba(11, 20, 102, 0.55); gap: 2.2cqw; }

.title.game {
  font-size: 8.5cqw;
  color: var(--yellow);
  transform: rotate(-3deg);
  text-shadow:
    0.3cqw 0 0 var(--ink), -0.3cqw 0 0 var(--ink), 0 0.3cqw 0 var(--ink), 0 -0.3cqw 0 var(--ink),
    0.22cqw 0.22cqw 0 var(--ink), -0.22cqw 0.22cqw 0 var(--ink), 0.22cqw -0.22cqw 0 var(--ink), -0.22cqw -0.22cqw 0 var(--ink),
    0.7cqw 0.8cqw 0 var(--orange), 0.9cqw 1cqw 0 var(--ink);
  animation: bob 2.4s ease-in-out infinite;
}
@keyframes bob { 0%, 100% { transform: rotate(-3deg) translateY(0); } 50% { transform: rotate(-3deg) translateY(-0.6cqw); } }

.ready-row { align-items: center; }
.vs { font-weight: 900; font-size: 3cqw; color: var(--cream); text-shadow: 0.25cqw 0.25cqw 0 var(--ink); }

.pad {
  position: relative;
  width: 16cqw;
  padding: 1.2cqw 1cqw 1.6cqw;
  border: 0.35cqw solid var(--ink);
  border-radius: 1.4cqw;
  background: var(--navy);
  box-shadow: 0 0.7cqw 0 var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8cqw;
  transition: transform 0.12s, box-shadow 0.12s, background 0.12s;
}
.pad .tag { font-size: 2.2cqw; padding: 0.2cqw 1.4cqw; border: 0.25cqw solid var(--ink); }
.pad em { font-style: normal; font-weight: 900; font-size: 2cqw; letter-spacing: 0.06em; color: var(--yellow); animation: pulse 0.8s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.12); } }
.crank { width: 6cqw; height: 6cqw; }
.crank .ring { fill: var(--blue); stroke: var(--ink); stroke-width: 4; }
.crank .arm { stroke: var(--cream); stroke-width: 5; stroke-linecap: round; fill: var(--yellow); animation: spin 1.2s linear infinite; }
.crank .arm circle { stroke: var(--ink); stroke-width: 3; }
.crank .hub { fill: var(--yellow); stroke: var(--ink); stroke-width: 3; }
@keyframes spin { to { transform: rotate(360deg); } }
.key {
  position: absolute;
  right: -1cqw;
  bottom: -1cqw;
  width: 3cqw;
  height: 3cqw;
  display: grid;
  place-items: center;
  border-radius: 0.6cqw;
  border: 0.25cqw solid var(--ink);
  background: var(--cream);
  color: var(--ink);
  font-weight: 900;
  font-size: 1.6cqw;
  box-shadow: 0 0.3cqw 0 var(--ink);
}
.pad.is-ready { transform: translateY(0.7cqw); box-shadow: 0 0 0 var(--ink); }
.pad.is-ready.p1 { background: var(--teal); }
.pad.is-ready.p2 { background: var(--orange); }
.pad.is-ready em { color: var(--ink); animation: none; }
.pad.is-ready .crank .arm { animation-duration: 0.35s; }
.pad.is-ready .tag { background: var(--cream); }

.press {
  font-weight: 900;
  font-size: 1.5cqw;
  letter-spacing: 0.2em;
  color: var(--cream);
  text-shadow: 0.15cqw 0.15cqw 0 var(--ink);
  animation: blink 1.1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

.tag {
  font-weight: 900;
  font-size: 1.3cqw;
  padding: 0.2cqw 1cqw;
  border-radius: 2cqw;
  color: var(--deep);
}
.p1 .tag { background: var(--teal); }
.p2 .tag { background: var(--orange); }
.is-ready .tag { background: var(--cream); }

#countdown { background: rgba(11, 20, 102, 0.45); }
#count-num {
  display: grid;
  place-items: center;
  width: 16cqw;
  height: 16cqw;
  border-radius: 50%;
  background: var(--yellow);
  border: 0.4cqw solid var(--ink);
  color: var(--ink);
  font-weight: 900;
  font-size: 10cqw;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  animation: pop 0.9s ease-out infinite;
}
@keyframes pop { 0% { transform: scale(1.4); opacity: 0; } 25% { transform: scale(1); opacity: 1; } 100% { transform: scale(0.9); opacity: 0.9; } }

#finale { background: transparent; justify-content: flex-start; padding-top: 12cqw; }
.finale-card {
  background: var(--orange);
  color: var(--ink);
  border: 0.3cqw solid var(--ink);
  border-radius: 0.4cqw;
  padding: 0.6cqw 2.4cqw 1cqw;
  animation: rise 0.5s ease-out;
}
.finale-card p { font-weight: 800; font-size: 1.2cqw; }
.script { font-family: 'Kaushan Script', cursive; font-size: 5cqw; color: var(--cream); line-height: 1.15; text-shadow: 0.2cqw 0 0 var(--ink), -0.2cqw 0 0 var(--ink), 0 0.2cqw 0 var(--ink), 0 -0.2cqw 0 var(--ink), 0.3cqw 0.3cqw 0 var(--ink); }
@keyframes rise { from { transform: translateY(3cqw) scale(0.8); opacity: 0; } to { transform: none; opacity: 1; } }

.score b { font-size: 6cqw; font-weight: 900; line-height: 1; }
.score.win { background: var(--yellow); color: var(--deep); }
.score.win .tag { background: var(--deep); color: var(--cream); }
.together { font-size: 1.8cqw; font-weight: 600; }
.together b { color: var(--yellow); font-weight: 900; }

/* ---------- Result screen ---------- */
#result { background: rgba(11, 20, 102, 0.95); gap: 1.6cqw; overflow: hidden; }
#result::before {
  content: '';
  position: absolute;
  left: 50%; top: 50%;
  width: 160cqw; height: 160cqw;
  margin: -80cqw 0 0 -80cqw;
  background: repeating-conic-gradient(from 0deg, rgba(62, 91, 234, 0.35) 0deg 10deg, transparent 10deg 20deg);
  animation: rays 30s linear infinite;
  pointer-events: none;
}
@keyframes rays { to { transform: rotate(360deg); } }
#result > * { position: relative; }
#result #confetti { position: absolute; }
#result .score-row { margin-top: 3.4cqw; }
#result .title.game { font-size: 7cqw; }
.pad.score { width: 17cqw; gap: 0.2cqw; padding-top: 1.6cqw; }
.pad.score b { font-size: 6.5cqw; font-weight: 900; line-height: 1; color: var(--cream); text-shadow: 0.3cqw 0.3cqw 0 var(--ink); }
.pad.score small { font-size: 1.2cqw; font-weight: 900; letter-spacing: 0.2em; opacity: 1; color: var(--cream); }
.pad.score .crown { position: absolute; top: -3.4cqw; width: 5cqw; display: none; }
.pad.score .crown path { fill: var(--yellow); stroke: var(--ink); stroke-width: 4; stroke-linejoin: round; }
.pad.score.win { background: var(--yellow); transform: scale(1.1); animation: winbob 1.2s ease-in-out infinite; }
.pad.score.win b, .pad.score.win small { color: var(--ink); text-shadow: none; }
.pad.score.win .crown { display: block; }
.pad.score:not(.win) { opacity: 0.85; }
@keyframes winbob { 50% { transform: scale(1.1) translateY(-0.5cqw); } }
.bersama-banner {
  display: flex; align-items: center; gap: 1.2cqw;
  background: var(--orange);
  border: 0.35cqw solid var(--ink);
  border-radius: 0.6cqw;
  box-shadow: 0 0.6cqw 0 var(--ink);
  padding: 0.4cqw 2cqw 0.6cqw;
  transform: rotate(-2deg);
  animation: bump 1.6s ease-in-out infinite;
}
.bersama-banner .script {
  font-size: 3.6cqw; color: var(--cream); -webkit-text-stroke: 0;
  text-shadow: 0.2cqw 0 0 var(--ink), -0.2cqw 0 0 var(--ink), 0 0.2cqw 0 var(--ink), 0 -0.2cqw 0 var(--ink), 0.3cqw 0.3cqw 0 var(--ink);
}
.bersama-banner b {
  font-size: 4.2cqw; font-weight: 900; line-height: 1; color: var(--yellow);
  text-shadow: 0.2cqw 0 0 var(--ink), -0.2cqw 0 0 var(--ink), 0 0.2cqw 0 var(--ink), 0 -0.2cqw 0 var(--ink), 0.3cqw 0.3cqw 0 var(--ink);
}
.bersama-banner small { font-size: 1.3cqw; font-weight: 900; letter-spacing: 0.15em; color: var(--ink); }
@keyframes bump { 50% { transform: rotate(-2deg) scale(1.06); } }
#confetti { position: absolute; }
#result .score-row { margin-top: 3.4cqw; }
#result .title.game { font-size: 7cqw; }
.pad.score { width: 17cqw; gap: 0.2cqw; padding-top: 1.6cqw; }
.pad.score b { font-size: 6.5cqw; font-weight: 900; line-height: 1; color: var(--cream); text-shadow: 0.3cqw 0.3cqw 0 var(--ink); }
.pad.score small { font-size: 1.2cqw; font-weight: 900; letter-spacing: 0.2em; opacity: 1; color: var(--cream); }
.pad.score .crown { position: absolute; top: -3.4cqw; width: 5cqw; display: none; }
.pad.score .crown path { fill: var(--yellow); stroke: var(--ink); stroke-width: 4; stroke-linejoin: round; }
.pad.score.win { background: var(--yellow); transform: scale(1.1); animation: winbob 1.2s ease-in-out infinite; }
.pad.score.win b, .pad.score.win small { color: var(--ink); text-shadow: none; }
.pad.score.win .crown { display: block; }
.pad.score:not(.win) { opacity: 0.85; }
@keyframes winbob { 50% { transform: scale(1.1) translateY(-0.5cqw); } }
.together-chip {
  font-weight: 900; font-size: 1.5cqw; letter-spacing: 0.12em;
  color: var(--ink); background: var(--cream);
  border: 0.3cqw solid var(--ink); border-radius: 3cqw;
  padding: 0.5cqw 1.8cqw; box-shadow: 0 0.4cqw 0 var(--ink);
}
.together-chip b { color: var(--orange); font-size: 2cqw; }
#confetti { position: absolute; inset: 0; pointer-events: none; }
#confetti i {
  position: absolute; top: -3cqw; width: 0.8cqw; height: 1.4cqw;
  border: 0.15cqw solid var(--ink);
  animation-name: fall; animation-timing-function: linear; animation-iteration-count: infinite;
}
@keyframes fall { to { top: 105%; transform: rotate(720deg); } }

/* ---------- Today's record ---------- */
.record {
  font-weight: 900; font-size: 1.3cqw; letter-spacing: 0.14em;
  color: var(--ink); background: var(--cream);
  border: 0.3cqw solid var(--ink); border-radius: 3cqw;
  padding: 0.4cqw 1.6cqw; box-shadow: 0 0.4cqw 0 var(--ink);
}
.record b { color: var(--orange); font-size: 1.8cqw; }
.record[hidden], .new-record[hidden] { display: none; }
.new-record {
  font-weight: 900; font-size: 1.8cqw; letter-spacing: 0.08em;
  color: var(--ink); background: var(--yellow);
  border: 0.3cqw solid var(--ink); border-radius: 0.6cqw;
  padding: 0.4cqw 1.4cqw; box-shadow: 0 0.4cqw 0 var(--ink);
  margin: -0.8cqw 0 -1.6cqw;
  transform: rotate(-3deg);
  animation: stamp 0.5s ease-out both, pulse2 1s ease-in-out 0.5s infinite;
}
@keyframes stamp { from { transform: rotate(-3deg) scale(2.5); opacity: 0; } to { transform: rotate(-3deg) scale(1); opacity: 1; } }
@keyframes pulse2 { 50% { transform: rotate(-3deg) scale(1.08); } }

/* ---------- Mode picker ---------- */
#mode { background: rgba(11, 20, 102, 0.75); gap: 2cqw; }
.pick { font-weight: 900; font-size: 1.6cqw; letter-spacing: 0.3em; color: var(--cream); }
button.pad { font: inherit; color: inherit; cursor: pointer; }
.mode-btn { width: 20cqw; padding: 1.8cqw 1cqw 2cqw; }
.mode-btn:hover { transform: translateY(-0.4cqw); }
.mode-btn:active { transform: translateY(0.7cqw); box-shadow: 0 0 0 var(--ink); }
.mode-btn em { animation: none; font-size: 2.6cqw; }
.mode-btn small { font-weight: 700; font-size: 1.1cqw; opacity: 0.85; }
.ico { width: 9cqw; height: 5.6cqw; fill: var(--blue); stroke: var(--cream); stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; }
.mode-btn[data-mode="ketik"] .ico path { fill: none; stroke: var(--yellow); stroke-width: 4; }
.mode-btn[data-mode="kayuh"] .ico path { fill: none; }

/* ---------- Idle: per-mode pad content ---------- */
.qr { display: none; width: 10cqw; height: 10cqw; background: #fff; border: 0.3cqw solid var(--ink); border-radius: 0.6cqw; padding: 0.3cqw; }
.qr svg { width: 100%; height: 100%; display: block; }
body[data-mode="ketik"] .pad .qr { display: block; }
body[data-mode="ketik"] .pad .crank,
body[data-mode="ketik"] .pad .key { display: none; }
body[data-mode="ketik"] .pad.is-ready .qr { opacity: 0.25; }
.switch {
  position: absolute; left: 1.6cqw; bottom: 1.6cqw;
  font: 900 1cqw 'Montserrat', sans-serif; letter-spacing: 0.12em;
  color: var(--cream); background: transparent;
  border: 0.2cqw solid var(--cream); border-radius: 2cqw; padding: 0.5cqw 1.2cqw; cursor: pointer; opacity: 0.8;
}

body[data-mode="ketik"] #idle .pad em { font-size: 1.5cqw; }
