:root {
  --bg: rgba(12, 18, 28, 0.78);
  --bg2: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 255, 255, 0.12);
  --fg: #eef2f7;
  --muted: #9aa6b5;
  --gold: #ffd24a;
  --green: #22c55e;
  --red: #ef4444;
  --blue: #3b82f6;
  --panel-w: 400px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #000; color: var(--fg);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif; font-size: 14px; }
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
button { font: inherit; color: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--bg2); border-radius: 8px; padding: 6px 10px; }
button:hover { background: rgba(255,255,255,0.14); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.primary { background: var(--gold); color: #1a1300; border-color: transparent; font-weight: 700; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; }
input { font: inherit; color: var(--fg); background: rgba(0,0,0,0.35); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- 상단 바 */
#topbar { position: fixed; top: 0; left: 0; right: 0; height: 52px; display: flex; align-items: center; gap: 16px;
  padding: 0 16px; background: linear-gradient(180deg, rgba(5,10,18,0.9), rgba(5,10,18,0.55)); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line); z-index: 10; }
.logo { font-size: 20px; letter-spacing: -0.5px; font-weight: 300; }
.logo b { color: var(--gold); font-weight: 800; }
#raceinfo { font-weight: 600; }
#phase { display: flex; gap: 8px; align-items: center; padding: 4px 12px; border-radius: 999px; background: var(--bg2); border: 1px solid var(--line); }
#phase.betting { background: rgba(34,197,94,0.18); border-color: rgba(34,197,94,0.5); }
#phase.race { background: rgba(239,68,68,0.2); border-color: rgba(239,68,68,0.55); }
#phase.result { background: rgba(59,130,246,0.2); border-color: rgba(59,130,246,0.55); }
#phase.urgent { animation: blink 0.8s infinite; }
@keyframes blink { 50% { background: rgba(239,68,68,0.45); } }
#phase-time { font-variant-numeric: tabular-nums; font-weight: 700; }
#pool { color: var(--muted); font-size: 13px; }
#userbox { margin-left: auto; display: flex; gap: 10px; align-items: center; }
#userbox .bal { color: var(--gold); font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- HUD */
#hud { position: fixed; top: 64px; left: 12px; width: 250px; z-index: 5; pointer-events: none; }
#clock { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin-bottom: 8px; }
#clock .row { display: flex; justify-content: space-between; align-items: baseline; }
#clock-t { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
#clock-d { color: var(--gold); font-weight: 700; }
#clock .bar { height: 5px; background: rgba(255,255,255,0.12); border-radius: 3px; margin-top: 6px; overflow: hidden; }
#clock .bar i { display: block; height: 100%; width: 0; background: var(--gold); }
#standings { list-style: none; margin: 0; padding: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
#standings li { display: grid; grid-template-columns: 22px 26px 1fr auto; align-items: center; gap: 6px; padding: 3px 6px; border-radius: 6px; font-size: 13px; }
#standings li.mine { background: rgba(255,210,74,0.18); }
#standings li .rk { color: var(--muted); font-weight: 700; text-align: right; }
#standings li .gap { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
#standings li.fin .gap { color: var(--gold); }

.badge { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 6px;
  font-weight: 800; font-size: 13px; border: 1px solid rgba(255,255,255,0.35); flex: none; }

/* ---------- 출전마 소개 카드 */
#horse-card { position: fixed; top: 64px; left: 12px; width: 300px; z-index: 5; pointer-events: none; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
#horse-card .top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
#horse-card .top .badge { width: 38px; height: 38px; font-size: 20px; }
#horse-card .nm { font-size: 19px; font-weight: 800; }
#horse-card .idx { margin-left: auto; color: var(--muted); }
#horse-card .s { display: grid; grid-template-columns: 48px 1fr 30px; align-items: center; gap: 8px; margin: 5px 0; font-size: 13px; }
#horse-card .s i { display: block; height: 7px; border-radius: 4px; background: rgba(255,255,255,0.12); overflow: hidden; }
#horse-card .s i b { display: block; height: 100%; background: linear-gradient(90deg, #60a5fa, #22d3ee); }
#horse-card .s em { font-style: normal; font-weight: 700; text-align: right; }
#horse-card .tags { margin-top: 9px; font-size: 13px; line-height: 1.45; }
#horse-card .tags b { color: var(--gold); }
#horse-card .row { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; font-size: 12px; color: var(--muted); }
#horse-card .row b { color: var(--fg); }
.entry.featured { border-color: rgba(96,165,250,0.9); background: rgba(96,165,250,0.12); }

/* ---------- 카메라 */
#cams { position: fixed; left: 50%; bottom: 14px; transform: translateX(calc(-50% - var(--panel-w) / 2)); display: flex; gap: 6px;
  padding: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; z-index: 5; }
#cams button { white-space: nowrap; flex: none; padding: 6px 8px; font-size: 13px; }
#cams button.on { background: var(--gold); color: #1a1300; border-color: transparent; font-weight: 700; }
body.panel-closed #cams { transform: translateX(-50%); }

/* ---------- 패널 */
#panel { position: fixed; top: 52px; right: 0; bottom: 0; width: var(--panel-w); background: var(--bg); backdrop-filter: blur(8px);
  border-left: 1px solid var(--line); display: flex; flex-direction: column; z-index: 6; transition: transform 0.25s; }
body.panel-closed #panel { transform: translateX(100%); }
#panel-toggle { position: fixed; top: 62px; right: calc(var(--panel-w) + 10px); z-index: 7; background: var(--bg); transition: right 0.25s; }
body.panel-closed #panel-toggle { right: 10px; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; border-radius: 0; background: transparent; padding: 11px 4px; color: var(--muted); }
.tabs button.on { color: var(--fg); box-shadow: inset 0 -2px 0 var(--gold); font-weight: 700; }
.tab { display: none; overflow-y: auto; padding: 12px; flex: 1; }
.tab.on { display: block; }
#race-head { margin-bottom: 10px; }
#race-head h3 { margin: 0 0 2px; font-size: 17px; }

.entry { display: grid; grid-template-columns: 30px 1fr auto; gap: 8px; align-items: center; padding: 8px; border: 1px solid var(--line);
  border-radius: 10px; margin-bottom: 6px; background: var(--bg2); cursor: pointer; }
.entry.sel { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
.entry .badge { width: 28px; height: 28px; font-size: 15px; }
.entry .nm { font-weight: 700; }
.entry .nm small { color: var(--muted); font-weight: 400; margin-left: 4px; }
.entry .stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: 4px; }
.entry .stat { font-size: 10px; color: var(--muted); }
.entry .stat i { display: block; height: 4px; border-radius: 2px; background: rgba(255,255,255,0.12); margin-top: 2px; overflow: hidden; }
.entry .stat i b { display: block; height: 100%; background: linear-gradient(90deg, #60a5fa, #22d3ee); }
.entry .recent { font-size: 11px; color: var(--muted); margin-top: 3px; }
.entry .odds { display: flex; flex-direction: column; gap: 4px; }
.entry .odds button { min-width: 78px; padding: 4px 6px; font-size: 12px; display: flex; justify-content: space-between; gap: 6px; }
.entry .odds button b { font-variant-numeric: tabular-nums; }
.entry .odds button.on { background: var(--gold); color: #1a1300; }

#slip { position: sticky; bottom: -12px; margin: 10px -12px 0; padding: 12px; background: rgba(10,14,22,0.97); border-top: 1px solid var(--line); }
#slip .sel-line { margin-bottom: 8px; }
#slip .chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
#slip .chips button { padding: 4px 8px; font-size: 12px; }
#slip .expect { color: var(--gold); margin: 6px 0; font-weight: 700; }
#slip .go { width: 100%; padding: 10px; font-size: 15px; }
#mybets { margin-top: 12px; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; justify-content: space-between; gap: 8px; padding: 7px 4px; border-bottom: 1px solid var(--line); font-size: 13px; }
.win { color: var(--green); font-weight: 700; }
.lose { color: var(--muted); }
h4 { margin: 14px 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.race-card { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin-bottom: 8px; background: var(--bg2); }
.race-card .top3 { display: flex; gap: 10px; margin-top: 4px; flex-wrap: wrap; }

/* ---------- 결과 */
#result { position: fixed; left: calc(50% - var(--panel-w) / 2); top: 50%; transform: translate(-50%, -50%); width: min(560px, 92vw);
  background: rgba(8,12,20,0.93); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px; z-index: 8; box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
body.panel-closed #result { left: 50%; }
#result h2 { margin: 0 0 12px; text-align: center; }
#result .podium { display: grid; grid-template-columns: 1fr 1.2fr 1fr; gap: 10px; align-items: end; margin-bottom: 14px; }
#result .pod { text-align: center; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 6px; }
#result .pod.p1 { padding: 18px 6px; border-color: var(--gold); }
#result .pod .place { font-size: 22px; font-weight: 800; color: var(--gold); }
#result .pod .badge { margin: 6px auto; width: 32px; height: 32px; font-size: 16px; }
#result table { width: 100%; border-collapse: collapse; font-size: 13px; }
#result td, #result th { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: left; }
#result th { color: var(--muted); font-weight: 500; }
#result .mine { margin-top: 12px; padding: 10px; border-radius: 10px; background: var(--bg2); }
#result .close { position: absolute; top: 10px; right: 12px; border: 0; background: transparent; font-size: 18px; }
#result .scroll { max-height: 210px; overflow-y: auto; }

/* ---------- 중계 자막 */
#caption { position: fixed; left: calc(50% - var(--panel-w) / 2); bottom: 76px; transform: translateX(-50%); max-width: min(760px, 80vw);
  padding: 8px 16px; border-radius: 10px; background: rgba(5, 10, 18, 0.78); border-left: 3px solid var(--gold);
  font-size: 16px; font-weight: 600; line-height: 1.45; text-align: center; z-index: 5; pointer-events: none;
  opacity: 0; transition: opacity 0.35s; }
#caption.on { opacity: 1; }
body.panel-closed #caption { left: 50%; }

#sound-hint { position: fixed; left: calc(50% - var(--panel-w) / 2); top: 64px; transform: translateX(-50%); z-index: 7;
  padding: 8px 16px; border-radius: 999px; background: var(--gold); color: #1a1300; font-weight: 700; border: 0; }
#sound-hint:hover { background: var(--gold); filter: brightness(1.08); }
body.panel-closed #sound-hint { left: 50%; }

/* ---------- 모달/토스트/로딩 */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.55); display: flex; align-items: center; justify-content: center; z-index: 20; }
.card { width: min(380px, 92vw); background: #0f1622; border: 1px solid var(--line); border-radius: 16px; padding: 22px; }
.card h2 { margin: 0 0 6px; }
.card label { display: block; margin-top: 12px; color: var(--muted); font-size: 13px; }
.card label input { margin-top: 4px; }
.card .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.err { color: var(--red); min-height: 18px; margin-top: 8px; font-size: 13px; }
#toast { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 30; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
#toast div { background: rgba(10,14,22,0.95); border: 1px solid var(--line); padding: 9px 16px; border-radius: 10px; animation: fade 3.5s forwards; }
#toast div.bad { border-color: var(--red); }
#toast div.good { border-color: var(--green); }
@keyframes fade { 0% { opacity: 0; transform: translateY(-6px); } 8%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }
#loading { position: fixed; inset: 0; display: flex; flex-direction: column; gap: 14px; align-items: center; justify-content: center; background: #08101a; z-index: 40; transition: opacity 0.5s; }
#loading.done { opacity: 0; pointer-events: none; }
.spinner { width: 36px; height: 36px; border: 3px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 모바일 */
@media (max-width: 900px) {
  :root { --panel-w: 100vw; }
  #topbar { gap: 8px; padding: 0 8px; font-size: 12px; }
  .logo { font-size: 16px; }
  #userbox button { padding: 5px 8px; white-space: nowrap; }
  #pool { display: none; }
  #panel { top: auto; height: 55vh; border-left: 0; border-top: 1px solid var(--line); }
  body.panel-closed #panel { transform: translateY(100%); }
  #panel-toggle, body.panel-closed #panel-toggle { right: 10px; top: 60px; }
  #cams { transform: translateX(-50%); bottom: calc(55vh + 8px); flex-wrap: nowrap; overflow-x: auto; width: 94vw; }
  #cams button { white-space: nowrap; flex: none; padding: 5px 8px; }
  #phase { white-space: nowrap; padding: 3px 8px; }
  #raceinfo { font-size: 11px; }
  body.panel-closed #cams { bottom: 14px; }
  #horse-card { width: 230px; top: 58px; padding: 8px; transform: scale(0.92); transform-origin: top left; }
  #hud { width: 190px; transform: scale(0.9); transform-origin: top left; }
  #result { left: 50%; }
  #sound-hint { left: 50%; top: 58px; white-space: nowrap; font-size: 12px; }
  #caption { left: 50%; bottom: calc(55vh + 60px); font-size: 13px; max-width: 92vw; }
  body.panel-closed #caption { bottom: 70px; }
}
@media (max-width: 480px) { .logo { display: none; } }
