:root {
  --bg: #0b1020;
  --card: rgba(16, 22, 40, 0.94);
  --text: #eef2fa;
  --muted: #9aa6c0;
  --accent: #ffd54a;
  --primary: #d8262e;
  --line: rgba(255, 255, 255, 0.12);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: 'Sarabun', sans-serif; }
#app canvas { display: block; touch-action: none; cursor: grab; }
#app canvas:active { cursor: grabbing; }
.hidden { display: none !important; }

.overlay { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: radial-gradient(ellipse at top, #1f3c88 0%, #0b1020 70%); z-index: 10; overflow: auto; }
#summary { background: rgba(5, 8, 18, 0.85); }
.card { width: min(520px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 28px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); }
.card.wide { width: min(900px, 100%); }
.brand { font-family: 'Kanit'; font-weight: 700; color: var(--accent); letter-spacing: 1px; }
.brand { display: flex; align-items: center; gap: 12px; font-size: 22px; }
.brand .logo { height: 64px; width: auto; filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.45)); }
.brand small { display: block; font-size: 13px; font-weight: 400; letter-spacing: 0; color: var(--muted, #9aa4c0); }
h1 { font-family: 'Kanit'; font-weight: 700; margin: 4px 0 6px; font-size: 28px; }
.muted { color: var(--muted); font-size: 14px; margin: 0 0 18px; }
label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 12px; color: var(--muted); }
input, select { display: block; width: 100%; margin-top: 6px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: #0d1428; color: var(--text); font: inherit; font-size: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; }
button {
  font: 600 15px 'Kanit', sans-serif; padding: 10px 16px; border-radius: 12px; border: 0; color: var(--text); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: linear-gradient(180deg, #2a3866, #1d2850); box-shadow: 0 4px 0 #0d1430, 0 6px 14px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
}
button:hover { filter: brightness(1.12); }
button:active { transform: translateY(3px); box-shadow: 0 1px 0 #0d1430, inset 0 1px 0 rgba(255, 255, 255, 0.18); }
button.primary { background: linear-gradient(180deg, #ff5058, var(--primary)); box-shadow: 0 5px 0 #8e141b, 0 8px 18px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.25); font-size: 20px; width: 100%; margin-top: 8px; padding: 13px; letter-spacing: 0.5px; }
button.primary:active { box-shadow: 0 2px 0 #8e141b, inset 0 1px 0 rgba(255, 255, 255, 0.25); }
.ic { width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.18em; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: #556; }
.dot.on { background: #35d27f; box-shadow: 0 0 8px #35d27f; }
.dot.off { background: #e2363e; }
.ok { color: #74eaa8; display: inline-flex; gap: 4px; align-items: center; }
.bad { color: #ff8f95; display: inline-flex; gap: 4px; align-items: center; }
.ic.gold { color: var(--accent); width: 1.2em; height: 1.2em; margin-right: 8px; }
.help { margin: 18px 0 0; padding: 0; list-style: none; font-size: 14px; color: var(--muted); display: grid; gap: 8px; }
.help li { display: flex; gap: 10px; align-items: flex-start; }
.help li > .ic { color: var(--accent); margin-top: 2px; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#hud .top { position: absolute; top: 12px; left: 12px; right: 12px; display: flex; align-items: center; gap: 12px; }
#zoneName { font-family: 'Kanit'; font-size: 20px; background: rgba(0, 0, 0, 0.55); padding: 6px 14px; border-radius: 12px; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
#zoneName .ic { color: var(--accent); }
.progress { flex: 1; height: 8px; background: rgba(255, 255, 255, 0.15); border-radius: 4px; overflow: hidden; }
#progressBar { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), var(--accent)); }
#timer { font-variant-numeric: tabular-nums; background: rgba(0, 0, 0, 0.55); padding: 6px 10px; border-radius: 10px; }
#crosshair { display: none; } /* ใช้จุดเล็ง 3 มิติในฉากแทน */
#crosshair-old { position: absolute; left: 50%; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px; border: 2px solid rgba(255, 255, 255, 0.7); border-radius: 50%; transition: transform 0.15s, border-color 0.15s; }
#crosshair.on { border-color: var(--accent); transform: scale(1.5); }
#quizHint { position: absolute; left: 50%; bottom: 80px; transform: translateX(-50%); background: rgba(0, 0, 0, 0.7); border: 1px solid var(--accent); padding: 10px 18px; border-radius: 12px; font-weight: 600; text-align: center; max-width: calc(100% - 32px); }
#toast { position: absolute; left: 50%; top: 70px; transform: translate(-50%, -10px); opacity: 0; transition: 0.3s; background: rgba(0, 0, 0, 0.8); padding: 12px 22px; border-radius: 14px; font-size: 20px; font-weight: 700; max-width: calc(100% - 32px); text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.controls { position: absolute; right: 12px; bottom: 12px; display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; pointer-events: auto; }
.controls button { padding: 8px 12px; font-size: 14px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 12px 0; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: center; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 600; }
.score { font-size: 20px; color: var(--accent); font-weight: 700; margin: 0; }
#summary .row button { width: auto; margin-top: 8px; }

@media (max-width: 640px) {
  #zoneName { font-size: 15px; }
  table { font-size: 12px; }
  th:nth-child(3), td:nth-child(3), th:nth-child(4), td:nth-child(4), th:nth-child(5), td:nth-child(5), th:nth-child(6), td:nth-child(6) { display: none; }
}

/* โหมดแว่น: operator เป็นคนคุมเวลา */
#netBadge { pointer-events: auto; background: rgba(0, 0, 0, 0.55); box-shadow: none; padding: 6px 12px; font-size: 15px; border-radius: 12px; white-space: nowrap; }
body:not(.networked) #netBadge { display: none; }
body.networked #btnPause, body.networked #btnSpeed, body.networked #btnQuit { display: none; }
.seat-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.seat-buttons button { font: 700 32px 'Kanit'; padding: 18px 0; }

/* ผลการเล่นบนเว็บ: บันทึกแล้ว + ปุ่มเปิดเกียรติบัตร */
.web-result { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin: 12px 0 4px; padding: 12px 14px; border-radius: 12px; background: rgba(255, 210, 63, 0.1); border: 1px solid rgba(255, 210, 63, 0.35); }
.web-result .btn-cert { display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 10px; background: var(--accent); color: #1a1300; font-weight: 700; text-decoration: none; }
