:root {
  --bg: #0f1115;
  --panel: #1a1d24;
  --line: #2a2f3a;
  --fg: #e7e9ee;
  --muted: #9aa3b2;
  --accent: #3b82f6;
  --ok: #22c55e;
  --warn: #f59e0b;
  --err: #ef4444;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans CJK SC", sans-serif;
  display: flex; flex-direction: column; min-height: 100%;
  -webkit-user-select: none; user-select: none;
}

.bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; }
.spacer { flex: 1; }
.status { color: var(--muted); font-size: 13px; }
.status.on { color: var(--ok); }
.status.off { color: var(--warn); }

main { flex: 1; display: flex; flex-direction: column; gap: 10px; padding: 10px; }

.stage {
  position: relative; background: #000; border-radius: 10px; overflow: hidden;
  aspect-ratio: 16 / 9; width: 100%; max-height: 70vh;
}
.stage video { width: 100%; height: 100%; display: block; object-fit: contain; background: #000; }
.video-msg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 14px; pointer-events: none;
}
.video-msg.hidden { display: none; }
.sound-gate {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  padding: 10px 16px; border-radius: 999px; border: 0; cursor: pointer;
  background: rgba(0,0,0,.55); color: #fff; font-size: 15px; backdrop-filter: blur(4px);
}
.hidden { display: none !important; }

.pad { display: flex; flex-direction: column; gap: 10px; align-items: center; }

.dpad {
  display: grid; grid-template-columns: repeat(3, 64px); grid-template-rows: repeat(3, 64px);
  gap: 6px;
}
.d {
  border: 1px solid var(--line); background: var(--panel); color: var(--fg);
  border-radius: 10px; font-size: 22px; cursor: pointer; touch-action: none;
}
.d:active, .d.active { background: var(--accent); border-color: var(--accent); }
.up-left { grid-area: 1 / 1; } .up { grid-area: 1 / 2; } .up-right { grid-area: 1 / 3; }
.left { grid-area: 2 / 1; }    .home { grid-area: 2 / 2; font-size: 20px; } .right { grid-area: 2 / 3; }
.down-left { grid-area: 3 / 1; } .down { grid-area: 3 / 2; } .down-right { grid-area: 3 / 3; }

.presets, .toggles { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--fg);
  border-radius: 8px; padding: 9px 12px; cursor: pointer; font-size: 14px;
}
.btn:hover { border-color: var(--accent); }
.btn.wide { min-width: 130px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; width: 100%; }
.btn.ghost { color: var(--muted); }
.btn.on { background: var(--warn); border-color: var(--warn); color: #111; }

select {
  background: var(--panel); color: var(--fg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px;
}

.overlay {
  position: fixed; inset: 0; background: rgba(8,10,14,.85);
  display: flex; align-items: center; justify-content: center; z-index: 20;
}
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 20px; width: min(92vw, 320px); display: flex; flex-direction: column; gap: 12px;
}
.card h2 { margin: 0 0 4px; font-size: 18px; }
.card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.card input {
  background: #0f1115; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px; color: var(--fg); font-size: 15px;
}
.err { color: var(--err); font-size: 13px; min-height: 1em; margin: 0; }

@media (min-width: 720px) {
  main { flex-direction: row; align-items: flex-start; }
  .stage { flex: 1; max-height: 80vh; }
  .pad { width: 280px; }
}
