/* =====================================================================
   Teacher Universe — public voting page
   Light, quiet-luxury look: ivory paper, white cards, near-black type,
   champagne gold accents. Flat colours only (no gradients).
   Mobile first; two columns from 960px.
   --tc  colour of the selected teacher (set by app.js)
   --c   colour of one teacher (set per row)
   ===================================================================== */
@property --tc { syntax: "<color>"; inherits: true; initial-value: #c2577a; }

:root {
  --bg: #f6f3ec;
  --paper: #ffffff;
  --paper-2: #fbf9f4;
  --line: #e8e2d6;
  --line-2: #d9cfbd;
  --ink: #17150f;
  --ink-2: #58534a;
  --ink-3: #8d8679;
  --gold: #a27a34;
  --gold-soft: #f3ead7;
  --gold-line: #dcc79d;
  --live: #d23a4e;
  --ok: #2f9a6a;
  --warn: #d08a1e;
  --danger: #cc3a4d;
  --tc: #c2577a;
  --tci: var(--tc);
  --tci: color-mix(in srgb, var(--tc) 80%, #000);
  --shadow-sm: 0 1px 2px rgba(23, 21, 15, .04), 0 6px 16px -8px rgba(23, 21, 15, .10);
  --shadow-md: 0 2px 6px rgba(23, 21, 15, .04), 0 22px 44px -22px rgba(23, 21, 15, .22);
  --f: "IBM Plex Sans Thai", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  --f-serif: "Noto Serif Thai", Georgia, "Times New Roman", serif;
  --f-num: "Inter", "IBM Plex Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  transition: --tc .6s ease;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { -webkit-text-size-adjust: 100%; touch-action: manipulation; background: var(--bg); }
body {
  font: 400 15px/1.5 var(--f);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
button { font: inherit; color: inherit; }
svg { display: block; }
[hidden] { display: none !important; }
.row-score, .row-pct, .row-heat, .plate-score b, .me-n, .speed-t b, .tile b, .board-total b, .live b, .status b, .ban-left b, .combo b, .cp, .fx-p {
  font-family: var(--f-num);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* ---------- Shell ---------- */
.app {
  position: relative;
  height: 100vh; height: 100dvh;
  max-width: 560px; margin: 0 auto;
  padding: calc(8px + var(--safe-t)) 14px calc(12px + var(--safe-b));
  display: flex; flex-direction: column; gap: 10px;
}
.layout {
  flex: 1 1 auto; min-height: 0;
  display: grid; gap: 10px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "board" "stage" "bar";
}

/* ---------- Header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 50px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mark {
  width: 40px; height: 40px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: var(--paper); border: 1px solid var(--gold-line); box-shadow: var(--shadow-sm);
}
.mark svg { width: 24px; height: 24px; fill: var(--gold); }
.brand-t { margin: 0; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.brand-en { font: 600 10.5px/1 var(--f-serif); letter-spacing: .28em; text-transform: uppercase; color: var(--gold); white-space: nowrap; }
.brand-th { font: 700 18px/1.2 var(--f-serif); color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-r { display: flex; align-items: center; gap: 8px; flex: none; }

.live {
  display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 13px 0 12px; border-radius: 999px;
  background: var(--paper); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
  font-size: 12.5px; color: var(--ink-2); white-space: nowrap;
}
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--live); box-shadow: 0 0 0 0 rgba(210, 58, 78, .5); animation: ping 1.8s infinite; }
@keyframes ping { 70% { box-shadow: 0 0 0 7px rgba(210, 58, 78, 0); } 100% { box-shadow: 0 0 0 0 rgba(210, 58, 78, 0); } }
.live-l { font: 700 10.5px/1 var(--f-num); letter-spacing: .14em; color: var(--live); }
.live b { font-size: 13px; font-weight: 700; color: var(--ink); }
.live-u { display: none; }

.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--paper); box-shadow: var(--shadow-sm);
  display: grid; place-items: center; cursor: pointer; padding: 0; color: var(--ink-2); transition: color .2s, border-color .2s;
}
.icon-btn:hover { color: var(--ink); border-color: var(--line-2); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn .off { display: none; }
.icon-btn[aria-pressed="false"] .on { display: none; }
.icon-btn[aria-pressed="false"] .off { display: block; color: var(--ink-3); }

/* ---------- Countdown / status ---------- */
.status {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 32px; padding: 4px 14px;
  border-radius: 999px; background: var(--paper); border: 1px solid var(--line); font-size: 13px; color: var(--ink-2); text-align: center;
}
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--gold); flex: none; }
.status b { font-weight: 700; color: var(--ink); letter-spacing: .02em; }
.status.closed::before { background: var(--danger); }

/* ---------- Leaderboard ---------- */
.board { grid-area: board; position: relative; z-index: 2; min-width: 0; }
.board-h, .board-f { display: none; }
.rows { display: flex; flex-direction: column; gap: 6px; }
.row {
  --c: #c2577a;
  --ci: var(--c);
  --ci: color-mix(in srgb, var(--c) 80%, #000);
  position: relative; width: 100%; min-height: 54px; margin: 0; padding: 7px 14px 7px 8px;
  display: grid; grid-template-columns: 22px 38px minmax(0, 1fr) auto; align-items: center; column-gap: 11px;
  border-radius: 14px; border: 1px solid var(--line); background: var(--paper); box-shadow: var(--shadow-sm);
  text-align: left; cursor: pointer; transition: background .25s, border-color .25s, box-shadow .25s, transform .12s;
}
.row:active { transform: scale(.985); }
.row::before {
  content: ""; position: absolute; left: -1px; top: 12px; bottom: 12px; width: 3px; border-radius: 0 3px 3px 0;
  background: var(--c); opacity: 0; transition: opacity .25s;
}
.row.on { border-color: var(--c); background: var(--paper-2); background: color-mix(in srgb, var(--c) 6%, #fff); }
.row.on::before { opacity: 1; }

.row-rank { display: grid; place-items: center; font: 600 13px/1 var(--f-num); color: var(--ink-3); }
.row-rank svg { width: 18px; height: 14px; fill: var(--gold); }
.row-av { position: relative; width: 38px; height: 38px; border-radius: 50%; overflow: hidden; background: var(--c); box-shadow: 0 0 0 2px var(--paper), 0 0 0 3px var(--c); }
.row-av img { width: 100%; height: 100%; object-fit: cover; object-position: center 20%; display: block; }
.av-ph { width: 100%; height: 100%; display: grid; place-items: center; color: #fff; background: var(--c); font: 600 12px/1 var(--f-serif); }
.row-main { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.row-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.row-name { font: 600 15px/1.25 var(--f-serif); color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-heat {
  display: none; align-items: center; gap: 4px; flex: none; height: 18px; padding: 0 7px 0 6px; border-radius: 999px;
  font-size: 11px; font-weight: 700; line-height: 1; color: var(--ci);
  background: var(--paper-2); background: color-mix(in srgb, var(--c) 12%, #fff);
}
.row.warm .row-heat { display: inline-flex; }
.eq { display: inline-flex; align-items: flex-end; gap: 1.5px; height: 9px; }
.eq b { display: block; width: 2px; height: 40%; border-radius: 1px; background: currentColor; animation: eq .9s ease-in-out infinite; }
.eq b:nth-child(2) { animation-delay: -.3s; }
.eq b:nth-child(3) { animation-delay: -.6s; }
@keyframes eq { 0%, 100% { height: 30%; } 50% { height: 100%; } }
.row.hot .eq b { animation-duration: .5s; }
.row-track { position: relative; height: 4px; border-radius: 4px; background: #efe9de; overflow: hidden; }
.row-track i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: inherit; background: var(--c); transition: width .7s var(--ease); }
.row-end { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; min-width: 56px; }
.row-score { font-size: 19px; font-weight: 700; line-height: 1; letter-spacing: -.02em; color: var(--ink); }
.row-pct { font-size: 11px; font-weight: 500; line-height: 1; color: var(--ink-3); }
.row-score.hidden-score { color: var(--ink-3); letter-spacing: .1em; font-size: 15px; }
.row.hot { border-color: var(--c); animation: heat 1.3s ease-in-out infinite; }
.row.fire { animation-duration: .6s; }
@keyframes heat {
  0%, 100% { box-shadow: var(--shadow-sm), 0 0 0 0 var(--c); }
  50% { box-shadow: var(--shadow-sm), 0 0 0 4px color-mix(in srgb, var(--c) 22%, transparent); }
}

/* the +1 stream coming off each teacher's score */
.row-crowd { position: absolute; right: 16px; top: 0; width: 0; height: 0; pointer-events: none; z-index: 3; }
.cp {
  position: absolute; right: 0; top: 0; white-space: nowrap; pointer-events: none; will-change: transform, opacity;
  font-size: 14px; font-weight: 800; line-height: 1; color: var(--ci);
  text-shadow: 0 0 2px #fff, 0 0 2px #fff, 0 0 6px #fff;
}
.cp.big { font-size: 17px; }
.cp.huge { font-size: 21px; }

/* ---------- Stage: the photo you tap + a caption plate ---------- */
.stage-wrap { grid-area: stage; display: flex; min-height: 0; min-width: 0; }
.stage {
  position: relative; flex: 1; min-height: 240px; display: flex; flex-direction: column; overflow: hidden; isolation: isolate;
  border-radius: 22px; border: 1px solid var(--line); background: var(--paper); box-shadow: var(--shadow-md);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; cursor: pointer; outline: none;
}
.stage-photo { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; background: var(--paper-2); }
.stage-img { position: absolute; inset: 0; transform-origin: 50% 70%; will-change: transform; transition: transform .14s cubic-bezier(.3, 1.5, .5, 1), filter .14s; }
.stage-img img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center 20%; pointer-events: none; }
.stage-img .pop-img { opacity: 0; }
.stage.has-pop.pressed .stage-img .pop-img { opacity: 1; }
.stage.has-pop.pressed .stage-img img:first-child { opacity: 0; }
.stage.pressed .stage-img { transform: scale(.982); filter: brightness(1.04); }
.stage-avatar { position: absolute; inset: 0; }

/* placeholder until a photo is uploaded: a monogram on a soft tint of the teacher's colour */
.ph {
  --c: #c2577a;
  --ci: var(--c);
  --ci: color-mix(in srgb, var(--c) 80%, #000);
  position: absolute; inset: 0; overflow: hidden;
  background: var(--paper-2); background: color-mix(in srgb, var(--c) 9%, #fbf9f4);
}
.ph::before, .ph::after {
  content: ""; position: absolute; left: 50%; top: 47%; aspect-ratio: 1; border-radius: 50%; transform: translate(-50%, -50%);
  border: 1px solid var(--line-2); border-color: color-mix(in srgb, var(--c) 32%, transparent);
}
.ph::before { width: min(60%, 330px); }
.ph::after { width: min(80%, 440px); opacity: .5; }
.ph-in { position: absolute; left: 50%; top: 47%; transform: translate(-50%, -50%); text-align: center; white-space: nowrap; }
.ph-in b { display: block; font: 700 clamp(52px, 16vw, 104px)/1.45 var(--f-serif); color: var(--ci); }

.plate-rank {
  position: absolute; z-index: 3; top: 12px; left: 12px; display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 12px;
  border-radius: 999px; font: 600 12.5px/1 var(--f); color: var(--ink); background: var(--paper); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
}
.plate-rank svg { width: 15px; height: 12px; fill: currentColor; }
.plate-rank.r1 { color: var(--gold); background: var(--gold-soft); border-color: var(--gold-line); }
.plate-rank:empty { display: none; }

.plate {
  position: relative; z-index: 2; flex: none; pointer-events: none;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 13px 18px 14px 20px; background: var(--paper); border-top: 1px solid var(--line);
}
.plate::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px; border-radius: 0 3px 3px 0; background: var(--tc); }
.plate-l { min-width: 0; }
.plate-name { font: 700 clamp(22px, 6.4vw, 30px)/1.2 var(--f-serif); color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plate-sub { margin-top: 2px; font-size: 13px; line-height: 1.4; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plate-sub:empty { display: none; }
.plate-score { position: relative; flex: none; text-align: right; }
.plate-score b { display: block; font-size: clamp(24px, 7vw, 32px); font-weight: 700; line-height: 1; letter-spacing: -.03em; color: var(--ink); }
.plate-score span { display: block; margin-top: 4px; font-size: 11.5px; color: var(--ink-3); }
.plate-score .crowd { position: absolute; right: 2px; top: -6px; width: 0; height: 0; }
.plate-score .cp { --ci: var(--tci); font-size: 15px; }

.hint {
  position: absolute; z-index: 3; left: 50%; bottom: 18px; transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 10px; height: 44px; padding: 0 18px 0 6px; border-radius: 999px;
  font: 600 14px/1 var(--f); color: var(--ink); white-space: nowrap; pointer-events: none;
  background: var(--paper); border: 1px solid var(--line); box-shadow: var(--shadow-md);
  transition: opacity .35s, transform .35s;
}
.hint-ic { position: relative; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--tc); }
.hint-ic::after { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--tc); animation: ripple 1.6s ease-out infinite; }
.hint-ic svg { width: 18px; height: 18px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
@keyframes ripple { from { transform: scale(1); opacity: .7; } to { transform: scale(1.9); opacity: 0; } }
.hint.gone { opacity: 0; transform: translate(-50%, 8px); }

.combo {
  position: absolute; z-index: 3; top: 12px; right: 12px; display: flex; align-items: baseline; gap: 6px; height: 32px; padding: 0 13px;
  align-items: center; border-radius: 999px; background: var(--paper); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
  opacity: 0; transform: translateY(-6px); transition: opacity .2s, transform .2s; pointer-events: none;
}
.combo b { font-size: 17px; font-weight: 800; line-height: 1; color: var(--tci); }
.combo small { font: 700 10px/1 var(--f-num); letter-spacing: .16em; color: var(--ink-3); }
.combo.show { opacity: 1; transform: none; }

/* tap feedback: +1 chips, ripple, hearts */
.fx { position: absolute; inset: 0; z-index: 4; pointer-events: none; overflow: hidden; }
.fx-p {
  position: absolute; left: 0; top: 0; white-space: nowrap; will-change: transform, opacity;
  padding: 5px 10px; border-radius: 999px; background: var(--tc); color: #fff;
  font-size: 15px; font-weight: 800; line-height: 1; letter-spacing: -.01em;
  box-shadow: 0 6px 16px -6px rgba(23, 21, 15, .45);
}
.fx-r { position: absolute; left: 0; top: 0; width: 64px; height: 64px; margin: -32px 0 0 -32px; border-radius: 50%; border: 2px solid var(--tc); will-change: transform, opacity; }
.fx-h { position: absolute; left: 0; top: 0; width: 16px; height: 16px; will-change: transform, opacity; }

.closed {
  position: absolute; inset: 0; z-index: 6; display: grid; place-items: center; align-content: center; text-align: center; padding: 24px;
  font: 700 22px/1.35 var(--f-serif); color: var(--ink); background: rgba(246, 243, 236, .88); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.closed small { display: block; margin-top: 6px; font: 400 14px/1.5 var(--f); color: var(--ink-2); }
.stage.locked { cursor: not-allowed; }
.stage.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* ---------- Desktop-only stats ---------- */
.stats { grid-area: stats; display: none; }

/* ---------- My score + speed ---------- */
.bar {
  grid-area: bar; display: flex; align-items: center; gap: 16px; padding: 10px 16px; min-width: 0;
  border-radius: 18px; background: var(--paper); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
}
.me { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.me-l { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-l b { color: var(--tci); font-weight: 600; }
.me-n { font-size: 22px; font-weight: 700; line-height: 1.15; letter-spacing: -.02em; color: var(--ink); }
.speed { flex: 0 0 46%; display: flex; flex-direction: column; gap: 7px; }
.speed-t { display: flex; align-items: baseline; justify-content: flex-end; gap: 5px; font-size: 12px; color: var(--ink-3); white-space: nowrap; }
.speed-t b { font-size: 17px; font-weight: 700; line-height: 1; color: var(--ink); min-width: 2ch; text-align: right; }
.meter { display: grid; grid-template-columns: repeat(18, 1fr); gap: 2px; height: 8px; }
.meter i { border-radius: 2px; background: #ece6da; transition: background .12s; }
.meter i.x { background: #f6dfe2; }
.meter i.on { background: var(--ok); }
.meter i.on.w { background: var(--warn); }
.meter i.on.x { background: var(--danger); }
.speed.over .speed-t b { color: var(--danger); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; z-index: 30; left: 50%; top: calc(12px + var(--safe-t)); transform: translateX(-50%);
  width: calc(100% - 28px); max-width: 480px; padding: 12px 16px; border-radius: 14px;
  background: var(--paper); color: var(--ink); border: 1px solid var(--line); box-shadow: var(--shadow-md);
  font-size: 14px; line-height: 1.45; animation: toastIn .25s var(--ease);
}
.toast.warn { box-shadow: inset 3px 0 0 var(--warn), var(--shadow-md); }
.toast.danger { box-shadow: inset 3px 0 0 var(--danger), var(--shadow-md); background: #fff7f7; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -10px); } }

/* ---------- Ban sheet ---------- */
.ban { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 20px; background: rgba(23, 21, 15, .42); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.ban-card { width: 100%; max-width: 400px; text-align: center; padding: 28px 22px 20px; border-radius: 24px; background: var(--paper); border: 1px solid var(--line); box-shadow: 0 40px 80px -30px rgba(23, 21, 15, .5); }
.ban-ic { width: 60px; height: 60px; margin: 0 auto 14px; border-radius: 50%; display: grid; place-items: center; background: #fbeaec; border: 1px solid #f1c9ce; }
.ban-ic svg { width: 30px; height: 30px; fill: none; stroke: var(--danger); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ban h2 { margin: 0 0 6px; font: 700 21px/1.3 var(--f-serif); }
.ban-reason { margin: 0 0 10px; color: var(--danger); font-weight: 600; }
.ban-info { margin: 0 0 16px; font-size: 13.5px; color: var(--ink-2); }
.ban-left { display: flex; flex-direction: column; gap: 4px; padding: 14px; border-radius: 16px; background: var(--paper-2); border: 1px solid var(--line); margin-bottom: 14px; }
.ban-left span { font-size: 12px; color: var(--ink-3); }
.ban-left b { font-size: 30px; font-weight: 700; line-height: 1.1; color: var(--ink); letter-spacing: .02em; }
.ban-note { margin: 0 0 16px; font-size: 12px; color: var(--ink-3); }
.btn-ghost { width: 100%; height: 46px; border-radius: 999px; border: 0; background: var(--ink); color: #fff; cursor: pointer; font-weight: 600; }
.btn-ghost:hover { background: #2b2820; }

.noscript { position: fixed; inset: auto 12px 12px; z-index: 50; padding: 12px; border-radius: 12px; background: #fbeaec; color: var(--danger); text-align: center; }

/* =====================================================================
   Responsive
   ===================================================================== */
@media (min-width: 380px) {
  .live-u { display: inline; }
  .live-l { display: none; }
}
@media (min-width: 460px) {
  .live-l { display: inline; }
}
@media (max-width: 374px) {
  .live-l { display: none; }
  .live { padding: 0 11px; }
}
@media (max-width: 359px) {
  .app { padding-left: 10px; padding-right: 10px; }
  .brand-th { font-size: 16px; }
  .mark { width: 36px; height: 36px; }
  .row { column-gap: 9px; padding-right: 11px; }
  .speed { flex-basis: 50%; }
}

/* short phones: tighter leaderboard so the photo keeps its room */
@media (max-height: 720px) and (max-width: 959px) {
  .app { gap: 8px; }
  .layout { gap: 8px; }
  .top { min-height: 44px; }
  .rows { gap: 5px; }
  .row { min-height: 46px; padding-top: 5px; padding-bottom: 5px; grid-template-columns: 20px 32px minmax(0, 1fr) auto; }
  .row-av { width: 32px; height: 32px; }
  .row-main { gap: 5px; }
  .row-name { font-size: 14px; }
  .row-score { font-size: 17px; }
  .row-pct { display: none; }
  .bar { padding: 8px 14px; }
  .me-n { font-size: 19px; }
  .plate { padding-top: 10px; padding-bottom: 11px; }
  .plate-name { font-size: 22px; }
  .plate-score b { font-size: 24px; }
  .status { min-height: 28px; font-size: 12.5px; }
  .hint { bottom: 12px; }
}
@media (max-height: 600px) and (max-width: 959px) {
  .row-track { display: none; }
  .row { min-height: 40px; }
  .plate-sub { display: none; }
}

/* phones held sideways */
@media (max-height: 520px) and (orientation: landscape) {
  .app { max-width: none; padding-left: calc(14px + env(safe-area-inset-left, 0px)); padding-right: calc(14px + env(safe-area-inset-right, 0px)); }
  .layout { grid-template-columns: minmax(0, 1fr) minmax(260px, 38%); grid-template-rows: minmax(0, 1fr) auto; grid-template-areas: "stage board" "stage bar"; }
  .board { overflow: auto; }
  .row-track { display: block; }
}

/* desktop & large tablets: photo on the left, live board on the right */
@media (min-width: 960px) {
  body { overflow: auto; }
  .app { max-width: 1280px; min-height: 660px; padding: 22px 40px 28px; gap: 18px; }
  .top { min-height: 58px; }
  .mark { width: 46px; height: 46px; }
  .mark svg { width: 28px; height: 28px; }
  .brand-en { font-size: 11.5px; }
  .brand-th { font-size: 22px; }
  .live { height: 38px; padding: 0 15px 0 14px; font-size: 13px; }
  .live-l, .live-u { display: inline; }
  .icon-btn { width: 40px; height: 40px; }
  .status { align-self: center; padding: 4px 18px; }

  .layout {
    gap: 16px 28px;
    grid-template-columns: minmax(0, 1fr) 420px;
    grid-template-rows: minmax(0, 1fr) auto auto;
    grid-template-areas: "stage board" "stage stats" "stage bar";
  }
  .board { display: flex; flex-direction: column; min-height: 0; padding: 22px 20px 18px; border-radius: 22px; background: var(--paper); border: 1px solid var(--line); box-shadow: var(--shadow-sm); }
  .board-h { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 16px; padding: 0 2px; }
  .board-h h2 { margin: 0; font: 700 18px/1.2 var(--f-serif); }
  .board-total { font-size: 13px; color: var(--ink-3); }
  .board-total b { font-weight: 700; color: var(--ink); }
  .rows { gap: 10px; }
  .rows.many { overflow-y: auto; min-height: 0; padding: 14px 4px 4px; margin: -14px -4px 0; }
  .row { min-height: 80px; padding: 12px 18px 12px 12px; grid-template-columns: 22px 52px minmax(0, 1fr) auto; column-gap: 14px; border-radius: 16px; background: var(--paper-2); box-shadow: none; }
  .row:hover { border-color: var(--line-2); }
  .row.on, .row.on:hover { border-color: var(--c); }
  .row-av { width: 52px; height: 52px; }
  .av-ph { font-size: 15px; }
  .row-main { gap: 9px; }
  .row-name { font-size: 18px; }
  .row-score { font-size: 26px; }
  .row-pct { font-size: 12px; }
  .row-crowd { right: 20px; top: 2px; }
  .row.hot { animation-name: heat-flat; }
  .cp { font-size: 16px; }
  .cp.big { font-size: 20px; }
  .cp.huge { font-size: 25px; }
  .board-f {
    display: flex; align-items: flex-start; gap: 10px; margin: auto 0 0; padding-top: 16px; border-top: 1px solid var(--line);
    font-size: 12.5px; line-height: 1.6; color: var(--ink-3);
  }
  .board-f svg { width: 18px; height: 18px; flex: none; margin-top: 2px; fill: none; stroke: var(--gold); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
  .rows + .board-f { margin-top: auto; }
  .rows { margin-bottom: 16px; }

  .stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .tile { padding: 14px 18px; border-radius: 18px; background: var(--paper); border: 1px solid var(--line); box-shadow: var(--shadow-sm); }
  .tile span { display: block; font-size: 12.5px; color: var(--ink-3); }
  .tile p { margin: 4px 0 0; display: flex; align-items: baseline; gap: 6px; }
  .tile b { font-size: 26px; font-weight: 700; line-height: 1.1; letter-spacing: -.02em; }
  .tile small { font-size: 12px; color: var(--ink-3); }

  .bar { padding: 16px 20px; border-radius: 20px; }
  .me-n { font-size: 30px; }
  .speed-t b { font-size: 20px; }
  .meter { height: 10px; }

  .stage { border-radius: 26px; min-height: 500px; }
  .plate { padding: 20px 28px 22px 30px; }
  .plate::before { top: 20px; bottom: 20px; width: 4px; }
  .plate-name { font-size: clamp(30px, 2.8vw, 40px); }
  .plate-sub { font-size: 15px; margin-top: 4px; }
  .plate-score b { font-size: clamp(32px, 3vw, 44px); }
  .plate-score span { font-size: 13px; }
  .plate-score .cp { font-size: 19px; }
  .plate-rank { top: 18px; left: 18px; height: 32px; font-size: 13.5px; padding: 0 14px; }
  .ph-in b { font-size: clamp(84px, 8vw, 132px); }
  .hint { height: 50px; font-size: 15px; padding-right: 22px; bottom: 24px; }
  .hint-ic { width: 38px; height: 38px; }
  .combo { top: 18px; right: 18px; height: 36px; }
  .fx-p { font-size: 18px; padding: 6px 12px; }
}
@keyframes heat-flat {
  0%, 100% { box-shadow: 0 0 0 0 var(--c); }
  50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 22%, transparent); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
