:root {
  color-scheme: dark;
  --bg:        #080a0c;
  --surface:   #0f1318;
  --surface2:  #171d24;
  --surface3:  #1d242e;
  --border:    #1e2730;
  --border2:   #273240;
  --text:      #dce8f2;
  --muted:     #687c8f;
  --accent:    #00d4aa;
  --accent2:   #00b391;
  --warn:      #f5a623;
  --danger:    #ff5f5f;
  --info:      #5ba4e8;
  --h:         48px;      /* header height */
  --radius:    10px;
  --radius-sm: 6px;
  --shadow:    0 8px 32px rgba(0,0,0,.6);
  --glow:      0 0 0 2px rgba(0,212,170,.3);
  --viewport-w: 100vw;
  --app-h:     100dvh;
  --stage-pad: 12px;
  --panel-w:   clamp(320px, 28vw, 420px);
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  height: 100%;
  background: var(--bg);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  width: 100%;
  min-width: 320px;
  height: var(--app-h); overflow: hidden;
  background: var(--bg); color: var(--text);
  font: 13px/1.5 "Inter", system-ui, -apple-system, sans-serif;
  /* v14 */
  display: flex; flex-direction: column;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

app-root {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
}

/* ── Header ──────────────────────────────────────────── */
header {
  display: flex; align-items: center; gap: 8px;
  padding: 0 max(12px, env(safe-area-inset-left)) 0 max(12px, env(safe-area-inset-right));
  height: var(--h); flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  /* subtle glass on supported browsers */
  backdrop-filter: blur(0);
}
.logo {
  display: flex; align-items: center; gap: 7px;
  font-size: 14px; font-weight: 700; letter-spacing: -.2px;
  color: var(--text); flex-shrink: 0;
}
.logo svg { flex-shrink: 0; }
.hbar-sep { width: 1px; height: 18px; background: var(--border2); flex-shrink: 0; }
.hbar-group { display: flex; align-items: center; gap: 5px; min-width: 0; overflow: hidden; }
.hbar-end { margin-left: auto; display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

/* ── Lucide Icons ─────────────────────────────────────── */
/* Base: SVG icons rendered by Lucide inside flex containers */
.lucide {
  display: block;          /* avoid inline baseline gaps */
  width: 14px; height: 14px;
  stroke-width: 2;
  flex-shrink: 0;
  pointer-events: none;
}
/* Standalone icon-only buttons get a slightly larger icon */
button.icon-btn .lucide { width: 15px; height: 15px; }
/* Tabs: compact */
.tab .lucide { width: 13px; height: 13px; stroke-width: 1.9; }
/* Badges: small */
.badge .lucide { width: 12px; height: 12px; stroke-width: 2; }
/* ── Buttons ─────────────────────────────────────────── */

button, label.btn, a.btn, select.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  border: 1px solid var(--border2); background: var(--surface2);
  color: var(--text); border-radius: var(--radius-sm);
  padding: 0 11px; height: 32px; min-width: 32px;
  font: inherit; font-size: 12.5px; line-height: 1;
  text-decoration: none;
  cursor: pointer; white-space: nowrap; outline: none;
  transition: background .12s, border-color .12s, box-shadow .12s, opacity .12s;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}
button:hover, label.btn:hover, a.btn:hover { background: var(--surface3); border-color: var(--border2); }
button:active, label.btn:active, a.btn:active { transform: scale(.97); }
button:focus-visible, label.btn:focus-visible, a.btn:focus-visible, select.btn:focus-visible { box-shadow: var(--glow); border-color: var(--accent); }
button.primary, label.btn.primary, a.btn.primary {
  background: var(--accent); color: #051410;
  border-color: var(--accent2); font-weight: 700; font-size: 13px; padding: 0 16px;
}
button.primary:hover, label.btn.primary:hover, a.btn.primary:hover { background: var(--accent2); border-color: var(--accent2); }
button.secondary {
  background: rgba(255,255,255,.05); border-color: rgba(255,255,255,.13);
  color: var(--text);
}
button.secondary:hover { background: rgba(255,255,255,.09); border-color: rgba(255,255,255,.2); }
button.icon-btn { padding: 0; width: 32px; font-size: 15px; }
button.panel-btn {
  background: transparent; border-color: var(--border2);
  color: var(--muted); font-size: 12px;
}
button.panel-btn:hover { color: var(--text); background: var(--surface2); }
body.panel-open button.panel-btn { color: var(--accent); border-color: rgba(0,212,170,.4); background: rgba(0,212,170,.07); }
.top-official-link {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  height: 32px; min-width: 32px; padding: 0 10px;
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.03);
  color: var(--muted);
  font-size: 11.5px; font-weight: 750;
  line-height: 1; text-decoration: none; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.top-official-link:hover {
  color: var(--accent);
  background: rgba(0,212,170,.07);
  border-color: rgba(0,212,170,.34);
}
.top-official-link .lucide { width: 13px; height: 13px; }
button:disabled, label.btn.disabled, a.btn.disabled, select.btn:disabled { opacity: .35; cursor: not-allowed; pointer-events: none; }
input[type="file"] { display: none; }
select.btn {
  appearance: none; -webkit-appearance: none; padding: 0 26px 0 11px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23687c8f'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center;
}
select.btn option { background: var(--surface2); }

/* ── Badges ──────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; padding: 2px 9px; border-radius: 20px;
  border: 1px solid var(--border2); background: var(--surface2);
  color: var(--muted); white-space: nowrap;
  max-width: 200px; overflow: hidden; text-overflow: ellipsis;
  cursor: default; transition: color .2s, border-color .2s, background .2s;
}
.badge.active { color: var(--accent); border-color: rgba(0,212,170,.35); background: rgba(0,212,170,.07); }
.badge.warn   { color: var(--warn);   border-color: rgba(245,166,35,.35); }
.badge.error  { color: var(--danger); border-color: rgba(255,95,95,.35); }
/* Drive badge */
.drive-badge { cursor: pointer; user-select: none; }
.drive-badge.syncing .lucide { animation: drive-spin 1.4s linear infinite; }
@keyframes drive-spin { to { transform: rotate(360deg); } }
/* hide badges on very small screens */
@media (max-width: 520px) { .badge { display: none; } }

/* ── Main area ───────────────────────────────────────── */
.body-main {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 1fr;
  overflow: hidden;
}
body.panel-open .body-main { grid-template-columns: minmax(0,1fr) var(--panel-w); }

/* ── Stage (canvas area) ─────────────────────────────── */
.stage {
  position: relative; display: flex;
  align-items: center; justify-content: center;
  background: #040506; min-height: 0; overflow: hidden;
  padding: var(--stage-pad);
}
/* Crash player shell: keep the emulator menus out of sight during play. */
body.titans-mode header,
body.titans-mode aside { display: none !important; }
body.titans-mode .body-main { display: block; width: 100%; height: 100%; }
body.titans-mode aside { display: none !important; }
body.titans-mode .stage { width: 100%; height: 100%; padding: 0; background: #090a0b; }
body.titans-mode canvas,
body.titans-mode #idleOverlay {
  width: min(100vw, calc(100dvh * 16 / 9));
  height: min(100dvh, calc(100vw * 9 / 16));
  max-width: 100vw; max-height: 100dvh;
  border: 0; border-radius: 0; box-shadow: none;
}
#titansHud { display: none; }
body.titans-mode #titansHud {
  position: absolute; z-index: 8; top: max(14px, env(safe-area-inset-top)); right: max(14px, env(safe-area-inset-right));
  display: flex; align-items: center; gap: 9px; padding: 7px 9px 7px 15px;
  border: 1px solid rgba(255,255,255,.16); border-radius: 999px;
  background: rgba(8,10,12,.72); color: white; backdrop-filter: blur(10px);
  opacity: .78; transition: opacity .18s ease;
}
body.titans-mode #titansHud:hover,
body.titans-mode #titansHud:focus-within { opacity: 1; }
body.titans-mode #titansHud .icon-btn { background: rgba(255,255,255,.08); color: white; border-color: rgba(255,255,255,.17); }
body.titans-mode .titans-hud-title { font-size: 10px; letter-spacing: .15em; font-weight: 800; }
body.titans-mode #stageMini,
body.titans-mode #fpsBadge { display: none !important; }
canvas {
  display: block;
  width: min(100%, calc((var(--app-h) - var(--h) - (var(--stage-pad) * 2)) * 16 / 9));
  aspect-ratio: 16 / 9;
  max-height: calc(var(--app-h) - var(--h) - (var(--stage-pad) * 2));
  background: #000;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  touch-action: none;
}
:fullscreen,
:-webkit-full-screen {
  background: #000;
}
.stage:fullscreen,
.stage:-webkit-full-screen {
  width: var(--viewport-w) !important;
  height: var(--app-h) !important;
  padding: 0 !important;
  background: #000 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}
body.browser-fullscreen .stage {
  padding: 0;
  background: #000;
}
body.browser-fullscreen #fpsBadge,
body.browser-fullscreen #stageMini {
  display: none !important;
}
.stage:fullscreen canvas,
.stage:-webkit-full-screen canvas,
body.browser-fullscreen canvas,
canvas:fullscreen,
canvas:-webkit-full-screen {
  width: min(var(--viewport-w), calc(var(--app-h) * 16 / 9)) !important;
  height: min(var(--app-h), calc(var(--viewport-w) * 9 / 16)) !important;
  max-width: var(--viewport-w) !important;
  max-height: var(--app-h) !important;
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  object-fit: contain;
  background: #000;
}
body.panel-open canvas {
  width: min(100%, calc((var(--app-h) - var(--h) - (var(--stage-pad) * 2)) * 16 / 9));
}

/* ── Idle welcome screen ─────────────────────────────── */
#idleOverlay {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: min(100%, calc((var(--app-h) - var(--h) - (var(--stage-pad) * 2)) * 16 / 9));
  aspect-ratio: 16 / 9;
  max-height: calc(var(--app-h) - var(--h) - (var(--stage-pad) * 2));
  display: flex; align-items: center; justify-content: center;
  padding: clamp(18px, 4vw, 44px);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--radius-sm);
  overflow: hidden; pointer-events: none;
  background:
    radial-gradient(circle at 24% 22%, rgba(0,212,170,.26), transparent 28%),
    radial-gradient(circle at 78% 74%, rgba(91,164,232,.18), transparent 32%),
    linear-gradient(145deg, #071116 0%, #101923 48%, #050607 100%);
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255,255,255,.025);
  transition: opacity .22s ease, transform .22s ease, visibility .22s;
}
body.titans-mode #idleOverlay {
  padding: clamp(24px, 7vw, 84px);
  border: 0; border-radius: 0;
  background:
    radial-gradient(ellipse at 74% 49%, rgba(226,89,20,.25), transparent 29%),
    radial-gradient(ellipse at 14% 84%, rgba(232,172,39,.16), transparent 30%),
    linear-gradient(110deg, #101315 0%, #171819 51%, #080a0b 100%);
}
body.titans-mode #idleOverlay::after {
  content: ""; position: absolute; inset: 0; opacity: .15; pointer-events: none;
  background: repeating-linear-gradient(120deg, transparent 0 58px, rgba(255,255,255,.08) 59px 60px, transparent 61px 112px);
}
body.titans-mode .idle-content { width: 100%; max-width: 1100px; justify-content: space-between; gap: 40px; }
body.titans-mode .idle-kicker { color: #ef9a32; font-weight: 800; letter-spacing: .2em; font-size: 11px; }
body.titans-mode .idle-title { max-width: 620px; font-size: clamp(36px, 7vw, 82px); line-height: .95; color: #fff; text-wrap: balance; }
body.titans-mode .idle-subtitle { margin-top: 18px; max-width: 450px; color: #c0c2c0; font-size: clamp(14px, 1.7vw, 18px); }
body.titans-mode .idle-actions { margin-top: 27px; pointer-events: auto; }
body.titans-mode .titans-play { min-width: 176px; height: 52px; border: 0; border-radius: 4px; background: #ed7b21; color: #15100b; font-size: 15px; letter-spacing: .08em; }
body.titans-mode .titans-play:hover { background: #ff963d; }
body.titans-mode .titans-import { height: 52px; padding: 0 18px; border-radius: 4px; background: rgba(255,255,255,.07); }
body.titans-mode .titans-prototype { height: 52px; padding: 0 16px; border-radius: 4px; background: rgba(8,13,13,.65); border-color: rgba(255,255,255,.18); color: #d9e8df; letter-spacing: .04em; }
body.titans-mode .titans-prototype:hover { background: rgba(27,55,48,.8); border-color: rgba(107,220,155,.55); color: #fff; }
body.titans-mode .titans-mark { position: relative; transform: rotate(-8deg); color: #f27c22; font-style: italic; font-weight: 1000; line-height: .76; text-align: center; text-shadow: 0 5px 0 #6b2514, 0 10px 24px rgba(0,0,0,.5); font-size: clamp(62px, 12vw, 145px); letter-spacing: -.09em; }
body.titans-mode .titans-mark strong { display: block; margin-top: 12px; color: #fff0bd; font-size: .34em; letter-spacing: .12em; line-height: 1.05; text-shadow: 0 3px #813314; }
body.titans-mode .titans-hint { position: absolute; bottom: max(15px, env(safe-area-inset-bottom)); left: max(20px, env(safe-area-inset-left)); color: rgba(255,255,255,.45); font-size: 10px; letter-spacing: .15em; }
body.emulator-started #idleOverlay {
  opacity: 0; visibility: hidden;
  transform: translate(-50%, -50%) scale(.985);
}
#idleOverlay::before {
  content: ""; position: absolute; inset: -35%;
  background:
    linear-gradient(115deg, transparent 0 42%, rgba(255,255,255,.07) 43% 44%, transparent 45% 100%),
    repeating-linear-gradient(90deg, rgba(255,255,255,.028) 0 1px, transparent 1px 72px);
  transform: rotate(-8deg);
  animation: idleSweep 12s linear infinite;
}
#idleOverlay::after {
  content: ""; position: absolute; inset: 0;
  background:
    linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(circle at center, black, transparent 72%);
  opacity: .55;
}
@keyframes idleSweep { to { transform: rotate(-8deg) translateX(72px); } }
.idle-content {
  position: relative; z-index: 1;
  display: grid; grid-template-columns: minmax(180px, 1fr) minmax(220px, 340px);
  align-items: center; gap: clamp(20px, 5vw, 56px);
  width: min(860px, 100%); pointer-events: none;
}
.idle-copy { max-width: 430px; }
.idle-kicker {
  display: inline-flex; align-items: center; gap: 7px;
  margin-bottom: 12px; color: var(--accent);
  font-size: 11px; font-weight: 800; letter-spacing: .12em;
  text-transform: uppercase;
}
.idle-kicker::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 12px var(--accent);
}
.idle-title {
  font-size: clamp(26px, 4.6vw, 52px);
  line-height: .98; font-weight: 850; letter-spacing: 0;
  color: #f3fbff; text-wrap: balance;
}
.idle-subtitle {
  margin-top: 12px; color: #9bb0bf;
  font-size: clamp(12px, 1.8vw, 15px); line-height: 1.55;
  max-width: 34em;
}
.idle-actions {
  display: grid; grid-template-columns: repeat(2, minmax(132px, 1fr));
  gap: 10px; margin-top: 22px; width: min(100%, 330px);
  pointer-events: auto;
}
.idle-actions .btn, .idle-actions button { height: 40px; border-radius: 10px; font-size: 13px; font-weight: 600; }
.idle-actions .btn { font-weight: 700; }
#idleStartBtn {
  grid-column: 1 / -1;
}
.idle-repo-link {
  background: rgba(255,255,255,.05);
  border-color: rgba(255,255,255,.14);
  color: var(--text);
}
.idle-repo-link:hover {
  background: rgba(255,255,255,.09);
  border-color: rgba(255,255,255,.24);
}
.idle-powered {
  position: absolute; right: clamp(12px, 2.4vw, 22px); bottom: clamp(10px, 2vw, 18px);
  z-index: 2; pointer-events: auto;
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 26px; padding: 0 9px;
  border: 1px solid rgba(0,212,170,.22);
  border-radius: 999px;
  color: rgba(220,232,242,.72); text-decoration: none;
  background: rgba(4,7,10,.42);
  backdrop-filter: blur(8px);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.025);
  font-size: 10.5px; font-weight: 700; white-space: nowrap;
  transition: color .12s, border-color .12s, background .12s, transform .12s;
}
.idle-powered:hover {
  color: var(--text);
  border-color: rgba(0,212,170,.45);
  background: rgba(7,14,17,.7);
}
.idle-powered:active { transform: scale(.98); }
.idle-powered strong {
  color: var(--accent); font-weight: 850;
  letter-spacing: .02em;
}
.idle-powered-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(0,212,170,.8);
  flex-shrink: 0;
}
.idle-psp {
  position: relative; width: min(100%, 320px); aspect-ratio: 1.72;
  justify-self: center; border-radius: 28px;
  background: linear-gradient(145deg, #18232b, #090d11 58%, #151d24);
  border: 1px solid rgba(255,255,255,.09);
  box-shadow: 0 28px 60px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.08);
}
.idle-psp-screen {
  position: absolute; inset: 18% 20%;
  border-radius: 8px; border: 1px solid rgba(0,212,170,.28);
  background:
    linear-gradient(135deg, rgba(0,212,170,.24), rgba(91,164,232,.16)),
    radial-gradient(circle at 50% 50%, rgba(255,255,255,.24), transparent 35%),
    #020405;
  box-shadow: inset 0 0 24px rgba(0,0,0,.8), 0 0 30px rgba(0,212,170,.12);
}
.idle-psp-screen::after {
  content: ""; position: absolute; left: 16%; right: 16%; bottom: 18%;
  height: 3px; border-radius: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: idlePulse 1.9s ease-in-out infinite;
}
.idle-psp-dpad, .idle-psp-buttons, .idle-psp-stick {
  position: absolute; border-radius: 50%;
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.08);
}
.idle-psp-dpad { left: 8%; top: 35%; width: 40px; height: 40px; }
.idle-psp-buttons { right: 8%; top: 33%; width: 48px; height: 48px; }
.idle-psp-stick { left: 13%; bottom: 17%; width: 22px; height: 22px; background: rgba(0,212,170,.18); }
@keyframes idlePulse { 0%,100%{opacity:.45; transform:scaleX(.65)} 50%{opacity:1; transform:scaleX(1)} }

/* ── Loading overlay ─────────────────────────────────── */
#loadOverlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: rgba(4,5,6,.85); backdrop-filter: blur(6px);
  border-radius: var(--radius-sm); pointer-events: none;
  opacity: 0; transition: opacity .25s;
}
#loadOverlay.visible { opacity: 1; pointer-events: all; }
.spinner {
  width: 38px; height: 38px;
  border: 3px solid var(--border2); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.load-label { font-size: 13px; color: var(--muted); text-align: center; max-width: 260px; line-height: 1.5; }
.progress-wrap { width: 200px; height: 3px; background: var(--border2); border-radius: 2px; overflow: hidden; }
#progressBar { height: 100%; width: 0%; background: var(--accent); border-radius: 2px; transition: width .15s ease; }

/* ── Floating badges on stage ────────────────────────── */
#fpsBadge {
  position: absolute; top: 20px; left: 20px;
  background: rgba(0,0,0,.7); backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,.08); color: var(--accent);
  font-size: 11px; font-weight: 700; padding: 3px 8px;
  border-radius: var(--radius-sm); display: none; pointer-events: none;
  letter-spacing: .04em;
}
/* status mini-bar overlaid bottom-left of stage */
#stageMini {
  position: absolute; bottom: 20px; left: 20px;
  display: flex; align-items: center; gap: 6px;
  background: rgba(0,0,0,.65); backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,.07);
  border-radius: var(--radius-sm); padding: 4px 10px;
  font-size: 11px; color: var(--muted); pointer-events: none;
  max-width: calc(100% - 40px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.stage-dot {
  width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0;
  background: var(--muted); transition: background .3s;
}
.stage-dot.ok  { background: var(--accent); box-shadow: 0 0 5px var(--accent); }
.stage-dot.err { background: var(--danger); box-shadow: 0 0 5px var(--danger); }
.stage-dot.run { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }

/* ── Side panel ──────────────────────────────────────── */
aside {
  display: none; /* hidden by default */
  grid-template-rows: auto auto 1fr;
  border-left: 1px solid var(--border); background: var(--surface);
  min-height: 0; overflow: hidden;
}
body.panel-open aside { display: grid; }

.status-bar {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 9px 14px; border-bottom: 1px solid var(--border);
  font-size: 11.5px; color: var(--muted); min-height: 40px; flex-shrink: 0;
}
.status-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--muted);
  flex-shrink: 0; margin-top: 3px; transition: background .3s;
}
.status-dot.ok  { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.status-dot.err { background: var(--danger); box-shadow: 0 0 6px var(--danger); }
.status-dot.run { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
#statusText { flex: 1; line-height: 1.4; }

.panel-tab-select-wrap {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.panel-tab-select {
  width: 100%; height: 34px;
  appearance: none; -webkit-appearance: none;
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255,255,255,.035), rgba(255,255,255,0)),
    var(--surface2);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='7'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23687c8f' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"),
    linear-gradient(180deg, rgba(255,255,255,.035), rgba(255,255,255,0));
  background-repeat: no-repeat, repeat;
  background-position: right 11px center, 0 0;
  padding: 0 34px 0 11px;
  font: inherit; font-size: 12px; font-weight: 700;
  outline: none;
}
.panel-tab-select:focus { border-color: var(--accent); box-shadow: var(--glow); }
.panel-tab-select option { background: var(--surface2); color: var(--text); }
.tabs { display: none; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.tab {
  flex: 1; padding: 7px 0; text-align: center;
  font-size: 11.5px; font-weight: 600; color: var(--muted);
  cursor: pointer; border-bottom: 2px solid transparent;
  transition: color .12s, border-color .12s;
  -webkit-user-select: none; user-select: none;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; min-height: 0; overflow: hidden; flex: 1; }
.tab-panel.active { display: flex; flex-direction: column; }

#logPanel { position: relative; flex: 1; overflow: hidden; min-height: 0; }
#log {
  position: absolute; inset: 0; margin: 0; padding: 10px 12px;
  white-space: pre-wrap; overflow-y: auto; overflow-x: hidden;
  font-family: "JetBrains Mono","Fira Code","Cascadia Code",ui-monospace,monospace;
  font-size: 10.5px; line-height: 1.7; word-break: break-all;
  color: #b8cdd9; scrollbar-width: thin; scrollbar-color: var(--border2) transparent;
}
#log .l-err  { color: #ff6b6b; }
#log .l-warn { color: #f5a623; }
#log .l-ok   { color: #2ed4a0; }
#log .l-info { color: #5ba4e8; }
#log .l-dim  { color: #3e5060; }
#log .l-ts   { color: #2c3e4a; }

.log-toolbar {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-top: 1px solid var(--border);
  background: var(--surface); flex-shrink: 0;
}
.log-toolbar button { padding: 0 8px; height: 26px; font-size: 11px; }
#logFilter {
  flex: 1; background: var(--bg); border: 1px solid var(--border2);
  border-radius: var(--radius-sm); color: var(--text);
  font: 11px/1 inherit; padding: 0 8px; height: 26px; outline: none;
}
#logFilter:focus { border-color: var(--accent); }
#logFilter::placeholder { color: var(--muted); }

#infoPanel {
  padding: 12px 14px; font-size: 11.5px;
  overflow-y: auto; color: var(--muted); flex: 1;
  scrollbar-width: thin; scrollbar-color: var(--border2) transparent;
}
#aboutPanel {
  padding: 12px 14px; font-size: 11.5px;
  overflow-y: auto; color: var(--muted); flex: 1;
  scrollbar-width: thin; scrollbar-color: var(--border2) transparent;
}
#networkPanel {
  padding: 12px 14px; font-size: 11.5px;
  overflow-y: auto; color: var(--muted); flex: 1;
  scrollbar-width: thin; scrollbar-color: var(--border2) transparent;
}
.info-group { margin-bottom: 16px; }
.info-group h3 {
  font-size: 9.5px; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 7px;
  padding-bottom: 4px; border-bottom: 1px solid var(--border);
}
.info-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 3.5px 0; gap: 8px;
}
.info-key { color: var(--muted); flex-shrink: 0; font-size: 11px; }
.info-val { color: var(--text); font-weight: 500; text-align: right; word-break: break-word; font-size: 11px; }
.path-val { font-size: 10px; word-break: break-all; }
.info-val.good { color: var(--accent); }
.info-val.bad  { color: var(--danger); }
.info-val.warn { color: var(--warn); }
.about-hero {
  display: flex; align-items: center; gap: 12px;
  padding: 4px 0 14px; margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.about-mark {
  width: 42px; height: 42px; flex: 0 0 42px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  background: rgba(0,212,170,.1);
  border: 1px solid rgba(0,212,170,.28);
  color: var(--accent); font-weight: 900; font-size: 14px;
  letter-spacing: .04em;
}
.about-title {
  color: var(--text); font-size: 16px; line-height: 1.2;
  font-weight: 850;
}
.about-subtitle {
  margin-top: 3px; color: var(--muted);
  font-size: 11.5px; line-height: 1.4;
}
.about-text {
  color: #a9bac8;
  font-size: 11.5px; line-height: 1.6;
}
.about-text a,
.about-links a {
  color: var(--accent);
  text-decoration: none;
}
.about-text a:hover,
.about-links a:hover { text-decoration: underline; }
.about-links {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 10px;
}
.about-links a {
  display: inline-flex; align-items: center;
  min-height: 28px; padding: 0 9px;
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  background: var(--surface2);
  font-size: 11px; font-weight: 600;
}
/* ── Mobile: panel becomes a bottom drawer ───────────── */
@media (max-width: 700px), (pointer: coarse) and (max-height: 560px), (pointer: coarse) and (max-width: 920px) {
  :root {
    --h: 50px;
    --stage-pad: 0px;
  }

  html,
  body {
    height: var(--app-h);
    min-height: var(--app-h);
    overflow: hidden;
  }

  body {
    position: fixed;
    inset: 0;
    font-size: 13px;
  }

  header {
    display: grid;
    grid-template-columns: 40px minmax(84px, 1fr) 40px 84px;
    gap: 6px;
    padding: 5px max(8px, env(safe-area-inset-right)) 5px max(8px, env(safe-area-inset-left));
    min-height: var(--h);
    height: var(--h);
    background: rgba(12,16,20,.96);
    backdrop-filter: blur(12px);
  }
  .hbar-sep { display: none; }
  .btn-lbl { display: none; }
  .badge { display: none; }
  button, label.btn, a.btn, select.btn {
    height: 40px;
    min-width: 40px;
    padding: 0 10px;
    border-radius: 8px;
    font-size: 13px;
  }
  button.icon-btn { width: 40px; font-size: 17px; }
  button.primary, label.btn.primary, a.btn.primary { padding: 0 13px; }
  .logo {
    grid-column: 1;
    min-width: 38px;
    width: 38px;
    justify-content: center;
    overflow: hidden;
  }
  .logo span { display: none; }
  .logo svg { width: 22px; height: 22px; }
  #launchGroup {
    grid-column: 2;
    justify-self: stretch;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 40px));
    justify-content: start;
    gap: 4px;
    min-width: 0;
    overflow: hidden;
  }
  #fileLabel, #startBtn, #runtimeIsoLabel {
    width: 40px;
    min-width: 40px;
    max-width: 40px;
    padding: 0;
    overflow: hidden;
  }
  /* Show only the Lucide icon inside, hide text label */
  #fileLabel .lucide,
  #startBtn .lucide,
  #runtimeIsoLabel .lucide {
    width: 17px; height: 17px;
    display: block;
    flex-shrink: 0;
  }
  #fileLabel .btn-lbl,
  #startBtn .btn-lbl,
  #runtimeIsoLabel .btn-lbl { display: none; }
  #runtimeIsoLabel[style*="display:none"] { display: none !important; }
  #displayGroup {
    grid-column: 3;
    justify-self: stretch;
    display: grid;
    grid-template-columns: 40px;
    gap: 0;
    overflow: hidden;
  }
  .hbar-end {
    grid-column: 4;
    justify-self: stretch;
    margin-left: 0;
    display: grid;
    grid-template-columns: 40px 40px;
    gap: 4px;
    overflow: hidden;
  }
  .top-official-link {
    width: 40px;
    min-width: 40px;
    max-width: 40px;
    padding: 0;
  }
  .top-official-link span { display: none; }
  .top-official-link .lucide { width: 17px; height: 17px; }
  #fullscreenBtn {
    width: 40px;
    min-width: 40px;
    max-width: 40px;
  }
  #gamepadSelect { display: none; }
  #gamepadSelect option { color: var(--text); }
  .panel-btn {
    width: 40px;
    min-width: 40px;
    padding: 0;
    display: inline-flex;
  }

  .body-main {
    min-height: 0;
    background: #000;
  }
  .stage {
    padding: 0;
    background:
      linear-gradient(180deg, rgba(0,212,170,.06), transparent 22%),
      #000;
  }
  canvas {
    width: min(var(--viewport-w), calc((var(--app-h) - var(--h)) * 16 / 9));
    max-width: var(--viewport-w);
    max-height: calc(var(--app-h) - var(--h));
    border: none;
    border-radius: 0;
    box-shadow: none;
  }
  #idleOverlay {
    width: min(var(--viewport-w), calc((var(--app-h) - var(--h)) * 16 / 9));
    max-height: calc(var(--app-h) - var(--h));
    border: none; border-radius: 0;
    padding: 18px 18px max(54px, env(safe-area-inset-bottom));
  }
  .idle-content { grid-template-columns: 1fr; gap: 18px; }
  .idle-copy { max-width: 520px; }
  .idle-psp { width: min(72vw, 270px); order: -1; }

  .idle-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 16px;
    width: min(100%, 304px);
    max-width: 100%;
  }
  .idle-actions .btn,
  .idle-actions button {
    width: auto;
    min-width: 132px;
    height: 38px;
    border-radius: 9px;
    font-size: 12.5px;
    font-weight: 650;
    letter-spacing: 0;
    justify-content: center;
    gap: 6px;
    padding: 0 13px;
  }
  .idle-actions .btn.primary,
  .idle-actions label.btn.primary,
  .idle-actions a.btn.primary {
    background: var(--accent);
    color: #051410;
    border-color: var(--accent2);
    box-shadow: none;
    font-size: 12.5px;
  }
  .idle-actions .btn.primary:active,
  .idle-actions label.btn.primary:active,
  .idle-actions a.btn.primary:active { transform: scale(.97); }
  .idle-actions button:not(.primary),
  .idle-actions a.btn:not(.primary) {
    background: rgba(255,255,255,.05);
    border: 1px solid rgba(255,255,255,.12);
    color: var(--text);
    backdrop-filter: blur(8px);
  }
  .idle-actions button:not(.primary):active,
  .idle-actions a.btn:not(.primary):active { transform: scale(.97); }
  .idle-actions .lucide { width: 17px; height: 17px; }
  @media (max-width: 380px) {
    .idle-actions {
      width: 100%;
    }
    .idle-actions .btn,
    .idle-actions button {
      min-width: 0;
      padding: 0 9px;
      font-size: 12px;
    }
  }
  .idle-powered {
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
    min-height: 24px; padding: 0 8px;
    font-size: 10px;
    opacity: .82;
  }

  body.panel-open .body-main { grid-template-columns: 1fr; }
  body.panel-open aside {
    position: fixed;
    bottom: 0; left: 0; right: 0; z-index: 200;
    height: min(calc(var(--app-h) * .72), calc(var(--app-h) - 72px));
    max-height: calc(var(--app-h) - env(safe-area-inset-top) - 12px);
    border-left: none;
    border-top: 1px solid var(--border2);
    box-shadow: 0 -12px 40px rgba(0,0,0,.7);
    border-radius: 12px 12px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
    display: flex; flex-direction: column;
    background: rgba(15,19,24,.98);
    backdrop-filter: blur(16px);
    /* override grid to flex for flex-based scroll chain */
    grid-template-rows: none;
    overflow: hidden;
  }
  body.keyboard-open.panel-open aside {
    top: max(8px, env(safe-area-inset-top));
    bottom: auto;
    height: max(1px, calc(var(--visual-h) - env(safe-area-inset-top) - 8px));
    max-height: max(1px, calc(var(--visual-h) - env(safe-area-inset-top) - 8px));
    border-radius: 12px 12px 0 0;
  }
  /* Ensure flex chain allows tab content to scroll in portrait drawer */
  body.panel-open aside .tab-panel { flex: 1; min-height: 0; overflow: hidden; }
  body.panel-open aside .tab-panel.active { display: flex; flex-direction: column; min-height: 0; }
  body.panel-open aside::before {
    content: ''; display: block; width: 36px; height: 4px;
    background: var(--border2); border-radius: 2px;
    margin: 8px auto 4px;
    flex-shrink: 0;
  }

  /* Hide GPU select on tiny screens */
  #gpuSelectWrap { display: none; }
  .hbar-sep.gpu-sep { display: none; }

  #fpsBadge  {
    top: 8px; left: 8px;
    font-size: 10px; padding: 3px 7px;
  }
  #stageMini {
    bottom: max(8px, env(safe-area-inset-bottom));
    left: 8px;
    max-width: calc(100vw - 16px);
    font-size: 10.5px;
    padding: 4px 8px;
  }

  #toast {
    bottom: max(16px, env(safe-area-inset-bottom));
    max-width: calc(100vw - 28px);
    white-space: normal;
    text-align: center;
  }

  .tabs {
    overflow-x: auto;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab {
    flex: 0 0 auto;
    min-width: 72px;
    padding: 9px 8px;
    font-size: 11px;
  }

  .status-bar {
    min-height: 38px;
    padding: 8px 12px;
  }

  #libraryPanel,
  #drivePanel,
  #storagePanel,
  #infoPanel,
  #aboutPanel {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .library-toolbar,
  .saves-toolbar,
  .drive-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    align-items: center;
  }
  #deleteAllSavesBtn { margin-left: 0 !important; }
  .library-toolbar button,
  .library-toolbar label.btn,
  .saves-toolbar button,
  .saves-toolbar label.btn,
  .drive-actions button {
    height: 38px;
    min-width: 0;
    width: 100%;
    padding: 0 8px;
    font-size: 11px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #refreshLibraryBtn::before,
  #libraryImportLabel::before,
  #libraryDownloadUrlBtn::before,
  #refreshSavesBtn::before,
  #exportAllSavesBtn::before,
  #importSaveSlotLabel::before,
  #deleteAllSavesBtn::before {
    content: none;
  }
  #libraryUrlInput {
    grid-column: 1 / -1;
    order: 3;
    height: 38px;
    font-size: 12px;
  }
  #libraryDownloadUrlBtn { order: 4; }
  .library-count {
    grid-column: 1 / -1;
    order: 5;
    margin-left: 0;
    font-size: 10px;
  }
  .library-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }
  .game-card-actions button {
    height: 32px;
    font-size: 11px;
  }
  .save-card,
  .save-state-row,
  .drive-file-row {
    padding-left: 0;
    padding-right: 0;
  }
}

@media (pointer: coarse) and (orientation: landscape) and (max-height: 560px) {
  :root { --h: 44px; }
  header {
    grid-template-columns: 36px minmax(80px, 1fr) 36px 76px;
    height: var(--h);
    min-height: var(--h);
    padding-top: 3px;
    padding-bottom: 3px;
  }
  button, label.btn, a.btn, select.btn,
  button.icon-btn {
    height: 36px;
    min-width: 36px;
  }
  .logo,
  #fileLabel,
  #startBtn,
  #runtimeIsoLabel,
  #fullscreenBtn,
  .top-official-link,
  .panel-btn {
    width: 36px;
    min-width: 36px;
    max-width: 36px;
  }
  #launchGroup {
    grid-template-columns: 36px 36px 36px;
    gap: 4px;
  }
  #displayGroup {
    grid-template-columns: 36px;
  }
  .hbar-end {
    grid-template-columns: 36px 36px;
    gap: 4px;
  }
  body.panel-open aside {
    left: auto;
    top: var(--h);
    width: min(360px, 48vw);
    height: calc(var(--app-h) - var(--h));
    max-height: none;
    border-radius: 0;
    border-top: none;
    border-left: 1px solid var(--border2);
    display: flex; flex-direction: column;
    overflow: hidden;
    grid-template-rows: none;
  }
  body.keyboard-open.panel-open aside {
    top: var(--h);
    bottom: auto;
    height: max(1px, calc(var(--visual-h) - var(--h)));
    max-height: max(1px, calc(var(--visual-h) - var(--h)));
  }
  body.panel-open aside::before { display: none; }
  /* In landscape the aside is flex-column — ensure every child shrinks correctly */
  body.panel-open aside .status-bar {
    min-height: 0; padding: 5px 10px; font-size: 10.5px;
  }
  body.panel-open aside .panel-tab-select-wrap {
    padding: 4px 10px;
  }
  body.panel-open aside .tabs {
    flex-shrink: 0;
  }
  /* tab-panel must fill remaining space and scroll */
  body.panel-open aside .tab-panel.active {
    flex: 1; min-height: 0; overflow: hidden;
  }
  /* Compact toolbar in landscape: single flex row, no 2-col grid */
  body.panel-open aside .library-toolbar,
  body.panel-open aside .saves-toolbar,
  body.panel-open aside .drive-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 6px 10px;
  }
  body.panel-open aside .library-toolbar button,
  body.panel-open aside .library-toolbar label.btn,
  body.panel-open aside .saves-toolbar button,
  body.panel-open aside .saves-toolbar label.btn,
  body.panel-open aside .drive-actions button {
    height: 30px;
    width: auto;
    min-width: 0;
    flex: 0 1 auto;
    padding: 0 8px;
    font-size: 10.5px;
  }
  body.panel-open aside #libraryUrlInput {
    height: 30px;
    flex: 1 1 100px;
    font-size: 10.5px;
  }
}
@media (max-width: 400px) {
  button, label.btn, a.btn { padding: 0 8px; }
  .logo span { font-size: 12px; }
  .library-grid { grid-template-columns: 1fr; }
  .idle-title { font-size: 30px; }
  .idle-subtitle { font-size: 12px; }
}

/* ── Scrollbars ──────────────────────────────────────── */
::-webkit-scrollbar       { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #3a4f60; }

/* ── Toast ───────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(12px);
  background: var(--surface3); border: 1px solid var(--border2);
  color: var(--text); font-size: 12.5px; padding: 8px 18px;
  border-radius: 20px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; z-index: 9999;
  transition: opacity .2s, transform .2s; white-space: nowrap;
}
#toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Storage panel ───────────────────────────────────────────────── */
#storagePanel {
  padding: 12px 14px; font-size: 11.5px;
  overflow-y: auto; flex: 1; color: var(--muted);
  scrollbar-width: thin; scrollbar-color: var(--border2) transparent;
  display: flex; flex-direction: column; gap: 14px;
}
.storage-actions { display: flex; flex-direction: column; gap: 6px; }
.storage-actions button,
.storage-actions label.btn {
  width: 100%; justify-content: flex-start;
  padding: 0 12px; height: 30px; font-size: 11.5px;
}
.toolbar-push { margin-left: auto; }
.panel-section-label {
  padding: 4px 12px 2px;
  margin-top: 2px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.empty-row {
  display: block;
  padding: 8px 12px;
  color: var(--muted);
  font-size: 11px;
}
button.danger { border-color: rgba(255,95,95,.35); color: var(--danger); }
button.danger:hover { background: rgba(255,95,95,.1); border-color: var(--danger); }

/* ── Google Drive panel ─────────────────────────────────────────── */
#drivePanel {
  padding: 12px 14px; font-size: 11.5px;
  overflow-y: auto; flex: 1; color: var(--muted);
  scrollbar-width: thin; scrollbar-color: var(--border2) transparent;
  display: flex; flex-direction: column; gap: 12px;
}
.drive-config {
  display: grid; grid-template-columns: minmax(0, 1fr) 32px 32px;
  gap: 6px; margin-bottom: 8px;
}
#googleClientIdInput {
  min-width: 0; height: 30px;
  background: var(--bg); border: 1px solid var(--border2);
  border-radius: var(--radius-sm); color: var(--text);
  font: 11px/1 inherit; padding: 0 8px; outline: none;
}
#googleClientIdInput:focus { border-color: var(--accent); box-shadow: var(--glow); }
#googleClientIdInput::placeholder { color: var(--muted); }
.drive-config button { height: 30px; padding: 0; }
.drive-actions {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}
.drive-actions button {
  justify-content: flex-start;
  height: 30px; min-width: 0; padding: 0 9px; font-size: 11px;
  overflow: hidden; text-overflow: ellipsis;
}
.drive-help {
  color: #8ea2b2; font-size: 10.5px; line-height: 1.5;
  padding: 8px 10px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: rgba(91,164,232,.055);
}
.drive-activity {
  color: var(--muted); font-size: 10.5px; line-height: 1.45;
  min-height: 30px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  overflow-wrap: anywhere;
}
.drive-activity.ok { color: var(--accent); border-color: rgba(0,212,170,.26); background: rgba(0,212,170,.055); }
.drive-activity.run { color: var(--warn); border-color: rgba(245,166,35,.26); background: rgba(245,166,35,.055); }
.drive-activity.warn { color: var(--warn); border-color: rgba(245,166,35,.26); }
.drive-activity.bad { color: var(--danger); border-color: rgba(255,95,95,.28); background: rgba(255,95,95,.055); }
/* Auto-sync row */
.drive-autosync-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface2); margin-bottom: 4px;
}
.drive-autosync-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--text); cursor: pointer; flex: 1; min-width: 160px;
}
.drive-autosync-label input[type=checkbox] { accent-color: var(--accent); width: 14px; height: 14px; cursor: pointer; }

/* ── Network tab ───────────────────────────────────────────────── */
.network-config { display: flex; flex-direction: column; gap: 8px; }
.network-toggle {
  display: flex; align-items: center; gap: 8px;
  color: var(--text); font-size: 12px;
}
.network-toggle input { accent-color: var(--accent); width: 14px; height: 14px; }
.network-config input {
  width: 100%; height: 30px; min-width: 0;
  background: var(--bg); border: 1px solid var(--border2);
  border-radius: var(--radius-sm); color: var(--text);
  font: 11.5px/1 inherit; padding: 0 9px; outline: none;
}
.network-config input:focus { border-color: var(--accent); box-shadow: var(--glow); }
.network-two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr); gap: 8px; }
.network-actions { display: flex; gap: 8px; }
.network-actions button { flex: 1; height: 30px; font-size: 11px; }
.network-activity {
  margin-top: 12px; color: var(--muted); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 9px; line-height: 1.45;
}
#driveAutoSyncInterval {
  font-size: 11px; padding: 2px 5px; border-radius: 4px;
  border: 1px solid var(--border2); background: var(--surface3); color: var(--text);
}
#driveAutoSyncInterval:disabled { opacity: .4; }
.drive-autosync-status { font-size: 10px; color: var(--muted); white-space: nowrap; }
#driveRemoteList {
  min-height: 80px; overflow-y: auto; border-top: 1px solid var(--border);
}
.drive-empty {
  display: block; padding: 22px 10px; text-align: center;
  color: var(--muted); line-height: 1.7;
}
.drive-section-label {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 0 4px; gap: 8px;
  font-size: 9.5px; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.drive-file-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto 24px;
  align-items: center; gap: 6px;
  padding: 5px 0; border-bottom: 1px solid rgba(30,39,48,.45);
}
.drive-file-row:hover { background: rgba(255,255,255,.025); }
.drive-file-name {
  color: var(--text); overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; font-size: 10.5px;
}
.drive-file-size { color: var(--muted); font-size: 9.5px; white-space: nowrap; }
.drive-file-row button {
  height: 22px; min-width: 22px; width: 22px; padding: 0;
  font-size: 11px; border-color: transparent; background: transparent;
}
.drive-file-row button:hover { background: var(--surface3); border-color: var(--border2); }

@media (max-width: 700px), (pointer: coarse) and (max-height: 560px), (pointer: coarse) and (max-width: 920px) {
  #drivePanel {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .drive-actions button {
    height: 38px;
    width: 100%;
    padding: 0 8px;
    font-size: 11px;
    color: var(--text);
  }
  .drive-file-row {
    padding-left: 0;
    padding-right: 0;
  }
}

/* ── Library tab ────────────────────────────────────────────────── */
#libraryPanel {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 10px 12px 12px;
  scrollbar-width: thin; scrollbar-color: var(--border2) transparent;
}
.library-toolbar {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding-bottom: 10px; position: sticky; top: 0; z-index: 2;
  background: var(--surface);
}
.library-toolbar button, .library-toolbar label.btn {
  height: 28px; font-size: 11px; padding: 0 9px;
}
#libraryUrlInput {
  flex: 1 1 150px; min-width: 0; height: 28px;
  background: var(--bg); border: 1px solid var(--border2);
  border-radius: var(--radius-sm); color: var(--text);
  font: 11px/1 inherit; padding: 0 8px; outline: none;
}
#libraryUrlInput:focus { border-color: var(--accent); box-shadow: var(--glow); }
#libraryUrlInput::placeholder { color: var(--muted); }
.library-count {
  margin-left: 0; color: var(--muted); font-size: 10.5px;
  white-space: nowrap;
}
.library-preload-count {
  margin-left: auto; color: var(--warn); font-size: 10.5px;
  white-space: nowrap;
}
#libraryEmpty {
  padding: 28px 10px; color: var(--muted); font-size: 11.5px;
  text-align: center; line-height: 1.8;
}
.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 10px;
  align-items: start;
}
.game-card {
  min-width: 0; overflow: hidden;
  border: 1px solid var(--border);
  background: #0b0f13;
  border-radius: var(--radius-sm);
  transition: transform .12s, border-color .12s, background .12s;
}
.game-card:hover {
  transform: translateY(-1px);
  border-color: rgba(0,212,170,.45);
  background: var(--surface2);
}
.game-cover {
  position: relative; aspect-ratio: 16 / 9;
  background: linear-gradient(135deg, #202832, #0b0f13 62%, #10352f);
  overflow: hidden;
}
.game-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.game-cover-fallback {
  height: 100%; padding: 12px;
  display: flex; align-items: flex-end;
  color: var(--text); font-size: 15px; line-height: 1.1; font-weight: 800;
  text-transform: uppercase; word-break: break-word;
}
.game-cover-fallback::before {
  content: "PSP"; position: absolute; top: 8px; right: 9px;
  color: rgba(255,255,255,.22); font-size: 10px; font-weight: 800;
  letter-spacing: .12em;
}
.game-card-body { padding: 8px; min-width: 0; }
.game-card-title {
  color: var(--text); font-size: 11.5px; font-weight: 700; line-height: 1.25;
  min-height: 30px; overflow: hidden;
}
.game-card-meta {
  margin-top: 4px; color: var(--muted); font-size: 9.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.game-card-actions { display: flex; gap: 5px; margin-top: 8px; }
.game-card-actions button {
  height: 25px; min-width: 0; padding: 0 8px; font-size: 10.5px;
  flex: 1;
}
.game-card-actions button:disabled {
  opacity: .45; cursor: default; transform: none;
}
.game-card-actions button.icon-only {
  flex: 0 0 28px; width: 28px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
.game-card-actions button.icon-only .lucide { width: 13px; height: 13px; }
.game-card-actions button.preload-toggle.active,
#gameInfoFavoriteBtn.active {
  color: var(--warn);
  border-color: rgba(245,166,35,.45);
  background: rgba(245,166,35,.10);
}
.game-card-actions button.preload-toggle.active .lucide,
#gameInfoFavoriteBtn.active .lucide {
  fill: none;
}
#gameInfoModal {
  position: fixed; inset: 0; z-index: 9998;
  display: none; align-items: center; justify-content: center;
  background: rgba(0,0,0,.62); padding: 18px;
}
#gameInfoModal.visible { display: flex; }
.game-info-dialog {
  width: min(360px, 100%); max-height: min(520px, calc(var(--app-h) - 36px));
  overflow: auto; background: var(--surface);
  border: 1px solid var(--border2); border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.game-info-cover { aspect-ratio: 16 / 9; background: var(--surface2); overflow: hidden; }
.game-info-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.game-info-body { padding: 12px; }
.game-info-title { color: var(--text); font-size: 15px; font-weight: 800; line-height: 1.25; margin-bottom: 10px; }
.game-info-row { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-top: 1px solid var(--border); font-size: 11px; }
.game-info-row span:first-child { color: var(--muted); flex-shrink: 0; }
.game-info-row span:last-child { color: var(--text); min-width: 0; overflow-wrap: anywhere; text-align: right; }
.game-info-actions { display: flex; gap: 6px; padding: 0 12px 12px; }
.game-info-actions button { flex: 1; height: 28px; font-size: 11px; }

/* ── Saves tab ──────────────────────────────────────────────────── */
#savesPanel {
  padding: 0; font-size: 11.5px;
  overflow-y: auto; flex: 1;
  scrollbar-width: thin; scrollbar-color: var(--border2) transparent;
  display: flex; flex-direction: column;
}
.saves-toolbar {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.saves-toolbar button { height: 26px; font-size: 11px; padding: 0 9px; }
.saves-toolbar label.btn { height: 26px; font-size: 11px; padding: 0 9px; }
#savesEmpty { padding: 24px 14px; color: var(--muted); font-size: 11.5px; text-align: center; line-height: 1.8; }
.saves-loading { color: var(--muted); }
#savesList { flex: 1; overflow-y: auto; padding: 8px 0;
  scrollbar-width: thin; scrollbar-color: var(--border2) transparent; }
/* ── Saves: section label ── */
.save-section-label {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px 3px; gap: 8px;
  font-size: 9.5px; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.save-section-label span { display: inline-flex; align-items: center; gap: 5px; }
.save-section-label .lucide { width: 11px; height: 11px; }
.save-section-spaced { margin-top: 6px; }
/* ── Save Data card (one per game slot) ── */
.save-card {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 12px 7px 8px;
  border-bottom: 1px solid rgba(30,39,48,.5);
  transition: background .12s;
}
.save-card:hover { background: var(--surface2); }
.save-card-thumb {
  flex-shrink: 0; width: 72px; height: 40px;
  border-radius: 3px; object-fit: cover; background: #111;
  border: 1px solid var(--border);
}
.save-card-thumb-placeholder {
  flex-shrink: 0; width: 72px; height: 40px;
  border-radius: 3px; background: var(--surface2);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--border2);
}
.save-card-thumb-placeholder .lucide { width: 18px; height: 18px; stroke-width: 1.5; }
.save-card-body { flex: 1; min-width: 0; }
.save-card-name {
  font-size: 11.5px; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.save-card-meta { font-size: 9.5px; color: var(--muted); margin-top: 2px; }
.save-card-files {
  font-size: 9px; color: var(--border2); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.save-card-actions { display: flex; gap: 3px; flex-shrink: 0; }
.save-card-actions button {
  height: 24px; min-width: 24px; width: 24px; padding: 0;
  font-size: 12px; border-color: transparent; background: transparent;
}
.save-card-actions button:hover { background: var(--surface3); border-color: var(--border2); }
.save-card-actions button.del:hover { background: rgba(255,95,95,.12); color: var(--danger); border-color: rgba(255,95,95,.3); }
/* ── Save States row (one per .ppst file) ── */
.save-state-row {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 12px 5px 10px;
  border-bottom: 1px solid rgba(30,39,48,.4);
  transition: background .12s;
}
.save-state-row:hover { background: var(--surface2); }
.save-state-thumb {
  flex-shrink: 0; width: 64px; height: 36px;
  border-radius: 2px; object-fit: cover; background: #111;
  border: 1px solid var(--border);
}
.save-state-body { flex: 1; min-width: 0; }
.save-state-name {
  font-size: 10.5px; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.save-state-meta { font-size: 9px; color: var(--muted); margin-top: 1px; }
.save-state-actions { display: flex; gap: 3px; flex-shrink: 0; }
.save-state-actions button {
  height: 22px; min-width: 22px; width: 22px; padding: 0;
  font-size: 11px; border-color: transparent; background: transparent;
}
.save-state-actions button:hover { background: var(--surface3); border-color: var(--border2); }
.save-state-actions button.del:hover { background: rgba(255,95,95,.12); color: var(--danger); border-color: rgba(255,95,95,.3); }
/* legacy -- keep for safety */
.save-game-group { margin-bottom: 4px; }
.save-game-header { display:none; }
.save-slot { display:none; }
.saves-stats { padding: 6px 12px 4px; font-size: 10.5px; color: var(--muted); flex-shrink: 0; }
/* Drive sync buttons — hidden until Google Drive is connected */
.drive-sync-btn { display: none !important; }
body.drive-connected .drive-sync-btn { display: inline-flex !important; }
.save-card-actions button.drive-sync-btn:hover { background: rgba(0,212,170,.12); border-color: rgba(0,212,170,.4); color: var(--accent); }
.save-state-actions button.drive-sync-btn:hover { background: rgba(0,212,170,.12); border-color: rgba(0,212,170,.4); color: var(--accent); }
.game-card-actions button.icon-only.drive-sync-btn:hover { background: rgba(0,212,170,.12); border-color: rgba(0,212,170,.4); color: var(--accent); }
#opfsFileList { margin-top: 4px; flex: 1; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--border2) transparent; }
.opfs-cat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 12px 3px; gap: 8px;
  font-size: 10px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted);
  border-bottom: 1px solid var(--border); border-top: 1px solid var(--border); margin-top: 4px;
}
.opfs-cat-size { color: var(--info); font-size: 9.5px; }
.opfs-file-row {
  display: grid; grid-template-columns: 1fr auto auto;
  align-items: center; gap: 4px 6px;
  padding: 4px 12px; border-bottom: 1px solid rgba(30,39,48,.4);
  font-size: 10.5px;
}
.opfs-file-row:hover { background: var(--surface2); }
.opfs-file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.opfs-file-size { font-size: 9.5px; color: var(--muted); flex-shrink: 0; }
.opfs-file-actions { display: flex; gap: 3px; }
.opfs-file-actions button {
  height: 20px; min-width: 20px; width: 20px; padding: 0;
  font-size: 11px; border-color: transparent; background: transparent;
}
.opfs-file-actions button:hover { background: var(--surface3); border-color: var(--border2); }
.opfs-file-actions button.del:hover { background: rgba(255,95,95,.12); color: var(--danger); border-color: rgba(255,95,95,.3); }
