:root {
  --sidebar-w: 240px;
  --bg-dark: #0f1117;
  --bg-card: #1a1d27;
  --bg-input: #252833;
  --border: #2d3041;
  --text: #e0e0e8;
  --text-dim: #9296aa;
  --primary: #6366f1;
  --success: #22c55e;
  --danger: #ef4444;
  --accent: #fbbf24;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
body { font-family: Inter, "Segoe UI", system-ui, sans-serif; background: var(--bg-dark); color: var(--text); }
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.admin-body { font-size: 14px; }
#admin-app { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); flex: 0 0 var(--sidebar-w); background: #12141c; border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.sidebar-header { padding: 20px 16px; border-bottom: 1px solid var(--border); }
.sidebar h1 { margin: 0; font-size: 20px; }
.sidebar h1 span { color: var(--primary); }
.server-badge { display: inline-block; margin-top: 10px; padding: 4px 8px; border-radius: 999px; background: #ef444426; color: var(--danger); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.server-badge.online { background: #22c55e26; color: var(--success); }
.client-selector { padding: 14px; border-bottom: 1px solid var(--border); }
.client-selector label { display: block; margin-bottom: 6px; color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }
.client-selector select, .input-field input, .layout-props input, .layout-props select { width: 100%; padding: 8px 10px; color: var(--text); background: var(--bg-input); border: 1px solid var(--border); border-radius: 6px; }
.client-actions { display: flex; gap: 6px; margin-top: 8px; }
.client-actions button { flex: 1; padding: 6px; background: var(--bg-input); border: 1px solid var(--border); border-radius: 6px; color: var(--text); }
.sidebar nav { flex: 1; padding: 12px 8px; }
.nav-item { display: block; padding: 11px 14px; border-radius: 8px; color: var(--text-dim); text-decoration: none; margin-bottom: 3px; }
.nav-item:hover { color: var(--text); background: #ffffff0d; }
.nav-item.active { background: var(--primary); color: #fff; }
.sidebar-footer { display: flex; flex-direction: column; gap: 8px; padding: 16px; border-top: 1px solid var(--border); }
.btn-primary, .btn-secondary, .btn-small { padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border); color: var(--text); background: var(--bg-input); }
.btn-primary { border: 0; background: var(--primary); color: #fff; font-weight: 700; }
.btn-secondary { background: transparent; color: var(--text-dim); }
.btn-small { padding: 7px 12px; font-size: 13px; }
.btn-small.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.admin-main { flex: 1; min-width: 0; padding: 24px 32px; overflow-y: auto; }
.client-banner { padding: 0 0 16px; border-bottom: 1px solid var(--border); margin-bottom: 22px; color: var(--text-dim); }
.client-banner strong { color: var(--primary); margin-left: 8px; font-size: 16px; }
#save-indicator { margin-left: 12px; color: var(--success); font-size: 12px; }
.section { display: none; }
.section.active { display: block; }
.section-header { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 22px; }
.section-header h2 { margin: 0; font-size: 24px; }
.toolbar-row { display: flex; flex-wrap: wrap; gap: 8px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 20px; }
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 20px; }
.card-wide { grid-column: 1 / -1; }
.card h3 { margin: 0 0 16px; color: var(--text-dim); font-size: 13px; text-transform: uppercase; letter-spacing: 1px; }
.color-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.color-field { display: flex; align-items: center; gap: 10px; }
.color-field span, .input-field span, .range-field span { color: var(--text-dim); font-size: 13px; }
.color-field span { flex: 1; }
.color-field input[type="color"] { width: 38px; height: 30px; padding: 0; background: none; border: 2px solid var(--border); border-radius: 6px; }
.range-field, .input-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.range-field input { width: 100%; accent-color: var(--primary); }
.range-field output { align-self: flex-end; color: var(--primary); font-weight: 700; }
.checkbox-field { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; color: var(--text-dim); }
.checkbox-field input { accent-color: var(--primary); }
.skin-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
.skin-field { display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--text-dim); font-size: 13px; text-align: center; }
.skin-preview { width: 82px; height: 82px; border: 2px dashed var(--border); border-radius: 8px; background: var(--bg-input) center / contain no-repeat; }
.skin-preview.has-image { border-style: solid; border-color: var(--primary); }
.skin-field input { width: 100%; font-size: 11px; color: var(--text-dim); }
.skin-field button { padding: 4px 10px; background: transparent; border: 1px solid var(--border); border-radius: 6px; color: var(--text-dim); }
.layout-grid { display: grid; grid-template-columns: 180px minmax(280px, 520px) 280px; gap: 16px; align-items: start; }
.layout-toolbar, .layout-canvas-wrap, .layout-props { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.layout-toolbar { display: flex; flex-direction: column; gap: 8px; }
.layout-add-btn { padding: 9px 10px; text-align: left; color: var(--text); background: var(--bg-input); border: 1px solid var(--border); border-radius: 7px; }
.layout-canvas-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; }
#layout-canvas { width: 100%; max-width: 480px; aspect-ratio: 480 / 900; background: #070912; border-radius: 8px; touch-action: none; }
.layout-stage { position: relative; width: 100%; max-width: 480px; aspect-ratio: 480 / 900; }
.layout-stage canvas { display: block; }
#layout-handles { position: absolute; inset: 0; pointer-events: none; }
.layout-move-handle { position: absolute; width: 28px; height: 28px; padding: 4px; transform: translate(-50%, -50%); display: grid; place-items: center; border: 1px solid #ffffff90; border-radius: 4px; background: #ffffffea; cursor: grab; touch-action: none; pointer-events: auto; }
.layout-move-handle img { width: 18px; height: 18px; pointer-events: none; }
.layout-move-handle:hover, .layout-move-handle:focus-visible, .layout-move-handle.selected { background: #a7f3d0; border-color: #059669; outline: 2px solid #059669; z-index: 2; }
.layout-move-handle:active { cursor: grabbing; }
.hint { color: var(--text-dim); font-size: 11px; text-align: center; }
.layout-props { display: flex; flex-direction: column; gap: 10px; color: var(--text-dim); }
.layout-props-row { display: grid; grid-template-columns: 80px 1fr; gap: 8px; align-items: center; }
.layout-props button { padding: 8px 10px; background: #ef444426; color: var(--danger); border: 1px solid #ef444466; border-radius: 7px; }
.hs-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; border-bottom: 1px solid var(--border); padding-bottom: 16px; margin-bottom: 16px; }
.hs-summary div { display: flex; flex-direction: column; gap: 4px; }
.hs-summary span { color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }
.hs-summary strong { font-size: 22px; }
.hs-table { width: 100%; border-collapse: collapse; }
.hs-table th, .hs-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; }
.hs-table th { color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }
.preview-frame { width: min(420px, 100%); height: 72vh; border: 2px solid var(--border); border-radius: 8px; background: #000; display: block; margin: 0 auto; }
.preview-grid { display: grid; grid-template-columns: minmax(300px, 420px) minmax(260px, 1fr); gap: 20px; align-items: start; }
.live-leaderboard { min-width: 0; }
.live-leaderboard-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.live-leaderboard-header h3 { margin: 0; }
#live-leaderboard-status { color: var(--success); font-size: 11px; white-space: nowrap; }
#live-leaderboard-list { margin: 0; padding: 0; list-style: none; }
#live-leaderboard-list li { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--border); }
#live-leaderboard-list li span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-live-score { display: block !important; color: var(--text-dim); }
.login-overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at 50% 28%, #232844, #07080d 70%); z-index: 20; }
.login-card { width: min(380px, 92vw); padding: 28px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 20px 70px #000b; }
.login-card h2 { margin: 0 0 8px; }
.login-card p { margin: 0 0 20px; color: var(--text-dim); }
.login-card label span { display: block; color: var(--text-dim); margin-bottom: 6px; font-size: 12px; text-transform: uppercase; }
.login-card input { width: 100%; padding: 12px; color: var(--text); background: var(--bg-input); border: 1px solid var(--border); border-radius: 8px; }
.login-card button { width: 100%; padding: 12px; background: var(--primary); color: #fff; border: 0; border-radius: 8px; font-weight: 700; }
.login-error { min-height: 18px; margin: 10px 0; color: var(--danger); font-size: 12px; }
.toast { position: fixed; right: 24px; bottom: 24px; padding: 12px 18px; border-radius: 8px; color: #fff; background: var(--success); font-weight: 700; z-index: 30; }

.live-dashboard-body { overflow: hidden; color: var(--live-text, #fff); background: var(--live-background, #0b1020); }
.live-dashboard { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: clamp(14px, 3vh, 28px); width: min(1180px, 100%); margin: 0 auto; padding: clamp(24px, 4vw, 32px); }
.live-header, .live-board-heading, .live-footer { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.live-brand { display: flex; align-items: center; gap: 20px; min-width: 0; }
.live-logo { width: clamp(56px, 9vw, 110px); max-height: 80px; object-fit: contain; }
.live-kicker { margin: 0 0 6px; color: var(--live-accent, #63e6be); font-size: 12px; font-weight: 800; letter-spacing: 2px; text-transform: uppercase; }
.live-header h1, .live-board h2 { margin: 0; color: var(--live-text, #fff); letter-spacing: 0; }
.live-header h1 { font-size: clamp(30px, 5vw, 64px); line-height: 1; }
.live-subtitle { margin: 8px 0 0; color: var(--live-dim, #a7b0c2); font-size: clamp(13px, 1.5vw, 18px); }
.live-status { display: flex; align-items: center; gap: 9px; color: var(--live-accent, #63e6be); white-space: nowrap; }
.live-status span { width: 10px; height: 10px; border-radius: 50%; background: currentColor; box-shadow: 0 0 14px currentColor; }
.live-status small { color: var(--live-dim, #a7b0c2); font-size: 12px; }
.live-board { min-height: 0; padding: clamp(18px, 3vw, 34px); border: 1px solid color-mix(in srgb, var(--live-accent, #63e6be) 35%, transparent); border-radius: 8px; background: var(--live-surface, rgba(10, 16, 30, .94)); box-shadow: 0 18px 70px #0005; }
.live-board-heading { padding-bottom: 16px; border-bottom: 1px solid #ffffff1c; }
.live-board h2 { font-size: clamp(24px, 3vw, 40px); }
.live-board-heading > strong { color: var(--live-dim, #a7b0c2); font-size: 14px; }
.live-score-list { display: grid; grid-template-rows: repeat(10, minmax(0, 1fr)); height: calc(100% - 86px); min-height: 0; margin: 16px 0 0; padding: 0; list-style: none; }
.live-score-row { display: grid; grid-template-columns: clamp(36px, 5vw, 58px) minmax(0, 1fr) auto; align-items: center; gap: 16px; min-height: 42px; padding: 7px 12px; border-bottom: 1px solid #ffffff14; color: var(--live-dim, #a7b0c2); font-size: clamp(16px, 2vw, 24px); }
.live-score-row.is-first { color: var(--live-text, #fff); background: color-mix(in srgb, var(--live-accent, #63e6be) 13%, transparent); }
.live-rank { color: var(--live-accent, #63e6be); font-weight: 900; font-variant-numeric: tabular-nums; }
.live-team { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-score { color: var(--live-text, #fff); font-variant-numeric: tabular-nums; }
.live-empty { display: grid; place-items: center; height: 100%; color: var(--live-dim, #a7b0c2); }
.live-footer { color: var(--live-dim, #a7b0c2); font-size: 12px; }
@media (max-width: 640px) {
  .live-dashboard { gap: 20px; padding: 22px 14px; }
  .live-header { align-items: flex-start; }
  .live-status { flex-direction: column; align-items: flex-end; gap: 4px; }
  .live-status span { display: none; }
  .live-score-row { gap: 9px; padding-inline: 6px; }
  .live-board-heading > strong { max-width: 110px; overflow: hidden; text-align: right; text-overflow: ellipsis; white-space: nowrap; }
}

.game-body { overflow: hidden; background: #05060a; user-select: none; }
#game-container { position: relative; width: 100%; height: 100vh; height: 100dvh; padding: 8px; display: grid; grid-template-rows: 64px minmax(0, 1fr) 64px; justify-items: center; gap: 8px; background: #05060a; }
#game-viewport { width: 100%; height: 100%; min-height: 0; display: grid; place-items: center; }
#game-stage { position: relative; width: var(--playfield-width); height: var(--playfield-height); container-type: inline-size; }
#pinball-canvas { display: block; max-width: 100%; aspect-ratio: 400 / 750; background: #000; box-shadow: 0 0 0 1px #ffffff22; }
#hud { width: var(--playfield-width, 100%); display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; pointer-events: none; }
#game-logo-preview { width: var(--playfield-width, 100%); height: 100%; display: grid; place-items: center; min-width: 0; }
#game-logo-preview .brand-logo { width: auto; height: auto; max-width: 100%; max-height: 56px; object-fit: contain; }
.score-box, .hud-center { padding: 8px 10px; border: 1px solid #ffffff22; border-radius: 8px; color: #fff; background: rgba(0,0,0,.55); backdrop-filter: blur(8px); }
.score-box { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.score-box span { color: #d7dbe7; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.score-box strong { font-size: 20px; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-center { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 12px; text-transform: uppercase; }
#hud-message, #tilt-warning { position: absolute; left: 50%; top: 105px; transform: translateX(-50%); color: #fff; font-size: 22px; font-weight: 900; text-shadow: 0 2px 18px #000; pointer-events: none; }
#tilt-warning { top: 145px; color: #ff4757; }
.flipper-zone { position: absolute; bottom: 0; width: 46%; height: 42%; }
#left-flipper-zone { left: 0; }
#right-flipper-zone { right: 0; }
#launch-zone { position: absolute; right: 0; bottom: 0; width: 9%; height: 100%; }
.game-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at center, rgba(12,16,30,.6), rgba(0,0,0,.92)); z-index: 10; }
.overlay-content { display: flex; flex-direction: column; align-items: center; gap: 16px; width: 100%; max-height: 100%; padding: 56px 12px 12px; overflow-y: auto; color: #fff; text-align: center; overflow-wrap: anywhere; }
.overlay-content h1 { margin: 0; font-size: 36px; line-height: 1.1; font-weight: 900; letter-spacing: 0; }
.brand-logo { max-width: 160px; max-height: 90px; object-fit: contain; display: none; }
.player-names-card { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; align-items: end; width: 100%; padding: 10px; border: 1px solid #ffffff22; border-radius: 8px; background: rgba(0,0,0,.52); }
.player-names-card label { display: flex; flex-direction: column; gap: 7px; color: #cbd5e1; text-transform: uppercase; font-size: 12px; font-weight: 700; text-align: left; }
.player-names-card strong, .next-team-field strong { display: block; padding: 10px; color: #fff; border: 1px solid #ffffff2e; border-radius: 7px; background: rgba(255,255,255,.08); }
.start-game-button { padding: 10px 18px; color: #111827; background: var(--accent); border: 0; border-radius: 7px; font-weight: 800; }
.next-team-field { display: flex; flex-direction: column; gap: 6px; width: 100%; max-width: 280px; color: #cbd5e1; text-transform: uppercase; font-size: 12px; font-weight: 700; text-align: left; }
.settings-trigger { position: absolute; top: 18px; right: 18px; padding: 8px 12px; color: #fff; background: rgba(255,255,255,.1); border: 1px solid #ffffff2e; border-radius: 8px; }
.settings-card { position: absolute; top: 60px; right: 8px; width: min(280px, calc(100% - 16px)); max-height: calc(100% - 68px); overflow: auto; padding: 10px; background: #161a24; border: 1px solid #ffffff22; border-radius: 8px; color: #fff; }
.settings-card-header, .settings-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.settings-card-header h3 { margin: 0; }
.settings-card button, .settings-card select, .gameover-actions button { padding: 8px 10px; color: #fff; background: #262b39; border: 1px solid #ffffff22; border-radius: 7px; }
.settings-row { margin-top: 12px; color: #cbd5e1; }
.settings-row select { max-width: 150px; }
.gameover-content { gap: 8px; padding: 12px; overflow: hidden; justify-content: center; }
.gameover-content h1 { font-size: 28px; }
.gameover-content h3 { margin: 2px 0 0; font-size: 16px; line-height: 1.1; }
.match-result { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; width: 100%; }
.match-result div { padding: 10px; border: 1px solid #ffffff22; border-radius: 8px; background: rgba(255,255,255,.08); display: flex; flex-direction: column; gap: 4px; }
#winner-banner { color: var(--accent); font-size: 18px; font-weight: 900; }
#highscore-submit-status, #restart-cooldown { min-height: 14px; font-size: 12px; line-height: 1.15; }
#highscore-list { width: 100%; margin: 0; padding-left: 0; list-style: none; }
#highscore-list li { display: grid; grid-template-columns: 32px 1fr auto; gap: 8px; padding: 5px 0; border-bottom: 1px solid #ffffff1a; text-align: left; font-size: 13px; line-height: 1.15; }
.gameover-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
#launch-meter { position: absolute; right: 10px; bottom: 30px; width: 24px; height: min(170px, 40%); border: 1px solid #ffffff44; border-radius: 999px; background: rgba(0,0,0,.55); overflow: hidden; pointer-events: none; }
#launch-meter-fill { position: absolute; left: 0; right: 0; bottom: 0; height: 20%; background: linear-gradient(#ffe16a, #ff5151); }
#launch-meter span { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%) rotate(-90deg); transform-origin: center; width: 130px; color: #fff; font-size: 10px; text-transform: uppercase; }

@media (max-width: 900px) {
  #admin-app { display: block; }
  .sidebar { width: 100%; min-height: auto; }
  .sidebar nav, .sidebar-footer { flex-direction: row; display: flex; flex-wrap: wrap; }
  .nav-item { flex: 1 1 110px; text-align: center; }
  .admin-main { padding: 16px; }
  .layout-grid { grid-template-columns: 1fr; }
  .layout-toolbar { flex-direction: row; flex-wrap: wrap; }
  .layout-add-btn { flex: 1 1 140px; }
  .preview-grid { grid-template-columns: 1fr; }
  .preview-frame { width: min(420px, 100%); }
}
@container (max-width: 300px) {
  .overlay-content h1 { font-size: 24px; }
  .settings-row { flex-wrap: wrap; }
  .settings-row select { max-width: 100%; }
}
@media (max-height: 600px) {
  #game-container { grid-template-rows: 48px minmax(0, 1fr) 36px; gap: 4px; padding: 4px; }
  #game-logo-preview .brand-logo { max-height: 32px; }
  .score-box, .hud-center { padding: 4px; }
  .score-box strong { font-size: 16px; }
  .hud-center { font-size: 10px; }
  .gameover-content { gap: 3px; padding: 4px 6px; }
  .gameover-content h1 { font-size: 18px; }
  .gameover-content h3 { font-size: 13px; }
  .match-result { gap: 4px; }
  .match-result div { padding: 4px; font-size: 11px; }
  #winner-banner { font-size: 13px; }
  #highscore-submit-status, #restart-cooldown { min-height: 10px; font-size: 10px; }
  #highscore-list li { grid-template-columns: 24px 1fr auto; gap: 6px; padding: 1px 0; font-size: 11px; }
  .gameover-actions { gap: 5px; }
  .gameover-actions button { padding: 4px 7px; font-size: 11px; }
}
