:root {
  --bg: #0b0f17;
  --bg-elev: #131926;
  --bg-card: #182032;
  --border: rgba(148, 174, 212, 0.16);
  --text: #eef3fb;
  --muted: #9aa8be;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --accent: #d99b52;
  --accent-hover: #c5863d;
  --danger: #dc3545;
  --ok: #34d399;
  --radius: 14px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

code {
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
  word-break: break-all;
}

/* ==================== LIBRARY VIEW ==================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 12px calc(16px + env(safe-area-inset-left));
  background: rgba(11, 15, 23, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.container {
  max-width: 1040px;
  margin: 0 auto;
  padding: 18px calc(16px + env(safe-area-inset-right)) calc(36px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.banner-warn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  border-color: rgba(217, 155, 82, 0.45);
  background: linear-gradient(135deg, rgba(217, 155, 82, 0.12), rgba(19, 25, 38, 0.96));
}

.banner-warn p {
  margin: 6px 0 0;
  font-size: 0.88rem;
  line-height: 1.45;
}

.section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.section-head h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
}

.section-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
}

.launch-row {
  display: flex;
  gap: 8px;
}

.text-input, .textarea-input {
  width: 100%;
  background: #0d121d;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 11px 13px;
  font-size: 16px; /* Prevents iOS Safari auto-zoom on focus */
  font-family: inherit;
  outline: none;
}

.text-input:focus, .textarea-input:focus {
  border-color: var(--primary);
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(265px, 1fr));
  gap: 14px;
}

.game-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.14s ease, border-color 0.14s ease;
}

.game-card:hover {
  transform: translateY(-2px);
  border-color: rgba(110, 198, 255, 0.42);
}

.game-cover-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: linear-gradient(135deg, #1b2538, #0f1522);
  overflow: hidden;
}

.game-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.game-cover-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  color: rgba(232, 186, 130, 0.55);
}

.game-badges {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: rgba(11, 15, 23, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.badge-draft { color: #93c5fd; border-color: rgba(147, 197, 253, 0.4); }
.badge-final { color: #fcd34d; border-color: rgba(252, 211, 77, 0.45); }
.badge-info { color: #6ee7b7; border-color: rgba(110, 231, 183, 0.4); }
.badge-cached { color: #6ee7b7; background: rgba(6, 78, 59, 0.82); }

.game-body {
  padding: 13px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.game-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
}

.game-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.game-actions {
  margin-top: auto;
  padding-top: 6px;
  display: flex;
  gap: 8px;
}

.empty-state {
  text-align: center;
  padding: 28px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.shortcut-guide summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.92rem;
}

.guide-body {
  margin-top: 12px;
  font-size: 0.88rem;
  line-height: 1.55;
}

.guide-body ol {
  padding-left: 20px;
}

/* ==================== BUTTONS ==================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 15px;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  color: var(--text);
  background: #232d42;
  transition: background 0.14s ease, opacity 0.14s ease;
  white-space: nowrap;
}

.btn:active { opacity: 0.82; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-accent { background: var(--accent); color: #11151d; }
.btn-accent:hover { background: var(--accent-hover); }
.btn-danger { background: rgba(220, 53, 69, 0.22); border-color: rgba(220, 53, 69, 0.5); color: #fda4af; }
.btn-ghost { background: rgba(255, 255, 255, 0.06); border-color: var(--border); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.12); }
.btn-sm { padding: 7px 11px; font-size: 0.82rem; border-radius: 8px; }
.btn-xs { padding: 4px 9px; font-size: 0.78rem; border-radius: 7px; }
.btn-block { width: 100%; }

/* ==================== PLAYER VIEW ==================== */

.player-view {
  position: fixed;
  inset: 0;
  background: #000;
  overflow: hidden;
  touch-action: manipulation;
}

#canvas, #overlayDiv {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0 none;
}

#canvas {
  background: #000;
}

#presplash {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #070a10;
  pointer-events: none;
}

.visible {
  visibility: visible;
  opacity: 1;
  transition: opacity 0.15s linear;
}

#statusDiv, #inputDiv {
  background: rgba(10, 14, 22, 0.88);
  width: min(560px, 90vw);
  margin: auto;
  padding: 12px 14px;
  position: absolute;
  top: env(safe-area-inset-top);
  left: 0;
  right: 0;
  border-radius: 0 0 10px 10px;
  z-index: 40;
}

#statusTextDiv {
  overflow: auto;
  max-height: 36vh;
  color: #cbd5e1;
  font-size: 13px;
}

#statusProgress {
  display: none;
  width: 100%;
  margin-top: 6px;
}

#inputPrompt {
  color: #f1f5f9;
  font-size: 1rem;
  margin-bottom: 8px;
}

#inputText {
  width: 100%;
  font-size: 16px;
  padding: 8px 10px;
  background: #0b0f17;
  color: #fff;
  border: 1px solid var(--primary);
  border-radius: 8px;
}

.boot-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top, #172033, #070a10 75%);
}

.boot-card {
  width: min(440px, 100%);
  background: rgba(19, 25, 38, 0.94);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 22px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.boot-cover {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 10px;
}

.boot-card h2 {
  margin: 0;
  font-size: 1.2rem;
}

.boot-stage {
  margin: 0;
  font-size: 0.92rem;
  color: #cbd5e1;
}

.progress-track {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.18s ease;
}

.boot-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

.runner-fab {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  left: calc(10px + env(safe-area-inset-left));
  z-index: 50;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(11, 15, 23, 0.62);
  color: #e2e8f0;
  font-size: 1.25rem;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.58);
  display: flex;
}

.runner-drawer {
  width: min(320px, 86vw);
  height: 100%;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(18px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.drawer-head h3 {
  margin: 0;
  font-size: 1.05rem;
}

.drawer-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.drawer-label {
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.drawer-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.drawer-footer {
  margin-top: auto;
  padding-top: 12px;
}

/* ==================== MODALS & TOAST ==================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  width: min(520px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-head h3 {
  margin: 0;
  font-size: 1.05rem;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field-label {
  font-size: 0.84rem;
  font-weight: 600;
  color: #cbd5e1;
  margin-top: 4px;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 6px 0;
}

.cache-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.badge-line {
  margin: 0;
  font-size: 0.85rem;
  color: #93c5fd;
  font-weight: 600;
}

.quote-line {
  margin: 0;
  padding: 8px 10px;
  border-left: 3px solid var(--accent);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 0 8px 8px 0;
  font-size: 0.86rem;
  color: #d6deeb;
}

.pill-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill-btn {
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: #cbd5e1;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.pill-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.toast {
  position: fixed;
  bottom: calc(18px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  max-width: min(460px, 92vw);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(19, 28, 44, 0.95);
  border: 1px solid rgba(110, 231, 183, 0.45);
  color: #e2e8f0;
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

@media (max-width: 560px) {
  .subtitle { display: none; }
  .topbar { padding-left: 12px; padding-right: 12px; }
}
