:root {
  --red: #d7262e; --red-d: #9e1620; --blue: #2f74d0; --blue-d: #1d4e94;
  --cream: #fff7e6; --ink: #3b2416; --wood: #c98a4b; --wood-d: #8a5a2b; --green: #3f9e3a;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #7cc04a; color: var(--ink); }
body { touch-action: none; user-select: none; -webkit-user-select: none; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
.hidden { display: none !important; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; background: #f3d9a4; }
#sceneWrap { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.ib { width: 42px; height: 42px; border-radius: 50%; border: 3px solid var(--ink); background: var(--cream); display: grid; place-items: center; padding: 0; box-shadow: 0 3px 0 rgba(59,36,22,.55); }
.ib svg { width: 22px; height: 22px; }
.ib:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(59,36,22,.55); }
#home { position: absolute; left: 8px; top: 8px; }
.snd { position: absolute; right: 8px; top: 8px; display: flex; gap: 8px; }

#banner { position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%); font-size: clamp(34px, 9vmin, 84px); font-weight: 900; color: #fff;
  -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 0 5px 0 var(--ink); white-space: nowrap; pointer-events: none; animation: pop .35s ease-out; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(.4); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }

/* player panels */
.panel { flex: 0 0 auto; background: var(--cream); border-top: 5px solid var(--red); padding: 8px 10px 10px; display: grid; gap: 8px;
  grid-template-columns: 1fr; position: relative; }
#panel2 { border-top: 0; border-bottom: 5px solid var(--blue); }
body.m1 #panel2 { display: none; }
.phead { display: flex; justify-content: space-between; align-items: center; font-weight: 800; font-size: 15px; }
.team { padding: 3px 12px; border-radius: 999px; color: #fff; border: 2px solid var(--ink); }
.team.kancil { background: var(--red); } .team.kerbau { background: var(--blue); }
.pstat { font-size: 14px; opacity: .85; }
.q { display: flex; align-items: center; justify-content: center; gap: 10px; background: #fff; border: 3px solid var(--ink); border-radius: 16px;
  min-height: 64px; font-weight: 900; font-size: clamp(28px, 7.4vmin, 46px); padding: 4px 10px; box-shadow: inset 0 -4px 0 rgba(0,0,0,.07); }
.q .ans { min-width: 1.6em; padding: 0 .25em; text-align: center; border-bottom: 4px dashed #c7b18c; color: var(--red-d); }
#panel2 .q .ans { color: var(--blue-d); }
.q.ok { background: #e2f7d4; } .q.bad { background: #ffe0dc; animation: shake .3s; }
@keyframes shake { 20% { transform: translateX(-8px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(3px); } }

.pad { display: grid; gap: 7px; grid-template-columns: repeat(6, 1fr); }
.k { border: 3px solid var(--ink); border-radius: 14px; background: #ffe3a8; font-weight: 900; font-size: clamp(22px, 5.6vmin, 30px); height: 50px;
  box-shadow: 0 4px 0 var(--wood-d); display: grid; place-items: center; padding: 0; }
.k.fn { background: #f1c98f; font-size: 18px; }
.k:active, .k.pressed { transform: translateY(3px); box-shadow: 0 1px 0 var(--wood-d); background: #ffd57a; }
.k svg { width: 26px; height: 26px; }

/* phone portrait, one player: big 3x4 pad below the question */
body.m1.tall .pad { grid-template-columns: repeat(3, 1fr); }
body.m1.tall .k { height: clamp(46px, 7.2vh, 62px); }
/* wide, one player: question left, pad right */
body.m1.wide .panel { grid-template-columns: minmax(220px, 1fr) minmax(320px, 1.3fr); grid-template-rows: auto 1fr; max-width: 980px; width: 100%; margin: 0 auto; border-radius: 0; }
body.m1.wide .phead { grid-column: 1 / 3; }
body.m1.wide .q { min-height: 108px; }
body.m1.wide #panel1 { background: var(--cream); }
body.m1.wide #app { background: var(--cream); }

/* two players, wide: scene on top, panels side by side */
body.m2.wide #app { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr auto; grid-template-areas: "s s" "a b"; }
body.m2.wide #sceneWrap { grid-area: s; }
body.m2.wide #panel1 { grid-area: a; border-right: 3px solid var(--ink); }
body.m2.wide #panel2 { grid-area: b; border-bottom: 0; border-top: 5px solid var(--blue); }
/* two players, tall: player 2 sits on the other side, panel turned around */
body.m2.tall #panel2 { transform: rotate(180deg); }
body.m2.tall .k { height: clamp(42px, 6.4vh, 58px); }
body.m2.tall .q { min-height: 54px; font-size: clamp(26px, 6.6vmin, 40px); }

/* overlays */
.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(40, 24, 10, .38); padding: 12px; z-index: 5; overflow-y: auto; }
.card { background: var(--cream); border: 4px solid var(--ink); border-radius: 22px; box-shadow: 0 8px 0 rgba(59,36,22,.6); padding: 16px 18px 18px;
  width: min(560px, 100%); text-align: center; position: relative; }
.card::before { content: ""; position: absolute; left: 14px; right: 14px; top: -4px; height: 12px; border-radius: 0 0 8px 8px;
  background: linear-gradient(90deg, var(--red) 0 50%, #fff 50% 100%); background-size: 36px 100%; border: 3px solid var(--ink); border-top: 0; }
h1 { margin: 10px 0 2px; font-size: clamp(26px, 6.4vmin, 40px); line-height: 1.05; color: var(--red); -webkit-text-stroke: 1px var(--ink); }
h1 span { color: var(--blue); }
.sub { margin: 0 0 10px; font-weight: 700; font-size: 15px; opacity: .85; }
.row { display: grid; grid-template-columns: 70px 1fr; align-items: center; gap: 8px; margin: 8px 0; text-align: left; }
.row b { font-size: 15px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { border: 3px solid var(--ink); border-radius: 12px; background: #fff; padding: 7px 11px; font-weight: 800; font-size: 15px; min-height: 42px; }
.chips button.on { background: var(--red); color: #fff; box-shadow: inset 0 -3px 0 var(--red-d); }
.chips.grade button { min-width: 44px; }
.btn { border: 4px solid var(--ink); border-radius: 18px; background: var(--green); color: #fff; font-weight: 900; font-size: 22px; padding: 10px 26px;
  box-shadow: 0 5px 0 #24621f; }
.btn.big { font-size: 28px; padding: 12px 40px; margin-top: 8px; }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #24621f; }
.btn.ghost { background: #fff; color: var(--ink); box-shadow: 0 5px 0 #b9a27b; }
.endc h2 { margin: 12px 0 4px; font-size: clamp(28px, 7vmin, 42px); }
.endc h2.kancil { color: var(--red); } .endc h2.kerbau { color: var(--blue); }
#endSub { margin: 0 0 10px; font-weight: 700; }
#endStats { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 8px; margin: 6px 0 12px; }
.st { background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 6px 4px; }
.st i { display: block; font-style: normal; font-size: 13px; font-weight: 700; opacity: .75; }
.st b { font-size: 24px; }
.st.rec { background: #fff2b8; }
.brow { display: flex; gap: 12px; justify-content: center; align-items: center; flex-wrap: wrap; }
@media (max-height: 560px) { .row { margin: 4px 0; } .sub { display: none; } .btn.big { padding: 8px 34px; font-size: 24px; } }
#start, #again { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
