:root {
  color-scheme: dark;
  --bg: #0d1120;
  --panel: rgba(23, 30, 55, 0.84);
  --text: #f4f7ff;
  --muted: #b7c2de;
  --accent: #65e8ff;
  --accent-soft: rgba(101, 232, 255, .16);
  --line: rgba(255,255,255,.12);
  --shadow: 0 24px 80px rgba(0,0,0,.34);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(101,232,255,.16), transparent 32rem),
    radial-gradient(circle at bottom right, rgba(158,123,255,.17), transparent 30rem),
    var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; font-weight: 800; }
a:hover { text-decoration: underline; }
button, input { font: inherit; }
.shell {
  width: min(1320px, calc(100% - 32px));
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: clamp(12px, 2vw, 24px) 0 calc(92px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 2vw, 20px);
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: clamp(18px, 2vw, 26px);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
.topbar {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(300px, .62fr);
  gap: clamp(12px, 2vw, 20px);
  align-items: stretch;
}
.title-card {
  padding: clamp(18px, 3.4vw, 26px) clamp(22px, 3vw, 28px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.brand-wordmark {
  display: block;
  width: min(100%, 760px);
  max-height: 126px;
  object-fit: contain;
  margin: 0 auto;
  filter: drop-shadow(0 10px 28px rgba(0,0,0,.32));
}
.primary-btn, .footer-install, .install-panel button {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 12px 20px;
  font-weight: 850;
  color: #07101c;
  background: linear-gradient(135deg, var(--accent), #ffffff);
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(101,232,255,.22);
  white-space: nowrap;
}
.controls {
  padding: 16px 18px 18px;
}
.controls h2 {
  margin: 0 0 10px;
  font-size: 1.02rem;
  letter-spacing: .02em;
}
.controls-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.keygrid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.keybox {
  min-height: 64px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  padding: 10px 12px;
  background: rgba(255,255,255,.075);
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 15px;
}
.keybox b, .slider-label { color: var(--accent); }
.keybox span { color: var(--text); font-weight: 750; font-size: .99rem; }
.audio-controls {
  display: grid;
  gap: 8px;
}
.slider-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: rgba(255,255,255,.065);
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 14px;
}
.slider-label {
  font-weight: 800;
  font-size: .96rem;
}
.volume-slider {
  width: 100%;
  appearance: none;
  height: 6px;
  border-radius: 999px;
  background: rgba(255,255,255,.18);
  outline: none;
}
.volume-slider::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #ffffff);
  border: 0;
  box-shadow: 0 4px 16px rgba(101,232,255,.3);
  cursor: pointer;
}
.volume-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #ffffff);
  border: 0;
  box-shadow: 0 4px 16px rgba(101,232,255,.3);
  cursor: pointer;
}
.volume-slider::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(255,255,255,.18);
}
.game-card { padding: clamp(8px, 1.5vw, 14px); overflow: hidden; flex: 1; min-height: 0; position: relative; }
#jsdos {
  width: 100%;
  height: min(72vh, 760px);
  min-height: 420px;
  border-radius: 18px;
  overflow: hidden;
  background: #000;
  outline: 1px solid rgba(255,255,255,.12);
}
.site-footer {
  position: fixed;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 30;
  width: min(720px, calc(100% - 28px));
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 10px;
  color: var(--muted);
  background: rgba(17, 23, 44, .82);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 18px 60px rgba(0,0,0,.35);
  backdrop-filter: blur(14px);
}
.footer-install { padding: 10px 16px; }
.touch-controls {
  position: fixed;
  inset: auto 0 calc(72px + env(safe-area-inset-bottom)) 0;
  z-index: 24;
  display: none;
  justify-content: space-between;
  align-items: end;
  gap: 10px;
  padding: 0 max(12px, env(safe-area-inset-left)) 0 max(12px, env(safe-area-inset-right));
  pointer-events: none;
}
.pad {
  width: clamp(132px, 30vw, 188px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 6px;
  pointer-events: auto;
}
.touch-key {
  touch-action: none;
  user-select: none;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 18px;
  color: var(--text);
  background: rgba(17, 23, 44, .74);
  box-shadow: 0 10px 32px rgba(0,0,0,.28);
  backdrop-filter: blur(10px);
  font-weight: 950;
  font-size: clamp(.95rem, 4vw, 1.35rem);
}
.touch-key:active, .touch-key.is-down { background: var(--accent-soft); border-color: rgba(101,232,255,.72); }
.pad .up { grid-column: 2; grid-row: 1; }
.pad .left { grid-column: 1; grid-row: 2; }
.pad .right { grid-column: 3; grid-row: 2; }
.pad .down { grid-column: 2; grid-row: 3; }
.utility-pad {
  pointer-events: auto;
  display: grid;
  gap: 8px;
  width: min(24vw, 120px);
}
.utility { min-height: 48px; font-size: .95rem; }
.install-help {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0,0,0,.58);
}
.install-help[hidden] { display: none; }
.install-panel {
  width: min(440px, 100%);
  padding: 24px;
  border-radius: 24px;
  background: #171e37;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.install-panel h2 { margin: 0 0 8px; }
.install-panel p { margin: 0 0 16px; color: var(--muted); line-height: 1.45; }

@media (hover: none), (pointer: coarse), (max-width: 900px) {
  .touch-controls { display: flex; }
  .shell { padding-bottom: calc(272px + env(safe-area-inset-bottom)); }
}
@media (max-width: 900px) {
  .topbar { grid-template-columns: 1fr; }
  .title-card { padding: 22px; }
  #jsdos { height: 58vh; min-height: 340px; }
  .controls { display: none; }
}
@media (max-width: 560px) {
  .shell { width: min(100% - 18px, 1320px); padding-top: 10px; }
  .title-card { align-items: center; text-align: center; }
  .brand-wordmark { max-height: 92px; }
  #jsdos { height: 52vh; min-height: 300px; border-radius: 14px; }
  .site-footer { width: calc(100% - 18px); gap: 8px; font-size: .82rem; }
  .footer-install { padding: 9px 12px; }
  .touch-controls { bottom: calc(68px + env(safe-area-inset-bottom)); }
  .pad { width: 36vw; gap: 5px; }
  .utility-pad { width: 22vw; }
  .utility { min-height: 44px; font-size: .92rem; }
}
@media (max-width: 420px) {
  .shell { padding-bottom: calc(286px + env(safe-area-inset-bottom)); }
  .site-footer { min-height: 50px; }
  .touch-controls { bottom: calc(64px + env(safe-area-inset-bottom)); }
  .pad { width: min(22vw, 142px); }
  .utility-pad { width: min(16vw, 90px); }
}
