:root {
  --bg: #f4f6f3; --card: #fff; --ink: #1c2321; --muted: #6b7570; --line: #e2e7e3;
  --green: #12a150; --green-soft: #e3f6ea; --gold: #f2b705; --gold-soft: #fff6d6;
  --red: #e5383b; --orange: #f07b16; --blue: #2f6fdb; --gray: #9aa39e;
  --radius: 16px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: 'Sarabun', system-ui, sans-serif; background: var(--bg); color: var(--ink); font-size: 16px; }
.wrap { max-width: 520px; margin: 0 auto; padding: 14px 14px 40px; }
.wrap.wide { max-width: 1100px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
h1 { font-size: 22px; margin: 0 0 14px; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 18px 0 8px; }
code { background: #eef1ee; padding: 1px 5px; border-radius: 5px; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.top-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.event-name { font-weight: 800; font-size: 19px; }
.clock { font-weight: 700; font-variant-numeric: tabular-nums; background: var(--ink); color: #fff; padding: 4px 10px; border-radius: 999px; }

.announce { background: var(--gold-soft); border: 1px solid #f3d978; padding: 10px 12px; border-radius: 12px; margin-bottom: 12px; font-weight: 600; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.card.pad0 { padding: 0; overflow-x: auto; }

/* ---------- hero (player) */
.hero { border-radius: 22px; padding: 22px 18px; text-align: center; color: #fff; margin-bottom: 12px; background: var(--gray); transition: background .3s; }
.hero-label { opacity: .85; font-size: 14px; }
.hero-round { font-size: 26px; font-weight: 700; }
.hero-round span { font-size: 64px; font-weight: 800; line-height: 1; display: block; }
.hero-time { font-size: 18px; opacity: .95; margin-top: 4px; }
.hero-status { font-size: 22px; font-weight: 800; margin-top: 12px; }
.countdown { font-size: 18px; font-variant-numeric: tabular-nums; margin-top: 6px; font-weight: 600; }
.hero-sub { font-size: 14px; opacity: .9; margin-top: 4px; }
.lvl-far { background: linear-gradient(135deg, #3a7bd5, #2f6fdb); }
.lvl-wait { background: linear-gradient(135deg, #2f9bd5, #1f7fb8); }
.lvl-soon { background: linear-gradient(135deg, #f7a325, #f07b16); }
.lvl-next { background: linear-gradient(135deg, #f26b1d, #e5383b); }
.lvl-now { background: linear-gradient(135deg, #e5383b, #b5179e); animation: pulse 1.6s infinite; }
.lvl-done { background: linear-gradient(135deg, #7d8a84, #5f6b66); }
.lvl-cancelled { background: #555; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(229,56,59,.5); } 50% { box-shadow: 0 0 0 12px rgba(229,56,59,0); } }

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { text-align: center; }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-val { font-size: 22px; font-weight: 800; }

.prizes { list-style: none; margin: 0; padding: 0; }
.prizes li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.prizes li:last-child { border-bottom: 0; }
.rank { background: var(--gold); color: #fff; font-weight: 800; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: 14px; }
.note { margin-top: 10px; color: var(--muted); }
.mini { margin: 0; padding-left: 18px; }
.mini li { margin: 4px 0; }

.btn { display: inline-block; border: 0; background: var(--green); color: #fff; font: inherit; font-weight: 700; padding: 10px 16px; border-radius: 12px; cursor: pointer; text-decoration: none; text-align: center; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-block { display: block; width: 100%; padding: 14px; font-size: 17px; }
.btn-ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn-danger { background: var(--red); }
.btn-go { background: var(--red); font-size: 17px; padding: 14px 18px; }
.btn-sm { padding: 5px 10px; font-size: 14px; border-radius: 8px; }
.foot { text-align: center; font-size: 13px; margin-top: 14px; }

/* ---------- schedule table */
.now-bar { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.now-bar > div { background: var(--card); border-radius: 14px; padding: 10px 14px; display: flex; flex-direction: column; }
.now-bar b { font-size: 20px; }
table.sched { width: 100%; border-collapse: collapse; }
.sched th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 600; padding: 10px; border-bottom: 1px solid var(--line); background: #fafbfa; position: sticky; top: 0; }
.sched td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.sched tr[onclick] { cursor: pointer; }
.sched td.rn { font-weight: 800; font-size: 18px; width: 48px; text-align: center; }
.sched td.pz { font-size: 14px; }
.sched tr.st-done td { color: var(--muted); }
.sched tr.st-playing td { background: #fff0f0; }
.sched tr.hl td { background: #eaf1ff; }
.sched td:nth-child(2) { white-space: nowrap; font-variant-numeric: tabular-nums; }
.sched tr.ev td { background: var(--green-soft); color: #0b6b35; font-size: 15px; }
.sched tr.ev-golden td { background: #22c55e; color: #fff; }
.sched tr.ev-golden .muted { color: #e8ffe9; }
.sched tr.ev-break td { background: #e9ecea; color: #444; }
.sched tr.ev.st-done td { opacity: .6; }
.delay { color: var(--orange); font-size: 12px; font-weight: 600; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.b-waiting { background: #eef2f7; color: #4b5a6b; }
.b-playing { background: var(--red); color: #fff; }
.b-done { background: var(--green-soft); color: #0b6b35; }
.b-cancelled { background: #ddd; color: #555; }

/* ---------- admin */
.tabs { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; }
.tabs button { border: 0; background: #fff; padding: 10px 14px; border-radius: 12px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.tabs button.active { background: var(--ink); color: #fff; }
.now-ctl { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.now-ctl .btn-go { margin-left: auto; }
.big { font-size: 26px; font-weight: 800; }
.seg { white-space: nowrap; }
.sb { border: 1px solid var(--line); background: #fff; font: inherit; font-size: 13px; padding: 6px 9px; cursor: pointer; margin: 0 -1px 0 0; }
.sb:first-child { border-radius: 8px 0 0 8px; }
.sb:last-child { border-radius: 0 8px 8px 0; }
.sb.on { font-weight: 800; }
.sb.on.b-waiting { background: #dfe6ef; }
.sb.on.b-playing { background: var(--red); color: #fff; border-color: var(--red); }
.sb.on.b-done { background: var(--green); color: #fff; border-color: var(--green); }
.sb.on.b-cancelled { background: #888; color: #fff; }
.admin-table input { width: 100%; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid #cfd6d1; border-radius: 9px; width: 100%; background: #fff; }
label { display: block; font-size: 13px; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--ink); font-size: 15px; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; align-items: end; }
.span2 { grid-column: span 2; }
.span3 { grid-column: 1 / -1; }
.w-s { width: 70px !important; }
.w-m { width: 90px !important; }
.nowrap { white-space: nowrap; }
.row-actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.ev-edit { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; }
.ev-edit.ev-golden { border-left: 6px solid #22c55e; }
.ev-edit.ev-break { border-left: 6px solid var(--gray); }
.faq-edit { display: grid; grid-template-columns: 1fr 2fr auto; gap: 8px; margin-bottom: 8px; align-items: start; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 12px; font-weight: 600; z-index: 9; }
.toast.bad { background: var(--red); }
.login { max-width: 360px; margin: 60px auto; }
.login form { display: grid; gap: 12px; }
.err { color: var(--red); font-weight: 600; }
@media (max-width: 640px) {
  .sched td, .sched th { padding: 8px 6px; }
  .sched td.pz { font-size: 13px; }
  .faq-edit { grid-template-columns: 1fr; }
  .span2 { grid-column: 1 / -1; }
  .admin-table th:nth-child(4), .admin-table td:nth-child(4) { display: none; }
}

/* ---------- QR print */
.print-page { background: #fff; }
.print-bar { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.qr-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; padding: 12px; }
.qr-card { border: 1.5px dashed #bbb; border-radius: 12px; padding: 10px; text-align: center; break-inside: avoid; }
.qr-card img { width: 100%; max-width: 160px; }
.qr-title { font-weight: 800; font-size: 20px; }
.qr-sub { font-size: 14px; }
.qr-hint { font-size: 11px; color: var(--muted); }
.qr-main { background: var(--green-soft); }
@media print {
  .no-print { display: none !important; }
  .qr-grid { gap: 6mm; padding: 0; }
  @page { size: A4; margin: 10mm; }
}
