/* Kanit, self-hosted: the server's CSP only allows fonts from its own origin, and a LAN game may have no internet. */
@font-face { font-family: "Kanit"; src: url(/fonts/Kanit-Regular.ttf) format("truetype"); font-weight: 300 500; font-display: swap; }
@font-face { font-family: "Kanit"; src: url(/fonts/Kanit-SemiBold.ttf) format("truetype"); font-weight: 600 700; font-display: swap; }
@font-face { font-family: "Kanit"; src: url(/fonts/Kanit-ExtraBold.ttf) format("truetype"); font-weight: 800 900; font-display: swap; }

:root {
  --navy: #101a3d; --navy2: #1d2c6b; --mint: #2dd4bf; --sun: #ffd23f; --ink: #14203f;
  --ease: cubic-bezier(.22, 1, .36, 1);
  --spring: cubic-bezier(.34, 1.4, .64, 1);
  --r-ctl: 12px; --r-card: 16px; --r-tile: 20px;
  font-family: "Kanit", "Noto Sans Thai", "Sarabun", "Thonburi", system-ui, sans-serif;
}
* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body { background: radial-gradient(circle at 15% 10%, var(--navy2), var(--navy) 65%) var(--navy); color: #fff; line-height: 1.5; overflow: hidden; user-select: none; -webkit-font-smoothing: antialiased; transition: background-color .3s; }
body.good { background-image: none; background-color: #0f9d8a; }
body.bad { background-image: none; background-color: #c0392b; }

/* Spacing rhythm: 4px grid. #app gap is the step between groups, .stack is the tighter step inside a group. */
#app { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px 16px max(16px, env(safe-area-inset-bottom)); gap: 24px; text-align: center; }
.stack { display: flex; flex-direction: column; align-items: center; gap: 12px; max-width: 100%; }
.stack.tight { gap: 8px; }
@media (min-width: 900px) { #app { padding: 32px 40px; gap: 32px; } }

h1 { font-size: clamp(28px, 5vw, 56px); font-weight: 800; line-height: 1.25; text-wrap: balance; }
h2 { font-size: clamp(20px, 3vw, 32px); font-weight: 700; line-height: 1.3; text-wrap: balance; }
.logo { font-size: clamp(40px, 8vw, 80px); font-weight: 900; line-height: 1.25; text-shadow: 0 4px 0 rgba(0,0,0,.2); }
.logo b { color: var(--mint); }

/* surfaces and controls: one lift, one set of radii */
.card { background: #fff; color: var(--ink); border-radius: var(--r-card); padding: 20px; box-shadow: 0 4px 0 rgba(0,0,0,.2); }
form.card { display: flex; flex-direction: column; gap: 12px; padding: 24px; }
input, select, textarea { width: 100%; font: inherit; font-size: 20px; font-weight: 700; text-align: center; height: 56px; padding: 0 16px; border: 2px solid #d8dcec; border-radius: var(--r-ctl); color: var(--ink); background: #fff; transition: border-color .15s var(--ease), box-shadow .15s var(--ease); }
textarea { height: auto; padding: 12px 16px; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: #8a93b3; font-weight: 600; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--mint); box-shadow: 0 0 0 3px rgba(45,212,191,.3); }
input[type=checkbox] { height: auto; }
:focus-visible { outline: 3px solid var(--sun); outline-offset: 3px; }
button.big { font: inherit; font-size: 22px; font-weight: 800; color: var(--navy); background: var(--mint); border: 0; border-radius: var(--r-ctl); min-height: 56px; padding: 0 32px; cursor: pointer; box-shadow: 0 4px 0 rgba(0,0,0,.3); transition: transform .12s var(--ease), box-shadow .12s var(--ease); }
button.big.dark { background: var(--ink); color: #fff; }
button.big.sm { min-height: 40px; font-size: 16px; padding: 0 20px; }
button.big.cta { margin-top: 8px; }
button.big:hover:not(:disabled) { filter: brightness(1.06); }
button.big:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 0 0 rgba(0,0,0,.3); }
button.big:disabled { opacity: .4; cursor: default; }
.err { color: var(--sun); font-weight: 700; line-height: 24px; }
.err:empty { display: none; }
.err.keep:empty { display: block; height: 24px; }
a.link { color: var(--mint); font-weight: 700; text-underline-offset: 4px; }
.hint { opacity: .8; font-size: 18px; }

/* motion: one easing, short, nothing loops */
.pop { animation: pop .3s var(--spring) both; }
@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.shake { animation: shake .4s var(--ease); }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.bar-time { position: fixed; top: 0; left: 0; height: 8px; width: 100%; background: var(--sun); transform-origin: left; animation: drain linear forwards; }
@keyframes drain { to { transform: scaleX(0); } }
#banner { position: fixed; bottom: 0; left: 0; right: 0; background: var(--sun); color: var(--ink); font-weight: 800; padding: 8px 16px max(8px, env(safe-area-inset-bottom)); text-align: center; z-index: 60; }
@media (prefers-reduced-motion: reduce) { *:not(.bar-time), *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* answer tiles */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; width: 100%; flex: 1; min-height: 0; }
.tile { border: 0; border-radius: var(--r-tile); color: #fff; font: inherit; font-weight: 800; display: flex; align-items: center; justify-content: center; gap: 16px; box-shadow: 0 6px 0 rgba(0,0,0,.25); cursor: pointer; padding: 16px; transition: transform .12s var(--ease), box-shadow .12s var(--ease); }
.tile:active { transform: translateY(6px); box-shadow: 0 0 0 rgba(0,0,0,.25); }
.tile .sh { font-size: clamp(64px, 26vw, 140px); line-height: 0; display: flex; flex: none; }
.tile.host { font-size: clamp(18px, 2.6vw, 32px); justify-content: flex-start; padding: 16px 24px; cursor: default; text-align: left; }
.tile.host:active { transform: none; box-shadow: 0 6px 0 rgba(0,0,0,.25); }
.tile.host .sh { font-size: clamp(32px, 4vw, 52px); }

/* player: question card above tiles that carry text. A tile with no text keeps the big shape. */
.qplay { display: flex; flex-direction: column; gap: 12px; width: 100%; flex: 1; min-height: 0; }
.pq { flex: none; max-height: 36%; overflow-y: auto; padding: 16px; font-size: clamp(18px, 5vw, 24px); font-weight: 800; line-height: 1.4; text-wrap: balance; }
.tiles.rows { grid-template-columns: 1fr; }
.tile.txt { flex-direction: column; gap: 8px; padding: 12px; min-width: 0; overflow: hidden; }
.tile.txt .sh { font-size: clamp(32px, 12vw, 56px); }
.tile.txt .lb { font-size: clamp(16px, 4.4vw, 22px); font-weight: 700; line-height: 1.3; text-wrap: balance; overflow-wrap: anywhere; max-width: 100%; }
.tile.txt.long .lb { font-size: clamp(14px, 3.6vw, 18px); }
.chosen { max-width: min(90vw, 480px); overflow-wrap: anywhere; }

/* host */
.pin { font-size: clamp(64px, 14vw, 160px); font-weight: 900; line-height: 1.1; letter-spacing: .08em; font-variant-numeric: tabular-nums; background: #fff; color: var(--ink); border-radius: 20px; padding: 8px 32px 8px calc(32px + .08em); box-shadow: 0 8px 0 rgba(0,0,0,.25); }
.bubbles { display: flex; flex-wrap: wrap; gap: 8px 12px; justify-content: center; max-width: min(90vw, 960px); min-height: 48px; }
.bubble { background: rgba(255,255,255,.16); border-radius: 999px; padding: 8px 20px; font-size: 20px; line-height: 32px; font-weight: 700; animation: pop .3s var(--spring) both; cursor: pointer; transition: background-color .15s var(--ease); }
.bubble:hover { background: #c0392b; }
.bignum { font-size: clamp(120px, 30vw, 360px); font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; text-shadow: 0 8px 0 rgba(0,0,0,.2); }
.qbox { font-size: clamp(24px, 4vw, 48px); font-weight: 800; line-height: 1.3; width: 100%; padding: 20px 24px; text-wrap: balance; }
@media (min-width: 900px) { .qbox { padding: 24px 32px; } }
.qstat { display: flex; align-items: center; justify-content: center; gap: 32px; }
.qstat .bignum { font-size: clamp(60px, 10vw, 120px); min-width: 2ch; text-shadow: 0 6px 0 rgba(0,0,0,.2); }
.qstat #tally { font-size: clamp(20px, 2.6vw, 32px); font-weight: 800; line-height: 1.3; font-variant-numeric: tabular-nums; }
.chart { --chrome: 100px; display: flex; align-items: flex-end; gap: 16px; height: min(42vh, 480px); width: min(900px, 94vw); }
.col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 8px; font-size: 28px; font-weight: 800; line-height: 1.2; font-variant-numeric: tabular-nums; }
.col .cnt { display: flex; align-items: center; gap: 8px; }
.col .b { width: 100%; border-radius: 12px 12px 0 0; height: 0; min-height: 8px; transition: height .8s var(--ease); }
.col .shp { display: flex; align-items: center; justify-content: center; height: 48px; font-size: 40px; line-height: 0; }
.col.wrong { opacity: .45; }
.board { width: min(900px, 94vw); display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 16px; font-size: clamp(20px, 3vw, 32px); font-weight: 800; font-variant-numeric: tabular-nums; }
.row .nm { width: 28%; display: flex; align-items: center; gap: 12px; text-align: left; min-width: 0; }
.row .nm .rk { flex: none; min-width: 1.25em; text-align: right; opacity: .6; }
.row .nm .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .track { flex: 1; background: rgba(0,0,0,.25); border-radius: var(--r-ctl); height: 56px; }
.row .fill { height: 100%; border-radius: var(--r-ctl); background: linear-gradient(90deg, var(--mint), #7cf0dc); width: 0; transition: width 1s var(--ease); display: flex; align-items: center; justify-content: flex-end; padding-right: 16px; color: var(--ink); }
.podium { display: flex; align-items: flex-end; gap: 16px; height: 52vh; }
.step { width: clamp(100px, 22vw, 240px); border-radius: var(--r-card) var(--r-card) 0 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 8px; padding: 16px 8px 0; text-align: center; overflow: hidden; overflow-wrap: anywhere; font-weight: 800; font-size: 24px; line-height: 1.3; font-variant-numeric: tabular-nums; height: 0; transition: height 1.2s var(--ease); }
.step .medal { font-size: 48px; line-height: 1; }
.mute { position: fixed; right: 16px; top: 16px; width: 40px; height: 40px; display: grid; place-items: center; background: rgba(0,0,0,.25); border: 0; color: #fff; border-radius: var(--r-ctl); cursor: pointer; z-index: 50; transition: background-color .15s var(--ease); }
.mute:hover { background: rgba(0,0,0,.4); }
.picks { display: flex; flex-direction: column; gap: 16px; width: min(560px, 94vw); max-height: 55vh; overflow: auto; padding-bottom: 8px; }
.pick { display: flex; justify-content: space-between; align-items: center; gap: 16px; text-align: left; padding: 16px 20px; }
.pick b { font-size: 20px; line-height: 1.3; }
.pick small { color: #6b7499; display: block; margin-top: 4px; font-size: 14px; }
.pick .big { flex: none; min-height: 48px; font-size: 18px; padding: 0 24px; }

/* admin: a normal scrolling light page */
body.admin { background: #f3f5fb; color: var(--ink); overflow: auto; user-select: auto; }
.admin #app { display: block; height: auto; max-width: 960px; margin: 0 auto; padding: 32px 24px 96px; text-align: left; }
.admin h1 { font-size: 32px; }
.admin h2 { font-size: 20px; }
.admin .logo { font-size: 28px; text-shadow: none; display: inline-block; }
.admin .logo b { color: #0f9d8a; }
.admin #app > .logo:has(+ #kf) { display: block; text-align: center; margin: 96px 0 24px; }
.admin #kf { margin: 0 auto; }
.admin #kf h2 { text-align: center; }
.admin input, .admin select, .admin textarea { font-size: 16px; text-align: left; height: 36px; padding: 0 12px; border-width: 1px; }
.admin textarea { height: auto; padding: 8px 12px; font-weight: 600; resize: vertical; }
.admin button.big { font-size: 16px; min-height: 48px; }
.admin .card { box-shadow: 0 1px 3px rgba(20,32,63,.15); margin-bottom: 16px; overflow-x: auto; }
.admin .card.q { box-shadow: 0 1px 3px rgba(20,32,63,.15), inset 4px 0 0 var(--mint); }
.admin :focus-visible { outline-color: #0f9d8a; }
.admin .card > label.muted:first-child { display: block; margin-bottom: 8px; }
.topbar { display: flex; align-items: center; gap: 24px; margin-bottom: 32px; flex-wrap: wrap; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { display: inline-flex; align-items: center; height: 36px; padding: 0 16px; border-radius: 999px; font-weight: 700; font-size: 14px; color: var(--ink); text-decoration: none; transition: background-color .15s var(--ease), color .15s var(--ease); }
.topbar nav a:not(.on):hover { background: #e3e7f5; }
.topbar nav a.on { background: var(--ink); color: #fff; }
.admin .row { font-size: 16px; font-weight: 600; justify-content: space-between; }
.admin .row .muted { margin-top: 4px; font-size: 14px; font-weight: 400; }
.btn { font: inherit; font-weight: 700; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; height: 36px; padding: 0 16px; border: 0; border-radius: 8px; background: #e3e7f5; color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap; transition: background-color .15s var(--ease); }
.btn:hover:not(:disabled) { background: #d7dcf0; }
.btn.pri { background: var(--ink); color: #fff; }
.btn.pri:hover:not(:disabled) { background: var(--navy2); }
.btn.danger { background: #fde8e6; color: #b3261e; }
.btn.danger:hover:not(:disabled) { background: #fbd5d1; }
.opt { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.opt .badge { width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; flex: none; }
.opt label.muted { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.opt input[type=checkbox] { width: 20px; height: 20px; margin: 0; flex: none; accent-color: #0f9d8a; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; align-items: center; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 16px; border-bottom: 1px solid #e3e7f5; text-align: left; vertical-align: middle; font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
tr:last-child td { border-bottom: 0; }
th { color: #6b7499; font-size: 13px; font-weight: 600; }
.meter { background: #e3e7f5; border-radius: 4px; height: 8px; width: 140px; display: inline-block; vertical-align: middle; margin-right: 8px; overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 4px; background: #0f9d8a; }
.meter.low i { background: #e8505b; }
.muted { color: #6b7499; }
.okmsg { color: #0f9d8a; font-weight: 700; }
.admin .err { color: #b3261e; }
.admin .actions select { width: auto; }
.admin .opt input:not([type=checkbox]) { flex: 1; min-width: 0; }
.admin button:disabled { opacity: .35; cursor: default; }
.pinbox { display: flex; align-items: center; flex-wrap: wrap; gap: 12px 24px; margin-top: 16px; padding: 12px 16px; background: #eef9f6; border-radius: var(--r-ctl); }
.pinbox.off { background: #f3eeee; }
.pinbox label { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; cursor: pointer; }
.pinbox input[type=checkbox] { width: 18px; height: 18px; margin: 0; accent-color: #0f9d8a; }
.pinbox .btn { margin-left: auto; }
.pinbig { font-size: 20px; letter-spacing: .12em; margin-left: 8px; font-variant-numeric: tabular-nums; }
.live { display: inline-block; vertical-align: middle; background: #0f9d8a; color: #fff; border-radius: 999px; padding: 4px 12px; margin-left: 8px; font-size: 12px; line-height: 1; font-weight: 700; }
.results { width: min(560px, 94vw); max-height: 52vh; overflow: auto; text-align: left; padding: 12px; }
.results .me { background: var(--sun); color: var(--ink); border-radius: 8px; }
.results .row { padding: 8px 12px; gap: 16px; font-size: 18px; font-weight: 700; justify-content: space-between; }
.imgrow { display: flex; align-items: center; gap: 12px; margin: 12px 0 16px; flex-wrap: wrap; }
.thumb { height: 64px; max-width: 120px; border-radius: 8px; object-fit: cover; border: 1px solid #d8dcec; }
.thumb.sm { height: 36px; width: 36px; }
.admin label.btn { cursor: pointer; }
.qimg { width: 100%; max-width: 94vw; flex: 1 1 0; min-height: 0; object-fit: contain; border-radius: var(--r-card); }
.qimg.small { flex: 0 0 auto; max-height: 18vh; width: auto; }
.tile.host.hasimg { padding: 0; flex-direction: column; align-items: stretch; gap: 0; overflow: hidden; }
.tile.host.hasimg .oi { flex: 1 1 0; min-height: 0; width: 100%; object-fit: cover; }
.tile.host .cap { display: flex; align-items: center; gap: 12px; padding: 12px 16px; font-size: clamp(16px, 2.2vw, 28px); text-align: left; }
.tile.host .cap .sh { font-size: clamp(24px, 3vw, 36px); }
