:root {
  --bg: #070b16; --panel: #111a2e; --panel2: #18233d; --line: rgba(125, 170, 230, 0.22);
  --text: #eef3fb; --dim: #9fb0cc; --accent: #38bdf8; --ok: #4ade80; --bad: #f87171; --gold: #facc15;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh; min-height: 100dvh;
  background: radial-gradient(circle at 50% 0%, #15213d 0%, #070b16 60%, #03050a 100%) fixed, var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
  overflow-x: hidden;
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.topbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); max-width: 860px; margin: 0 auto; }
.back-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px;
  background: rgba(56, 189, 248, 0.12); border: 1px solid rgba(56, 189, 248, 0.3); color: #7dd3fc;
  text-decoration: none; font-size: 0.85rem; font-weight: 700; white-space: nowrap;
}
.back-btn:hover { background: rgba(56, 189, 248, 0.24); }
.title { font-size: 1.02rem; margin: 0 auto 0 4px; white-space: nowrap; }
.title span { background: linear-gradient(90deg, #7dd3fc, #c4b5fd); -webkit-background-clip: text; background-clip: text; color: transparent; }
.coins { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.coins.pop { animation: pop 0.5s; }
@keyframes pop { 40% { transform: scale(1.3); color: var(--gold); } }
.mini { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); font-weight: 800; flex: none; }
@media (max-width: 420px) { .back-txt { display: none; } .title { font-size: 0.95rem; } }

.modes { display: flex; gap: 4px; max-width: 860px; margin: 0 auto; padding: 0 12px 8px; }
.mode { flex: 1; padding: 9px 4px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-weight: 700; font-size: 0.86rem; white-space: nowrap; }
.mode.on { background: linear-gradient(135deg, rgba(56,189,248,0.32), rgba(167,139,250,0.22)); border-color: rgba(56,189,248,0.7); }

#app { max-width: 860px; margin: 0 auto; padding: 0 12px 28px; }
.panel h3 { font-size: 0.92rem; margin: 14px 0 6px; color: #cfe0f7; }
.panel h3 small { color: var(--dim); font-weight: 500; margin-left: 6px; }
.lead { color: var(--dim); font-size: 0.88rem; line-height: 1.55; margin: 4px 0 10px; }

.window { position: relative; width: 100%; aspect-ratio: 16 / 10; max-height: 58vh; border-radius: 18px; overflow: hidden; background: #0b1220; box-shadow: 0 18px 50px rgba(0,0,0,0.7), 0 0 0 1px var(--line); touch-action: none; }
@media (max-width: 600px) { .window { aspect-ratio: 4 / 4.2; max-height: 52vh; } }
#win { display: block; width: 100%; height: 100%; cursor: crosshair; }
.hint { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); background: rgba(8,14,28,0.6); padding: 4px 12px; border-radius: 99px; font-size: 0.72rem; color: var(--dim); pointer-events: none; white-space: nowrap; transition: opacity 1s; }
.hint.fade { opacity: 0; }
.focus-over { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; text-shadow: 0 2px 16px rgba(0,0,0,0.8); }
.focus-over b { font-size: clamp(3rem, 14vw, 6rem); font-variant-numeric: tabular-nums; letter-spacing: 0.02em; color: rgba(255,255,255,0.92); }
.focus-over small { font-size: 1rem; color: #cfe0f7; font-weight: 700; }

.bar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.bar.center { justify-content: center; }
.lbl { font-size: 0.85rem; color: var(--dim); font-weight: 700; }
.master { display: inline-flex; align-items: center; gap: 4px; margin-left: auto; font-size: 0.9rem; }
.master input { width: 110px; }
input[type=range] { accent-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  padding: 8px 13px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2);
  font-weight: 700; font-size: 0.88rem; white-space: nowrap; touch-action: manipulation;
}
.btn:hover { border-color: rgba(56,189,248,0.6); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.btn.small { padding: 6px 10px; font-size: 0.82rem; }
.btn.big { padding: 11px 22px; font-size: 1rem; }
.btn.primary { background: linear-gradient(135deg, #0284c7, #6366f1); border-color: transparent; }
.btn.on { background: linear-gradient(135deg, #10b981, #0891b2); border-color: transparent; }

.scenes { display: grid; grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 6px; }
.scene { text-align: left; padding: 8px 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 0.84rem; }
.scene b { display: block; }
.scene small { color: var(--dim); font-size: 0.74rem; }
.scene.on { border-color: var(--accent); background: rgba(56,189,248,0.16); }
.scene.lock { opacity: 0.7; }

.mixer { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 12px; }
.snd { display: flex; flex-direction: column; gap: 2px; padding: 6px 8px; border-radius: 10px; background: var(--panel); border: 1px solid transparent; }
.snd.on { border-color: rgba(56,189,248,0.35); }
.snd label { font-size: 0.8rem; font-weight: 700; color: var(--dim); display: flex; justify-content: space-between; }
.snd.on label { color: var(--text); }
.snd input { width: 100%; }
.slots { display: flex; gap: 6px; flex-wrap: wrap; }
.slot { padding: 6px 10px; border-radius: 10px; border: 1px dashed var(--line); background: transparent; font-size: 0.8rem; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot.full { border-style: solid; background: var(--panel2); }

.courses { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.course { text-align: left; padding: 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); }
.course b { font-size: 1rem; }
.course small { display: block; color: var(--dim); margin-top: 3px; font-size: 0.78rem; line-height: 1.45; }
.course.lock { opacity: 0.55; }
.daily { margin-top: 10px; padding: 12px; border-radius: 14px; border: 1px solid rgba(250,204,21,0.35); background: linear-gradient(135deg, rgba(250,204,21,0.08), rgba(56,189,248,0.06)); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 0.86rem; }
.daily .grow { flex: 1; min-width: 180px; }
.daily small { color: var(--dim); }

.race-top { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 0.88rem; }
.race-top #raceInfo { margin-left: auto; color: var(--dim); font-weight: 700; }
.race-stage { position: relative; margin: 0 auto; width: fit-content; border-radius: 16px; overflow: hidden; box-shadow: 0 0 0 1px var(--line), 0 14px 40px rgba(0,0,0,0.6); touch-action: none; }
#race { display: block; }
.count { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 4rem; font-weight: 900; text-shadow: 0 4px 20px rgba(0,0,0,0.7); pointer-events: none; }
.picks { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }
.pick { width: 42px; height: 42px; border-radius: 50%; border: 3px solid transparent; font-weight: 900; color: #0b1020; font-size: 1rem; }
.pick.on { border-color: #fff; transform: scale(1.12); box-shadow: 0 0 14px rgba(255,255,255,0.5); }

.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; max-width: 460px; margin: 0 auto; }
.seg button { flex: 1; border: 0; background: var(--panel); padding: 9px 6px; font-size: 0.84rem; font-weight: 700; }
.seg button.on { background: rgba(56,189,248,0.3); }
.seg button:disabled { opacity: 0.5; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; margin-top: 12px; }
.card { padding: 10px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
.card small { display: block; color: var(--dim); font-size: 0.74rem; }
.card b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.week { display: flex; gap: 4px; justify-content: space-between; margin-top: 10px; align-items: flex-end; height: 92px; }
.week div { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 3px; height: 100%; font-size: 0.7rem; color: var(--dim); }
.week i { display: block; width: 70%; max-width: 34px; background: linear-gradient(180deg, #38bdf8, #6366f1); border-radius: 6px 6px 2px 2px; min-height: 2px; }

.ach { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; }
.ach div { display: flex; gap: 8px; align-items: center; padding: 8px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); font-size: 0.82rem; opacity: 0.5; }
.ach div.got { opacity: 1; border-color: rgba(250,204,21,0.45); }
.ach .e { font-size: 1.4rem; }
.ach small { display: block; color: var(--dim); font-size: 0.74rem; }

.props { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px; margin-top: 8px; }
.prop { padding: 8px 4px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); font-size: 0.78rem; }
.prop .e { font-size: 1.7rem; display: block; }
.prop.on { border-color: var(--ok); background: rgba(74,222,128,0.14); }
.prop.lock .e { filter: grayscale(1) brightness(0.7); }

.modal { position: fixed; inset: 0; background: rgba(2, 5, 12, 0.72); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 18px; width: 100%; max-width: 460px; max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.6); }
.modal-box h2 { margin: 0 0 8px; font-size: 1.15rem; }
.modal-box p { margin: 6px 0; color: #d4dcea; font-size: 0.9rem; line-height: 1.5; }
.modal-box .row { display: flex; gap: 6px; margin-top: 12px; justify-content: flex-end; flex-wrap: wrap; }
.modal-box ul { padding-left: 18px; margin: 6px 0; font-size: 0.88rem; line-height: 1.6; color: #d4dcea; }
.modal-box input[type=text] { width: 100%; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel2); }
.rank { list-style: none; padding: 0 !important; }
.rank li { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.rank .dot { width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 900; color: #0b1020; font-size: 0.8rem; }
.rank li.me { font-weight: 800; color: #fff; }
.err { font-family: ui-monospace, monospace; font-size: 0.72rem; white-space: pre-wrap; background: #000; padding: 8px; border-radius: 8px; max-height: 160px; overflow: auto; color: #fca5a5; }
.toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); background: rgba(17, 26, 46, 0.97); border: 1px solid rgba(250,204,21,0.5); border-radius: 14px; padding: 10px 16px; font-size: 0.88rem; font-weight: 700; z-index: 60; box-shadow: 0 10px 30px rgba(0,0,0,0.5); max-width: 92vw; text-align: center; }
