:root {
  --bg: #0b0e17; --bg2: #121725; --bg3: #1a2133; --line: #262f47; --ink: #e8ecf6; --muted: #8f9ab5;
  --accent: #4fd8ff; --gold: #e9c97c; --ok: #4ade80; --warn: #fbbf24; --bad: #f87171; --r: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; }
a { color: var(--accent); text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; border-radius: 10px; padding: 9px 16px; background: var(--accent); color: #04131b; font-weight: 600; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
button.ghost:hover:not(:disabled) { box-shadow: inset 0 0 0 1px var(--muted); }
button.gold { background: var(--gold); color: #2a1a04; }
button.danger { background: transparent; color: var(--bad); box-shadow: inset 0 0 0 1px #5a2a2a; }
button.small { padding: 6px 11px; font-size: 13px; }
input, textarea, select { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
textarea { resize: vertical; min-height: 64px; line-height: 1.4; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
h1 { font-size: 26px; margin: 0; } h2 { font-size: 19px; margin: 0 0 12px; } h3 { font-size: 15px; margin: 0; }

.top { display: flex; align-items: center; justify-content: space-between; padding: 12px 24px; border-bottom: 1px solid var(--line); background: var(--bg2); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 18px; color: var(--ink); }
.brand small { color: var(--muted); font-weight: 400; font-size: 13px; margin-left: 6px; }
.brand-mark { color: var(--gold); }
.top-right { display: flex; gap: 10px; align-items: center; }
.pill { font-size: 12px; padding: 5px 11px; border-radius: 999px; background: var(--bg3); color: var(--muted); }
.pill.on { color: #052e16; background: var(--ok); }
.pill.off { color: #fff; background: #6b2020; }
main { max-width: 1240px; margin: 0 auto; padding: 24px; }

.login { max-width: 360px; margin: 12vh auto; background: var(--bg2); padding: 28px; border-radius: var(--r); border: 1px solid var(--line); }
.login button { width: 100%; margin-top: 16px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 8px; }

.games { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; margin-top: 18px; }
.game-card { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; cursor: pointer; transition: border-color .15s, transform .15s; }
.game-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.game-card .thumb { height: 120px; border-radius: 10px; background: var(--bg3) center/contain no-repeat; margin-bottom: 12px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 34px; }
.game-card.new { display: flex; align-items: center; justify-content: center; border-style: dashed; color: var(--accent); font-weight: 600; min-height: 200px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }

.game-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.game-head input { font-size: 22px; font-weight: 700; background: transparent; border-color: transparent; padding: 4px 8px; max-width: 520px; }
.game-head input:hover, .game-head input:focus { border-color: var(--line); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tab { padding: 10px 16px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.on { color: var(--ink); border-bottom-color: var(--accent); }
.panel { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; margin-bottom: 18px; }
.help { font-size: 13px; color: var(--muted); line-height: 1.5; margin: 0 0 12px; }

.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
.slot { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.slot .preview { position: relative; height: 170px; border-radius: 10px; display: flex; align-items: center; justify-content: center; overflow: hidden;
  background-color: #0f1320; background-image: linear-gradient(45deg, #161c2c 25%, transparent 25%), linear-gradient(-45deg, #161c2c 25%, transparent 25%),
  linear-gradient(45deg, transparent 75%, #161c2c 75%), linear-gradient(-45deg, transparent 75%, #161c2c 75%);
  background-size: 20px 20px; background-position: 0 0, 0 10px, 10px -10px, -10px 0; }
.slot .preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.slot .preview .orig { color: var(--muted); font-size: 13px; text-align: center; padding: 10px; }
.slot .preview.pair { gap: 6px; }
.slot .preview.pair img { max-width: 48%; }
.slot textarea { min-height: 58px; font-size: 13px; }
.slot .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.status { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--bg3); color: var(--muted); }
.status.queued { color: var(--warn); } .status.running { color: var(--accent); } .status.failed { color: var(--bad); } .status.done { color: var(--ok); }
.status.running::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--accent); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.errline { font-size: 12px; color: var(--bad); word-break: break-word; }

.sounds .sound { display: grid; grid-template-columns: 180px 1fr 90px auto; gap: 10px; align-items: start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.sounds .sound:last-child { border-bottom: 0; }
.sounds audio { width: 100%; height: 34px; margin-top: 6px; }

table.vars { width: 100%; border-collapse: collapse; font-size: 13px; }
table.vars td, table.vars th { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; text-align: left; }
table.vars th { color: var(--muted); font-weight: 500; }
table.vars td.name { font-family: ui-monospace, Menlo, monospace; white-space: nowrap; }
table.vars tr.changed td.name { color: var(--gold); }
table.vars textarea { font-family: ui-monospace, Menlo, monospace; font-size: 12px; min-height: 38px; }
pre.report { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 14px; white-space: pre-wrap; font-size: 12.5px; max-height: 520px; overflow: auto; }
.preview-frame { width: 100%; height: 86vh; border: 1px solid var(--line); border-radius: var(--r); background: #000; }

.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.modal-card { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--r); padding: 22px; width: min(720px, 100%); max-height: 88vh; overflow: auto; }
.tpl-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tpl-pick label { margin: 0; padding: 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; color: var(--ink); }
.tpl-pick input { width: auto; margin-right: 6px; }
.tpl-pick label:has(input:checked) { border-color: var(--accent); background: var(--bg3); }
.history { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.history .h { border: 1px solid var(--line); border-radius: 10px; padding: 6px; font-size: 12px; }
.history .h.active { border-color: var(--ok); }
.history .h img { width: 100%; height: 100px; object-fit: contain; background: #0f1320; border-radius: 6px; cursor: pointer; }
.history .h audio { width: 100%; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(120px); background: var(--bg3); border: 1px solid var(--line); padding: 10px 18px; border-radius: 10px; transition: transform .25s; z-index: 30; }
.toast.show { transform: translateX(-50%) translateY(0); }
@media (max-width: 760px) { .sounds .sound { grid-template-columns: 1fr; } main { padding: 14px; } }
