:root {
  color-scheme: dark;
  --bg: #090b12;
  --panel: #121622;
  --line: #292f42;
  --text: #f2f4fa;
  --muted: #939bb0;
  --primary: #7568ff;
  --green: #42d49b;
  --danger: #f06470;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", sans-serif;
}
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; color: var(--text); background: radial-gradient(circle at 80% -20%, #293260, transparent 42%), var(--bg); }
button, a { font: inherit; }
button { cursor: pointer; }
button:disabled, a.disabled { pointer-events: none; opacity: .42; }

.shell { min-height: 100vh; padding: 20px; }
.topbar { display: flex; align-items: center; justify-content: space-between; max-width: 1540px; margin: 0 auto 16px; }
.brand { display: flex; align-items: center; gap: 11px; }
.brand > span { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 13px; background: linear-gradient(145deg, #5c50e8, #9478ff); box-shadow: 0 12px 34px #7765ff55; font-weight: 900; }
.brand div { display: flex; flex-direction: column; }
.brand small { margin-top: 3px; color: var(--muted); font-size: 9px; letter-spacing: .18em; }
.manager-status, .service-status { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
.manager-status i, .service-status i { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.manager-status.online, .service-status.online { color: var(--green); }
.manager-status.offline, .service-status.error, .service-status.port-conflict { color: var(--danger); }

.workspace { display: grid; grid-template-columns: minmax(260px, 330px) minmax(620px, 1fr); gap: 16px; max-width: 1540px; margin: 0 auto; }
.game-panel, .test-panel { overflow: hidden; border: 1px solid var(--line); border-radius: 18px; background: color-mix(in srgb, var(--panel) 94%, transparent); box-shadow: 0 22px 70px #0005; }
.game-panel { align-self: start; }
.game-list { display: grid; gap: 9px; max-height: min(640px, calc(100vh - 310px)); padding: 12px; overflow: auto; }
.catalog-loading { padding: 28px 14px; color: var(--muted); text-align: center; font-size: 12px; }
.game-entry { display: grid; grid-template-columns: 104px minmax(0, 1fr); width: 100%; min-height: 92px; height: auto; padding: 0; overflow: hidden; border: 1px solid #2f3548; border-radius: 12px; color: inherit; background: #171c29; text-align: left; }
.game-entry:hover, .game-entry:focus-visible { outline: 2px solid #887cff; outline-offset: 1px; background: #7568ff14; }
.game-entry[aria-pressed="true"] { border-color: #887cff; box-shadow: inset 0 0 0 1px #887cff, 0 8px 24px #7568ff2e; }
.cover { display: block; width: 104px; height: 100%; min-height: 92px; object-fit: cover; }
.game-copy { min-width: 0; padding: 11px 12px; }
.local-tag { display: inline-block; padding: 5px 8px; border: 1px solid #42d49b55; border-radius: 999px; color: var(--green); background: #42d49b12; font-size: 10px; font-weight: 850; letter-spacing: .08em; }
.game-copy h1 { margin: 7px 0 5px; overflow: hidden; font-size: 13px; line-height: 1.25; text-overflow: ellipsis; }
.game-copy p { margin: 0; color: var(--muted); font-size: 12px; }
.entry-hint { display: inline-block; margin-top: 7px; color: #bcb5ff; font-size: 10px; }
.identity-grid { display: grid; gap: 1px; margin: 0; background: var(--line); }
.identity-grid div { padding: 13px 20px; background: var(--panel); }
.identity-grid dt { margin-bottom: 4px; color: var(--muted); font-size: 10px; }
.identity-grid dd { margin: 0; font-size: 12px; }
.wide { width: calc(100% - 40px); margin: 18px 20px; }

.test-panel { display: grid; grid-template-rows: 60px 48px 50px minmax(640px, calc(100vh - 288px)) 64px; min-height: 862px; }
.stage-header { display: flex; align-items: center; justify-content: space-between; padding: 0 17px; border-bottom: 1px solid var(--line); }
.stage-header > div { display: flex; flex-direction: column; min-width: 0; }
.stage-header strong { font-size: 14px; }
.stage-header span { margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.stage-actions { display: flex; align-items: center; gap: 11px; }
.fullscreen-button { min-height: 32px; padding: 0 12px; border: 1px solid #887cff; color: #fff; background: linear-gradient(180deg, #887cff, #6556e7); font-size: 11px; font-weight: 850; }
.mode-tabs { display: flex; align-items: center; gap: 8px; padding: 8px 15px; border-bottom: 1px solid var(--line); background: #0f1320; }
.mode-tab { min-width: 86px; height: 31px; border: 1px solid #353c51; border-radius: 8px; color: var(--muted); background: #1a1f2d; font-size: 11px; font-weight: 850; letter-spacing: .08em; }
.mode-tab.active { color: white; border-color: #887cff; background: var(--primary); box-shadow: 0 8px 22px #7568ff4d; }
.launch-switches { display: flex; align-items: center; gap: 16px; padding: 7px 15px; overflow-x: auto; border-bottom: 1px solid var(--line); background: #121725; }
.launch-switch-group { display: inline-flex; flex: 0 0 auto; align-items: center; gap: 6px; }
.launch-switch-group > span { margin-right: 2px; color: var(--muted); font-size: 10px; font-weight: 750; }
.launch-switch-group button { min-height: 30px; padding: 0 10px; border: 1px solid #353c51; border-radius: 7px; color: #aeb5c8; background: #1a1f2d; font-size: 10px; font-weight: 800; }
.launch-switch-group button[aria-pressed="true"] { color: #fff; border-color: #6f9cff; background: #355aa7; box-shadow: 0 5px 15px #244d9f55; }
.stage { position: relative; min-height: 0; overflow: hidden; background: radial-gradient(circle at 50% 16%, #304557, #101a22 48%, #080d12); }
.stage iframe { display: block; width: 100%; height: 100%; border: 0; background: #050608; }
.stage-empty { position: absolute; inset: 0; display: grid; place-items: center; align-content: center; gap: 8px; color: var(--muted); text-align: center; }
.stage-empty strong { color: var(--text); font-size: 19px; }
.stage-empty span { font-size: 12px; }
.controls { display: flex; align-items: center; gap: 9px; padding: 11px 15px; border-top: 1px solid var(--line); background: #0f1320; }
button, .button-link { min-height: 38px; padding: 0 15px; border: 0; border-radius: 9px; text-decoration: none; }
.button-link { display: inline-flex; align-items: center; }
.primary { color: white; background: linear-gradient(180deg, #887cff, #6556e7); }
.secondary { color: #d6daea; background: #252b3b; }
.danger { color: #ffabb2; background: #48232b; }
#admin { margin-left: auto; }

.toast { position: fixed; z-index: 20; left: 50%; bottom: 24px; padding: 11px 16px; border-radius: 10px; color: white; background: #31384c; box-shadow: 0 14px 44px #0008; transform: translateX(-50%); }
.toast.error { background: #a73e49; }
.toast.success { background: #17825e; }
dialog { width: min(820px, calc(100vw - 36px)); padding: 0; border: 1px solid var(--line); border-radius: 14px; color: var(--text); background: #10141e; }
dialog::backdrop { background: #05070bcc; }
dialog header { display: flex; align-items: center; justify-content: space-between; padding: 12px 15px; background: #1b2130; }
dialog pre { min-height: 340px; max-height: 65vh; margin: 0; padding: 16px; overflow: auto; color: #c9cfdd; font: 12px/1.65 ui-monospace, Menlo, monospace; white-space: pre-wrap; }

@media (max-width: 980px) {
  .shell { padding: 12px; }
  .workspace { grid-template-columns: 1fr; }
  .game-list { display: flex; max-height: none; overflow-x: auto; }
  .game-entry { flex: 0 0 310px; }
  .identity-grid, .game-panel .wide { display: none; }
  .test-panel { grid-template-rows: 60px 48px 50px minmax(600px, 72vh) 64px; }
}
