:root {
  color-scheme: dark;
  --bg: #050812;
  --panel: rgba(14, 20, 34, .82);
  --line: rgba(160, 190, 230, .15);
  --text: #edf4ff;
  --muted: #8e9bb1;
  --accent: #76dcff;
  --danger: #ff7182;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--bg); scroll-behavior: smooth; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 80% 15%, rgba(77, 69, 164, .14), transparent 32rem),
    radial-gradient(circle at 10% 80%, rgba(25, 134, 148, .09), transparent 30rem),
    var(--bg);
}

button, select { font: inherit; }
button { color: inherit; }
button:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
[hidden] { display: none !important; }

.skip-link { position: fixed; top: -4rem; left: 1rem; z-index: 20; padding: .7rem 1rem; color: #00131b; background: #fff; border-radius: .5rem; }
.skip-link:focus { top: 1rem; }

.ambient { position: fixed; inset: 0; pointer-events: none; opacity: .18; background-image: linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px); background-size: 48px 48px; mask-image: linear-gradient(to bottom, black, transparent 82%); }

.site-header { position: relative; z-index: 2; display: flex; align-items: center; justify-content: space-between; width: min(1180px, calc(100% - 2rem)); min-height: 76px; margin: 0 auto; border-bottom: 1px solid var(--line); }
.brand { display: flex; gap: .75rem; align-items: center; color: inherit; text-decoration: none; letter-spacing: .08em; }
.brand-mark { display: grid; width: 38px; height: 38px; place-items: center; border: 1px solid rgba(118, 220, 255, .55); border-radius: 10px; color: #07111c; background: var(--accent); font-weight: 900; box-shadow: 0 0 28px rgba(118, 220, 255, .25); }
.brand strong, .brand small { display: block; }
.brand small { margin-top: .18rem; color: var(--muted); font-size: .66rem; letter-spacing: .16em; }
.header-actions { display: flex; gap: .7rem; align-items: center; }
.record-summary { color: var(--muted); font-size: .82rem; }
.icon-button, .secondary-button, .primary-button { min-height: 42px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; transition: transform .18s ease, border-color .18s ease, background .18s ease; }
.icon-button { width: 42px; background: rgba(255,255,255,.045); }
.secondary-button { padding: .62rem 1rem; color: #c8d4e8; background: rgba(255,255,255,.045); }
.secondary-button.danger { color: #ff9aa7; }
.primary-button { padding: .72rem 1.2rem; border-color: transparent; color: #031019; background: var(--accent); font-weight: 800; }
.icon-button:hover, .secondary-button:hover, .primary-button:hover { transform: translateY(-2px); border-color: rgba(118,220,255,.55); }

.screen { position: relative; z-index: 1; width: min(1180px, calc(100% - 2rem)); margin: 0 auto; }
.menu-screen { padding: clamp(3rem, 8vw, 7rem) 0 4rem; }
.hero-copy { max-width: 760px; }
.eyebrow { margin: 0 0 .7rem; color: var(--accent); font-size: .72rem; font-weight: 800; letter-spacing: .23em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 1rem; font-size: clamp(2.6rem, 7vw, 5.6rem); line-height: .98; letter-spacing: -.055em; }
h2 { font-size: clamp(1.7rem, 4vw, 2.7rem); letter-spacing: -.035em; }
.hero-copy > p:last-child { max-width: 680px; color: var(--muted); font-size: clamp(1rem, 2vw, 1.18rem); line-height: 1.8; }

.game-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-top: 3.2rem; }
.game-card { position: relative; min-height: 235px; overflow: hidden; padding: 1.35rem; text-align: left; border: 1px solid var(--line); border-radius: 18px; color: inherit; background: linear-gradient(145deg, rgba(19,27,45,.92), rgba(9,13,24,.8)); cursor: pointer; isolation: isolate; transition: transform .22s ease, border-color .22s ease; }
.game-card--haunted-mansion { --card-accent: #b66dff; }
.game-card--dark-escape { --card-accent: #76dcff; }
.game-card--ghost-maze { --card-accent: #5ef2d6; }
.game-card--abandoned-hospital { --card-accent: #76ff9b; }
.game-card--pingpong { --card-accent: #ffd166; }
.game-card--survival { --card-accent: #ff9f55; }
.game-card::after { position: absolute; right: -4rem; bottom: -5rem; z-index: -1; width: 11rem; height: 11rem; border-radius: 50%; background: var(--card-accent); opacity: .12; filter: blur(12px); content: ""; }
.game-card:hover { transform: translateY(-5px); border-color: color-mix(in srgb, var(--card-accent), white 15%); }
.card-top { display: flex; justify-content: space-between; align-items: flex-start; }
.game-icon { display: grid; width: 48px; height: 48px; place-items: center; border: 1px solid color-mix(in srgb, var(--card-accent), transparent 35%); border-radius: 13px; color: var(--card-accent); background: color-mix(in srgb, var(--card-accent), transparent 90%); font-size: 1.45rem; font-weight: 900; }
.game-record { color: var(--muted); font-size: .72rem; }
.game-card h2 { margin: 2.2rem 0 .35rem; font-size: 1.45rem; }
.game-card p { margin: 0; color: var(--muted); font-size: .9rem; line-height: 1.55; }
.play-label { display: inline-block; margin-top: 1.1rem; color: var(--card-accent); font-size: .76rem; font-weight: 800; letter-spacing: .1em; }
.keyboard-hint { margin: 1.5rem 0 0; color: #627087; text-align: center; font-size: .78rem; }

.play-screen { padding: 1.7rem 0 3rem; }
.play-heading { display: flex; justify-content: space-between; align-items: end; margin-bottom: 1rem; }
.play-heading h1 { margin: 0; font-size: clamp(1.8rem, 4vw, 3rem); }
.play-actions { display: flex; gap: .6rem; }
.canvas-shell { position: relative; overflow: hidden; border: 1px solid rgba(118, 220, 255, .18); border-radius: 18px; background: #030712; box-shadow: 0 28px 80px rgba(0,0,0,.42); }
canvas { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; }
.canvas-overlay { position: absolute; inset: 0; display: grid; place-content: center; padding: 1.5rem; text-align: center; background: rgba(3,7,18,.84); backdrop-filter: blur(8px); }
.canvas-overlay h2 { margin-bottom: .7rem; }
.canvas-overlay p:not(.eyebrow) { color: var(--muted); }
.result-score { display: block; margin-bottom: 1.4rem; color: #ffd166; font-size: 1.35rem; }
.overlay-actions { display: flex; justify-content: center; gap: .7rem; }

.touch-controls { display: none; justify-content: space-between; align-items: center; max-width: 620px; margin: 1.1rem auto 0; touch-action: none; user-select: none; }
.dpad { display: grid; grid-template: repeat(2, 52px) / repeat(3, 52px); gap: 5px; }
.dpad button:nth-child(1) { grid-column: 2; }
.dpad button:nth-child(2) { grid-column: 1; grid-row: 2; }
.dpad button:nth-child(3) { grid-column: 2; grid-row: 2; }
.dpad button:nth-child(4) { grid-column: 3; grid-row: 2; }
.touch-controls button { border: 1px solid rgba(255,255,255,.16); border-radius: 14px; color: #dce8f8; background: rgba(255,255,255,.07); font-weight: 900; }
.touch-controls button:active { background: rgba(118,220,255,.28); }
.action-pad { display: flex; gap: .8rem; align-items: end; }
.action-pad button { width: 62px; height: 62px; }
.action-pad .primary-action { width: 78px; height: 78px; color: #06101b; background: var(--accent); }

.modal { width: min(480px, calc(100% - 2rem)); padding: 2rem; border: 1px solid rgba(118,220,255,.25); border-radius: 18px; color: var(--text); background: #0d1422; box-shadow: 0 30px 100px #000; }
.modal::backdrop { background: rgba(1,4,12,.78); backdrop-filter: blur(6px); }
.modal-close { position: absolute; top: 1rem; right: 1rem; width: 36px; height: 36px; border: 0; color: var(--muted); background: transparent; cursor: pointer; font-size: 1.5rem; }
.modal > p:not(.eyebrow), .modal li { color: var(--muted); line-height: 1.65; }
.modal ul { padding-left: 1.25rem; margin-bottom: 1.6rem; }
.modal label { display: flex; flex-direction: column; gap: .55rem; margin: 1rem 0; color: #c5d0e2; }
.modal select { width: 100%; padding: .75rem; border: 1px solid var(--line); border-radius: 10px; color: var(--text); background: #131d2d; }
.modal .toggle-row { flex-direction: row; justify-content: space-between; align-items: center; }
.modal input[type="checkbox"] { width: 21px; height: 21px; accent-color: var(--accent); }
.range-row { display: flex; gap: 1rem; align-items: center; }
.range-row input { flex: 1; accent-color: var(--accent); }
.range-row output { min-width: 3rem; color: var(--accent); text-align: right; font-variant-numeric: tabular-nums; }
.modal .primary-button { width: 100%; margin-top: .7rem; }

@media (max-width: 840px) {
  .game-grid { grid-template-columns: repeat(2, 1fr); }
  .touch-controls { display: flex; }
}

@media (max-width: 560px) {
  .record-summary, .keyboard-hint { display: none; }
  .site-header, .screen { width: min(100% - 1rem, 1180px); }
  .menu-screen { padding-top: 3rem; }
  .game-grid { grid-template-columns: 1fr; }
  .game-card { min-height: 205px; }
  .play-heading { align-items: center; }
  .play-heading .eyebrow { display: none; }
  .play-heading h1 { font-size: 1.35rem; }
  .secondary-button { padding: .55rem .7rem; font-size: .82rem; }
  .canvas-shell { margin-inline: -.5rem; border-radius: 0; }
  .dpad { grid-template: repeat(2, 46px) / repeat(3, 46px); }
  .action-pad button { width: 54px; height: 54px; }
  .action-pad .primary-action { width: 68px; height: 68px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

body.reduce-motion *, body.reduce-motion *::before, body.reduce-motion *::after { transition: none !important; animation: none !important; }
