:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1f2630;
  --text: #e6edf3;
  --muted: #9aa7b4;
  --accent: #2fbf71;
  --border: #2a323c;
  --tab-h: 60px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
body { padding-bottom: env(safe-area-inset-bottom); }

.hidden { display: none !important; }

/* ---------- Screens ---------- */
.screen { display: none; height: calc(100vh - var(--tab-h)); height: calc(100dvh - var(--tab-h)); overflow: hidden; }
.screen.active { display: flex; flex-direction: column; }
.page { padding: 18px; overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; }
.page h2 { margin: 4px 0 6px; }
.muted { color: var(--muted); font-size: 14px; margin-top: 0; }

/* ---------- Play stage ---------- */
.stage { position: relative; flex: 1; background: #000; overflow: hidden; }
#camera { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }

.start-overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 35%, #1b2330, #0a0d12); padding: 20px; z-index: 5;
}
.start-card { max-width: 420px; text-align: center; }
.start-card h1 { font-size: 32px; margin: 0 0 2px; }
.tagline { color: var(--accent); font-size: 15px; letter-spacing: .04em; margin: 0 0 12px; text-transform: lowercase; }
.start-card p { color: var(--muted); margin: 6px 0 14px; }
.field { display: block; text-align: left; margin: 12px 0; }
.field.inline { display: flex; align-items: center; gap: 10px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
select, input[type="number"], input[type="text"] {
  width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font-size: 16px;
}
.field.inline select { width: auto; }

.btn-big {
  width: 100%; padding: 18px; font-size: 22px; font-weight: 700; border: none; border-radius: 14px;
  background: var(--accent); color: #04130a; margin-top: 8px;
}
.btn-big:disabled { opacity: .6; }
.tip { font-size: 12px; margin-top: 14px; }
.error { color: #ff7b72; font-size: 14px; min-height: 18px; }

/* ---------- HUD ---------- */
.hud { position: absolute; top: 0; left: 0; right: 0; padding: 10px 14px; z-index: 4; pointer-events: none; }
.hud-stats {
  display: inline-flex; gap: 16px; align-items: center; background: rgba(0,0,0,.45);
  padding: 8px 14px; border-radius: 999px; font-size: 16px; backdrop-filter: blur(6px);
}
.hud-stats b { color: #fff; }
.beat { width: 12px; height: 12px; border-radius: 50%; background: #3a4452; transition: background .05s, transform .05s; }
.beat.on { background: var(--accent); transform: scale(1.4); }
.hud-hint {
  margin-top: 10px; display: inline-block; background: rgba(0,0,0,.5); color: #e6edf3;
  padding: 8px 14px; border-radius: 12px; font-size: 14px; max-width: 80%;
  backdrop-filter: blur(6px); pointer-events: none;
}

/* ---------- Controls ---------- */
.controls { background: var(--panel); border-top: 1px solid var(--border); padding: 12px 16px; }
.ctrl { display: flex; align-items: center; gap: 12px; }
.ctrl > span { font-size: 14px; min-width: 92px; }
.ctrl input[type="range"] { flex: 1; accent-color: var(--accent); height: 30px; }
.ctrl-row { display: flex; gap: 20px; margin-top: 10px; flex-wrap: wrap; }
.switch { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }

/* ---------- Markers editor ---------- */
.marker-row {
  display: flex; gap: 12px; align-items: flex-start; background: var(--panel);
  border: 1px solid var(--border); border-left: 5px solid #888; border-radius: 12px;
  padding: 12px; margin-bottom: 12px;
}
.marker-art { position: relative; width: 64px; height: 64px; flex: none; background: #fff; border-radius: 8px; padding: 4px; }
.marker-art svg { width: 100%; height: 100%; display: block; }
.marker-letter {
  position: absolute; top: -8px; left: -8px; width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: #04130a; font-weight: 800; font-size: 15px;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 1px 4px rgba(0,0,0,.5);
}
.letter-input { text-transform: uppercase; font-weight: 700; text-align: center; max-width: 70px; }
.mf-line .letter-input { width: 70px; }
.marker-fields { flex: 1; min-width: 0; }
.mf-line { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.mf-line label { font-size: 12px; color: var(--muted); min-width: 58px; }
.mf-hint { font-size: 12px; color: var(--muted); font-style: italic; }
.marker-actions { display: flex; flex-direction: column; gap: 8px; flex: none; }
.btn-mini { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel-2); color: var(--text); font-size: 13px; }
.btn-mini.danger { color: #ff7b72; border-color: #5a2a2a; }

/* ---------- Recordings ---------- */
.recordings-panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; }
.recordings-panel h3 { margin: 0 0 8px; font-size: 16px; }
.rec-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.rec-item { display: flex; align-items: center; gap: 8px; background: var(--panel-2); border-radius: 8px; padding: 8px 10px; }
.rec-name { flex: 1; font-size: 14px; }

.rec-banner {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + 16px);
  z-index: 20; display: flex; align-items: center; gap: 12px;
  background: #b3144f; color: #fff; padding: 12px 18px; border-radius: 999px; font-weight: 600;
  box-shadow: 0 6px 24px rgba(0,0,0,.5);
}
.rec-banner .btn { background: #fff; color: #b3144f; padding: 8px 14px; }
.rec-pulse { width: 14px; height: 14px; border-radius: 50%; background: #fff; animation: recpulse 1s infinite; }
@keyframes recpulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }

.page-actions { display: flex; gap: 10px; margin-top: 6px; flex-wrap: wrap; }
.btn { padding: 12px 18px; border-radius: 10px; border: none; background: var(--accent); color: #04130a; font-size: 15px; font-weight: 600; }
.btn.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }

.help { line-height: 1.6; color: var(--muted); }
.help b { color: var(--text); }
h3 { margin: 18px 0 6px; }

/* ---------- Tabs ---------- */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; height: var(--tab-h);
  display: flex; background: var(--panel); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab { flex: 1; background: none; border: none; color: var(--muted); font-size: 13px; font-weight: 600; }
.tab.active { color: var(--accent); }

/* ---------- Print ---------- */
.print-area { display: flex; flex-wrap: wrap; gap: 16px; padding: 18px; align-content: flex-start; overflow-y: auto; }
.print-card { display: flex; flex-direction: column; align-items: center; gap: 6px; position: relative; padding: 10px; border: 1px dashed #4a5562; border-radius: 8px; }
.print-letter {
  font-size: 28px; font-weight: 800; color: var(--text); line-height: 1;
  width: 40px; height: 40px; border-radius: 50%; border: 2px solid currentColor;
  display: flex; align-items: center; justify-content: center;
}
.print-marker { background: #fff; }
.print-marker svg { width: 100%; height: 100%; display: block; }
.print-label { font-size: 14px; color: var(--text); text-align: center; }
.print-id { color: var(--muted); font-size: 12px; display: block; }

@media print {
  :root { --tab-h: 0px; }
  body { background: #fff; color: #000; }
  .no-print, .tabs, .controls, .screen:not([data-screen="print"]) { display: none !important; }
  .screen[data-screen="print"] { display: block; height: auto; overflow: visible; }
  .print-area { padding: 0; gap: 10mm; overflow: visible; justify-content: flex-start; }
  .print-card { border: 1px dashed #999; padding: 6mm; break-inside: avoid; page-break-inside: avoid; }
  .print-letter { color: #000; border-color: #000; }
  .print-label { color: #000; }
  .print-id { color: #444; }
  @page { margin: 12mm; }
}

/* small visible YouTube window — must be on-screen for browsers to play it */
#yt-host {
  position: fixed; top: calc(env(safe-area-inset-top) + 8px); right: 8px; width: 200px; z-index: 30;
  display: none; background: #000; border-radius: 10px; overflow: hidden; box-shadow: 0 6px 24px rgba(0,0,0,.6);
}
#yt-host.show { display: block; }
#yt-host #yt-player { width: 200px; height: 113px; display: block; }
.yt-bar { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 4px 10px; background: var(--panel); font-size: 12px; color: var(--text); }
#yt-close { background: none; border: none; color: var(--muted); font-size: 16px; padding: 2px 6px; }
@media print { #yt-host { display: none !important; } }
