:root {
  --bg: #14061a;
  --panel: #2a1250;
  --panel2: #3b1d73;
  --ink: #fff7ff;
  --muted: #f5c6ff;
  --line: #7c3aed;
  --chung: #2563eb;
  --chung-d: #1d4ed8;
  --hong: #ef4444;
  --hong-d: #dc2626;
  --gold: #facc15;
  --ok: #4ade80;
  --warn: #fb923c;
  radius: 16px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif; }
button, input, select { font: inherit; }
button { cursor: pointer; border: 0; }
.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: linear-gradient(90deg, #1e3a8a, #6d28d9, #9d174d);
  border-bottom: 0; position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 800; letter-spacing: .04em; }
.brand small { color: var(--muted); font-weight: 500; margin-left: 6px; }
.chip { font-size: 12px; padding: 4px 8px; border-radius: 999px; background: #fde047; color: #111; font-weight: 800; }
.chip.on { background: #4ade80; color: #052e16; }
.grow { flex: 1; }
.screen { padding: 14px; flex: 1; }
.hero { max-width: 720px; margin: 0 auto; }
h1 { font-size: 28px; margin: 8px 0 4px; }
.sub { color: var(--muted); margin-bottom: 22px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.card {
  background: linear-gradient(180deg, #3b1d73, #2a1250);
  border: 2px solid #c084fc; border-radius: 18px; padding: 16px;
}
.card h2 { margin: 0 0 10px; font-size: 16px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 12px 14px; border-radius: 14px; font-weight: 700; width: 100%;
  background: var(--panel2); color: var(--ink); border: 1px solid var(--line);
}
.btn:active { transform: scale(.98); }
.btn.primary { background: linear-gradient(180deg, #60a5fa, #2563eb); border-color: transparent; color: #fff; }
.btn.danger { background: linear-gradient(180deg, #fb7185, #e11d48); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.gold { background: linear-gradient(180deg, #facc15, #ca8a04); color: #111; border: 0; }
.btn.big { min-height: 64px; font-size: 20px; }
.btn.xl { min-height: 76px; font-size: 22px; border-radius: 18px; }
.btn.penalty { min-height: 72px; font-size: 20px; }
.btn.chung-p { background: #1d4ed8; border: 0; }
.btn.hong-p { background: #dc2626; border: 0; }

.judge-app { min-height: 100dvh; display: flex; flex-direction: column; }
.judge-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.judge-head {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px; padding: 6px 8px;
}
.jh-side { border-radius: 12px; padding: 8px 10px; display: flex; flex-direction: column; }
.jh-side.chung { background: linear-gradient(180deg, #3b82f6, #1d4ed8); }
.jh-side.hong { background: linear-gradient(180deg, #f87171, #dc2626); text-align: right; align-items: flex-end; }
.jh-pts { font-size: 34px; font-weight: 900; line-height: 1; }
.jh-mid { display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 88px; }
.jh-mid .clock { font-size: 28px; }
.judge-body {
  flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 0 6px 8px;
  min-height: 0;
}
.judge-col { display: grid; grid-template-rows: 1.15fr 1fr; gap: 6px; min-height: 0; }
.score-row { display: grid; gap: 6px; min-height: 0; }
.score-row.two { grid-template-columns: 1fr 1fr; }
.score-row.three { grid-template-columns: 1fr 1fr 1fr; }
.score-row.five { grid-template-columns: repeat(5, 1fr); }
.score-btn.minus { filter: brightness(0.78); }
.score-btn.minus .pts-num { font-size: clamp(14px, 3.6vw, 22px); }
.score-btn {
  width: 100%; height: 100%; min-height: 0; border: 0; border-radius: 16px;
  color: #fff; font-weight: 900; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; position: relative;
}
.judge-col.chung .score-btn { background: linear-gradient(180deg, #60a5fa, #1d4ed8); }
.judge-col.hong .score-btn { background: linear-gradient(180deg, #fb7185, #dc2626); }
.score-btn:active { filter: brightness(1.15); transform: scale(.98); }
.score-btn.waiting { outline: 3px solid #fde047; }
.score-btn.peer { outline: 3px solid #86efac; }
.pts-num { font-size: clamp(28px, 9vw, 56px); line-height: 1; }
.pts-lab { font-size: clamp(11px, 3.2vw, 16px); font-weight: 700; opacity: .92; }
.vote-n { position: absolute; top: 6px; right: 8px; font-size: 11px; background: #0008; padding: 2px 6px; border-radius: 999px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 12px; color: var(--muted); }
.field input, .field select {
  background: #0b0d14; color: var(--ink); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; outline: none;
  width: 100%; max-width: 100%; box-sizing: border-box; min-width: 0;
}
.code-input { text-transform: uppercase; letter-spacing: .3em; text-align: center; font-size: 28px; font-weight: 800; }
.roles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.role {
  border: 1px solid var(--line); background: var(--panel2); border-radius: 14px; padding: 12px; text-align: left;
  color: #fff;
}
.role.active { outline: 2px solid #60a5fa; }
.role b { display: block; color: #fff; }
.role span { color: var(--muted); font-size: 12px; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.5; }
.err { color: #fca5a5; font-size: 13px; min-height: 18px; }

/* kyorugi operator / judge */
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.side { border-radius: 18px; padding: 10px; min-height: 120px; }
.side.chung { background: linear-gradient(180deg, #1e3a8a, #1e40af); }
.side.hong { background: linear-gradient(180deg, #7f1d1d, #991b1b); }
.side .nm { font-size: 13px; opacity: .9; }
.side .pts { font-size: clamp(42px, 14vw, 84px); font-weight: 900; line-height: 1; }
.side .meta { display: flex; justify-content: space-between; font-size: 12px; opacity: .9; }
.clockbox {
  text-align: center; padding: 8px 0 12px;
}
.clock {
  font-variant-numeric: tabular-nums; font-weight: 900;
  font-size: clamp(36px, 12vw, 72px); letter-spacing: .04em;
}
.clock.warn { color: #facc15; text-shadow: 0 0 16px #facc15; }
.clock.hot {
  color: #fff;
  background: #ef4444;
  border-radius: 16px; padding: 4px 16px;
}
@keyframes blink { 50% { opacity: .35; } }
@keyframes last10 { 50% { background-position: 100% 0; } }
@keyframes hotpulse { 50% { transform: scale(1.04); } }
.roundline { color: var(--muted); font-size: 13px; }
.pad { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.pad .btn { min-height: 58px; }
.judge-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.col-actions { display: grid; gap: 8px; }
.tiny { font-size: 11px; color: var(--muted); }
.eventlog { max-height: 120px; overflow: auto; font-size: 12px; color: var(--muted); }
.eventlog div { padding: 4px 0; border-bottom: 1px solid #222; }

/* display */
.display { min-height: 100dvh; display: flex; flex-direction: column; background: #05060a; }
.display .bar {
  display: flex; justify-content: space-between; align-items: center; padding: 10px 18px; font-size: 18px;
}
.display .arena { flex: 1; display: grid; grid-template-columns: 1fr auto 1fr; }
.display .pane { display: flex; flex-direction: column; justify-content: center; align-items: center; }
.display .pane.chung { background: linear-gradient(180deg, #3b82f6, #1d4ed8); }
.display .pane.hong { background: linear-gradient(180deg, #f87171, #b91c1c); }
.display .big { font-size: clamp(80px, 22vw, 240px); font-weight: 900; line-height: .9; }
.display .who { font-size: clamp(18px, 4vw, 36px); font-weight: 700; margin-bottom: 8px; }
.display .mid {
  width: min(28vw, 280px); display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: #07080c; gap: 8px;
}
.display .mid .t { font-size: clamp(32px, 8vw, 72px); font-weight: 900; }
.display .mid .t.hot {
  color: #fff; background: #ef4444; border-radius: 16px; padding: 6px 12px;
}
.display .mid.hotbg { background: #7f1d1d; }
.display .gj { margin-top: 10px; font-size: clamp(16px, 3vw, 28px); }
.banner {
  text-align: center; padding: 10px; font-size: 28px; font-weight: 800; background: #111;
}
.banner.win-chung { background: #2563eb; }
.banner.win-hong { background: #ef4444; }
.qr-page { padding: 16px; text-align: center; }
.qr-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.qr-box { background: #fff; color: #111; border-radius: 18px; padding: 12px; }
.qr-box img { width: 100%; max-width: 260px; height: auto; background: #fff; }
.qr-box h3 { margin: 0 0 8px; font-size: 18px; }
@media (max-width: 700px) { .qr-grid { grid-template-columns: 1fr; } }

/* poomsae */
.pres { display: grid; gap: 8px; }
.pres row, .pres .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.steppers { display: flex; gap: 6px; }
.steppers button { width: 44px; height: 44px; border-radius: 12px; background: var(--panel2); color: #fff; }
.poom-deduct { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.poom-deduct-col { display: flex; flex-direction: column; gap: 10px; }
.poom-deduct .btn { min-height: 64px; font-size: 22px; font-weight: 800; }
.score-pill { font-size: 28px; font-weight: 800; min-width: 70px; text-align: center; }
.judge-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.judge-table th, .judge-table td { padding: 8px; border-bottom: 1px solid var(--line); text-align: center; }
.judge-table tr.hl td { background: #3f3a14; color: #fde68a; }
button:disabled { opacity: .45; pointer-events: none; }
.devices { font-size: 12px; color: var(--muted); }
.fs-btn { width: auto; min-height: 36px; padding: 6px 10px; }

@media (max-width: 700px) {
  .display .arena { grid-template-columns: 1fr; grid-template-rows: 1fr auto 1fr; }
  .display .mid { width: 100%; flex-direction: row; justify-content: space-around; padding: 8px; }
  .display .big { font-size: 22vw; }
}
.hidden { display: none !important; }
.toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: #111827; border: 1px solid #374151; padding: 10px 14px; border-radius: 999px; z-index: 50;
}
