/* ============================================================
   Baht Busters — shared styles (player + admin)
   Bright, chunky, kid-friendly "sticker" design.
   ============================================================ */
:root {
  --ink: #26243a;
  --paper: #fff8ec;
  --card: #ffffff;
  --coral: #ff6b6b;
  --teal: #29c7b0;
  --yellow: #ffd93d;
  --purple: #9b7bff;
  --green: #58c471;
  --blue: #4dabf7;
  --red: #ff5252;
  --shadow: 0 6px 0 rgba(38, 36, 58, .9);
  --radius: 22px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

body {
  font-family: "Baloo 2", "Comic Sans MS", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 18%, rgba(41, 199, 176, .14) 0 9vmin, transparent 9.5vmin),
    radial-gradient(circle at 88% 12%, rgba(255, 217, 61, .20) 0 7vmin, transparent 7.5vmin),
    radial-gradient(circle at 82% 84%, rgba(255, 107, 107, .13) 0 10vmin, transparent 10.5vmin),
    radial-gradient(circle at 8% 88%, rgba(155, 123, 255, .14) 0 8vmin, transparent 8.5vmin),
    var(--paper);
  min-height: 100vh;
}

.wrap { max-width: 980px; margin: 0 auto; padding: 16px 16px 40px; }

/* ---------- generic bits ---------- */
.card {
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

h1, h2, h3 { margin: 0 0 8px; line-height: 1.15; }
h1 { font-size: clamp(26px, 5vw, 40px); letter-spacing: .5px; }
h2 { font-size: clamp(20px, 3.4vw, 27px); }

.muted { opacity: .68; font-weight: 600; }
.small { font-size: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: inherit; font-weight: 800; font-size: 17px;
  color: var(--ink); background: #fff;
  border: 3px solid var(--ink); border-radius: 16px;
  padding: 12px 20px; cursor: pointer; user-select: none;
  box-shadow: 0 5px 0 rgba(38, 36, 58, .9);
  transition: transform .06s ease, box-shadow .06s ease, background .15s ease;
}
.btn:hover { background: #fffdf5; }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(38, 36, 58, .9); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: var(--shadow); }

.btn-coral   { background: var(--coral); color: #fff; }
.btn-teal    { background: var(--teal);  color: #fff; }
.btn-yellow  { background: var(--yellow); }
.btn-purple  { background: var(--purple); color: #fff; }
.btn-green   { background: var(--green); color: #fff; }
.btn-big     { font-size: 21px; padding: 16px 30px; border-radius: 20px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border: 2.5px solid var(--ink); border-radius: 999px;
  padding: 4px 13px; font-weight: 800; font-size: 14px;
}

.badge {
  display: inline-block; padding: 3px 12px; border-radius: 999px;
  border: 2.5px solid var(--ink); font-weight: 800; font-size: 13px;
}
.badge-buzz   { background: var(--yellow); }
.badge-answer { background: #ffd6a5; }
.badge-reveal { background: #c3fae8; }
.badge-over   { background: #d0bfff; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 14px; flex-wrap: wrap;
}
.logo { font-size: 22px; font-weight: 900; letter-spacing: .3px; }
.logo .flag { margin-right: 6px; }

.iconbtn {
  width: 46px; height: 46px; border-radius: 14px;
  border: 3px solid var(--ink); background: #fff; cursor: pointer;
  font-size: 20px; box-shadow: 0 4px 0 rgba(38,36,58,.9);
}
.iconbtn:active { transform: translateY(3px); box-shadow: none; }

/* ---------- join screen ---------- */
.join-card { max-width: 460px; margin: 6vh auto 0; text-align: center; }
.mascot-row { font-size: clamp(40px, 9vw, 62px); letter-spacing: 8px; margin-bottom: 4px; }

.field { text-align: left; margin-top: 16px; }
.field label { display: block; font-weight: 800; margin-bottom: 6px; font-size: 15px; }
.input {
  width: 100%; font-family: inherit; font-weight: 800; font-size: 24px;
  padding: 13px 16px; border: 3px solid var(--ink); border-radius: 16px;
  background: #fffdf5; color: var(--ink); outline: none; letter-spacing: 2px;
}
.input:focus { box-shadow: 0 0 0 4px rgba(255, 217, 61, .55); }
.code-input { text-transform: uppercase; text-align: center; font-size: 34px; letter-spacing: 10px; }

.join-error {
  margin-top: 14px; padding: 10px 14px; border-radius: 14px;
  background: #ffe3e3; border: 2.5px solid var(--red); color: #a12626;
  font-weight: 800; display: none;
}

/* ---------- lobby ---------- */
.lobby-card { max-width: 560px; margin: 4vh auto 0; text-align: center; }
.player-chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin: 18px 0; min-height: 44px; }
.pchip { font-size: 16px; padding: 7px 16px; background: #eefaff; }
.pchip .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-on  { background: var(--green); }
.dot-off { background: #c9c4bd; }

.settings-summary { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 6px; }

.waiting-dots::after { content: ''; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% {content:''} 25% {content:'.'} 50% {content:'..'} 75% {content:'...'} }

/* ---------- round screen (player) ---------- */
.round-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }

.stage { position: relative; max-width: 560px; margin: 0 auto; perspective: 1400px; }

.flipcard {
  position: relative; transform-style: preserve-3d;
  transition: transform .7s cubic-bezier(.2, .9, .3, 1.2);
}
.stage.flipped .flipcard { transform: rotateY(180deg); }
.face {
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border: 3px solid var(--ink); border-radius: 26px; background: #fff;
  box-shadow: var(--shadow); padding: 22px; text-align: center;
}
.face-back { position: absolute; inset: 0; transform: rotateY(180deg); display: flex; flex-direction: column; justify-content: center; }

.item-emoji { font-size: clamp(74px, 16vw, 120px); line-height: 1.15; filter: drop-shadow(0 6px 0 rgba(38,36,58,.12)); }
.item-name  { font-size: clamp(22px, 4.4vw, 32px); font-weight: 900; margin-top: 6px; }
.item-thai  { font-size: clamp(17px, 3vw, 22px); opacity: .75; font-weight: 700; }
.item-note  { display: inline-block; margin-top: 8px; font-size: 14px; font-weight: 800; background: #fff3c9; border: 2px solid var(--ink); padding: 2px 12px; border-radius: 999px; }

/* timer ring */
.ring-wrap { position: relative; width: clamp(150px, 34vw, 210px); margin: 0 auto -8px; }
.ring-wrap svg { transform: rotate(-90deg); display: block; }
.ring-bg   { fill: none; stroke: #efe9dc; stroke-width: 12; }
.ring-fg   { fill: none; stroke: var(--green); stroke-width: 12; stroke-linecap: round; transition: stroke .3s; }
.ring-num  { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: clamp(34px, 7vw, 52px); font-weight: 900; }

/* buzzer button */
.buzzer-zone { text-align: center; margin-top: 18px; }
.buzzer {
  width: clamp(150px, 40vw, 210px); height: clamp(150px, 40vw, 210px);
  border-radius: 50%; border: 6px solid var(--ink); cursor: pointer;
  background: radial-gradient(circle at 32% 30%, #ff9d9d, var(--red) 70%);
  color: #fff; font-family: inherit; font-weight: 900;
  font-size: clamp(24px, 5vw, 34px); letter-spacing: 1px;
  box-shadow: 0 10px 0 rgba(38,36,58,.9), inset 0 -10px 0 rgba(0,0,0,.18);
  animation: buzzpulse 1.4s ease-in-out infinite;
  user-select: none; touch-action: manipulation;
}
.buzzer:active { transform: translateY(6px) scale(.98); box-shadow: 0 3px 0 rgba(38,36,58,.9), inset 0 -4px 0 rgba(0,0,0,.18); }
.buzzer:disabled { animation: none; background: radial-gradient(circle at 32% 30%, #d8d3c8, #b7b1a4 70%); cursor: not-allowed; box-shadow: 0 6px 0 rgba(38,36,58,.5); }
@keyframes buzzpulse { 0%,100% { transform: scale(1);} 50% { transform: scale(1.045);} }

.buzzer-hint { margin-top: 12px; font-weight: 800; opacity: .7; }
.sitout { margin-top: 14px; font-size: 19px; font-weight: 800; background: #efeaff; border: 3px solid var(--ink); border-radius: 16px; padding: 12px; display: none; }

/* answer (your turn) */
.yourturn { text-align: center; margin-top: 14px; }
.yourturn-title { font-size: clamp(20px, 4vw, 28px); font-weight: 900; color: #b3541e; }
.answerbar-wrap { height: 16px; border: 3px solid var(--ink); border-radius: 999px; background: #fff; overflow: hidden; margin: 12px auto 18px; max-width: 420px; }
.answerbar { height: 100%; width: 100%; background: linear-gradient(90deg, var(--yellow), var(--coral)); transition: none; }

.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; max-width: 640px; margin: 0 auto; }
.choice-btn {
  font-family: inherit; font-weight: 900; font-size: clamp(20px, 4.4vw, 28px);
  padding: 18px 10px; border-radius: 18px; cursor: pointer;
  border: 3px solid var(--ink); background: #fffdf5; color: var(--ink);
  box-shadow: 0 5px 0 rgba(38,36,58,.9);
}
.choice-btn:hover { background: #fff3c9; }
.choice-btn:active { transform: translateY(4px); box-shadow: none; }

.waiting-card { text-align: center; padding: 26px; }
.waiting-emoji { font-size: 54px; animation: bob 1.2s ease-in-out infinite; display: inline-block; }
@keyframes bob { 0%,100% { transform: translateY(0);} 50% { transform: translateY(-8px);} }

/* reveal */
.reveal-emoji { font-size: clamp(64px, 13vw, 96px); line-height: 1.2; }
.verdict { font-size: clamp(24px, 5vw, 36px); font-weight: 900; margin: 8px 0 2px; }
.verdict-good { color: #1e7d43; }
.verdict-bad  { color: #c0392b; }
.price-big { font-size: clamp(30px, 6vw, 46px); font-weight: 900; background: #fff3c9; border: 3px solid var(--ink); display: inline-block; padding: 4px 22px; border-radius: 18px; margin-top: 6px; }
.pts { font-size: clamp(18px, 3.6vw, 24px); font-weight: 900; margin-top: 10px; }
.pts-plus { color: #1e7d43; } .pts-minus { color: #c0392b; }

/* ---------- game over (player) ---------- */
.over-card { max-width: 560px; margin: 4vh auto 0; text-align: center; }
.trophy { font-size: clamp(56px, 12vw, 84px); animation: bob 1.6s ease-in-out infinite; display: inline-block; }
.rank-list { list-style: none; margin: 16px 0; padding: 0; text-align: left; max-width: 380px; margin-inline: auto; }
.rank-list li { display: flex; justify-content: space-between; gap: 10px; font-weight: 800; font-size: 17px; padding: 9px 14px; border-bottom: 2px dashed #e5ddcd; }
.rank-list li.me { background: #fff3c9; border-radius: 12px; border-bottom-color: transparent; }

/* ---------- admin layout ---------- */
.admin-grid { display: grid; grid-template-columns: minmax(300px, 420px) 1fr; gap: 16px; align-items: start; }
@media (max-width: 860px) { .admin-grid { grid-template-columns: 1fr; } }

.code-box { display: flex; gap: 10px; align-items: center; justify-content: space-between; background: #fff3c9; border: 3px dashed var(--ink); border-radius: 16px; padding: 12px 16px; margin-top: 12px; }
.code-big { font-size: 34px; font-weight: 900; letter-spacing: 8px; }

.url-row { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.url-text { flex: 1; font-family: ui-monospace, Consolas, monospace; font-size: 13.5px; background: #f4efe4; border: 2px solid var(--ink); border-radius: 10px; padding: 8px 10px; word-break: break-all; }

.stepper { display: inline-flex; align-items: center; gap: 4px; }
.step-btn { width: 46px; height: 46px; font-size: 26px; border-radius: 14px; border: 3px solid var(--ink); background: #fff; cursor: pointer; box-shadow: 0 4px 0 rgba(38,36,58,.9); font-weight: 900; }
.step-btn:active { transform: translateY(3px); box-shadow: none; }
.step-val { min-width: 52px; text-align: center; font-size: 26px; font-weight: 900; }

.opt-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.opt-label { font-weight: 800; font-size: 15px; }

.pillset { display: flex; flex-wrap: wrap; gap: 7px; }
.pill { border: 2.5px solid var(--ink); background: #fff; border-radius: 999px; padding: 6px 14px; font-weight: 800; font-size: 14px; cursor: pointer; box-shadow: 0 3px 0 rgba(38,36,58,.7); }
.pill:active { transform: translateY(2px); box-shadow: none; }
.pill.on { background: var(--teal); color: #fff; }

.level-cards { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; margin-top: 8px; }
.lvl { border: 2.5px solid var(--ink); border-radius: 14px; background: #fff; padding: 9px 4px; text-align: center; cursor: pointer; box-shadow: 0 3px 0 rgba(38,36,58,.7); }
.lvl .n { font-size: 20px; font-weight: 900; }
.lvl .d { font-size: 11.5px; font-weight: 700; opacity: .75; line-height: 1.3; margin-top: 2px; }
.lvl.on { background: var(--purple); color: #fff; }

/* live board */
.live-item { display: flex; gap: 16px; align-items: center; }
.live-emoji { font-size: clamp(54px, 9vw, 84px); line-height: 1.1; }
.timerbar-wrap { height: 20px; border: 3px solid var(--ink); border-radius: 999px; overflow: hidden; background: #fff; margin-top: 14px; }
.timerbar { height: 100%; width: 100%; background: linear-gradient(90deg, var(--green), var(--yellow) 55%, var(--coral)); }

.score-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-top: 14px; }
.score-cell { border: 2.5px solid var(--ink); border-radius: 16px; padding: 10px 12px; background: #fffdf5; box-shadow: 0 3px 0 rgba(38,36,58,.7); }
.score-cell .nm { font-weight: 900; font-size: 15.5px; display: flex; justify-content: space-between; gap: 6px; align-items: center; }
.score-cell .sc { font-size: 24px; font-weight: 900; margin-top: 2px; }
.status-chip { font-size: 11.5px; font-weight: 800; border-radius: 999px; padding: 2px 9px; border: 2px solid var(--ink); white-space: nowrap; }
.st-buzz    { background: #ffe9a8; }
.st-answer  { background: #ffd6a5; }
.st-skip    { background: #e7e3f7; }
.st-off     { background: #eeeae2; opacity: .7; }
.st-lead    { background: #d3f9e0; }

.lb-table { width: 100%; border-collapse: collapse; font-weight: 800; margin-top: 10px; }
.lb-table th, .lb-table td { text-align: left; padding: 7px 8px; border-bottom: 2px dashed #e5ddcd; font-size: 14.5px; }
.lb-table tr.top td { background: #fff3c9; }

.log-line { font-size: 13.5px; font-weight: 700; opacity: .8; padding: 3px 0; border-bottom: 1.5px dashed #eee6d6; }

/* ---------- confetti ---------- */
.confetti-piece { position: fixed; top: -24px; width: 12px; height: 18px; z-index: 99; pointer-events: none; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); opacity: .9; } }

/* ---------- misc animations ---------- */
.pop-in { animation: popin .45s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes popin { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.shake { animation: shake .5s ease; }
@keyframes shake { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-9px)} 40%{transform:translateX(8px)} 60%{transform:translateX(-6px)} 80%{transform:translateX(4px)} }

.hidden { display: none !important; }
.center { text-align: center; }
.mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; } .mt16 { margin-top: 16px; } .mt20 { margin-top: 20px; }

/* ---------- big Live Board modal (whole class watches) ---------- */
.board-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(38, 36, 58, .74);
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
}
.board-modal {
  width: min(1150px, 96vw); max-height: 94vh; overflow-y: auto;
  border-width: 4px; border-radius: 28px; box-shadow: 0 14px 0 rgba(38,36,58,.9);
  padding: 26px 30px; animation: popin .3s cubic-bezier(.2, 1.4, .4, 1) both;
}
.bm-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.bm-head h2 { font-size: clamp(22px, 3vw, 30px); margin-right: auto; }
.bm-close { width: 42px; height: 42px; font-size: 26px; line-height: 1; flex: none; }

.bm-lobby { padding: 60px 0 70px; }

.bm-item { display: flex; gap: 26px; align-items: center; margin-top: 18px; flex-wrap: wrap; }
.bm-emoji { font-size: clamp(96px, 15vw, 160px); line-height: 1.05; filter: drop-shadow(0 8px 0 rgba(38,36,58,.12)); animation: bob 1.6s ease-in-out infinite; }
.bm-name { font-size: clamp(34px, 5vw, 54px); margin: 0 0 4px; line-height: 1.05; }
.bm-thai { font-size: clamp(20px, 2.6vw, 28px); }
.bm-note { font-size: 17px !important; padding: 5px 16px; margin-top: 10px; }
.bm-roundnum { font-size: clamp(34px, 4.6vw, 52px); font-weight: 900; line-height: 1; }

.bm-barwrap { height: 26px; margin-top: 22px; border-width: 3.5px; }
.bm-status { font-size: clamp(19px, 2.8vw, 28px); font-weight: 900; opacity: .9; margin-top: 14px; min-height: 1.4em; }

/* reveal pause box: correct answer + teacher's Next button */
#mbRevealBox {
  text-align: center; margin: 22px auto 6px; max-width: 720px;
  background: #fff3c9; border: 3.5px solid var(--ink); border-radius: 24px;
  padding: 18px 22px 24px; box-shadow: 0 8px 0 rgba(38,36,58,.85);
  animation: popin .4s cubic-bezier(.2, 1.4, .4, 1) both;
}
.bm-reveal-label { font-size: clamp(18px, 2.4vw, 24px); font-weight: 900; color: #1e7d43; }
.bm-reveal-price { font-size: clamp(56px, 9vw, 96px); font-weight: 900; line-height: 1.1; margin: 2px 0 10px; }
.bm-next { font-size: clamp(20px, 3vw, 28px); padding: 14px 34px; animation: buzzpulse 1.2s ease-in-out infinite; }

.bm-scores .score-cell { padding: 14px 16px; border-radius: 18px; }
.bm-scores .score-cell .nm { font-size: 19px; }
.bm-scores .score-cell .sc { font-size: 30px; }
