:root {
  color-scheme: dark;
  --ink: #ecf6ff;
  --muted: #91a3b7;
  --panel: rgba(10, 18, 31, 0.88);
  --line: rgba(169, 210, 255, 0.18);
  --accent: #83e7ff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: radial-gradient(circle at 50% -20%, #263952 0, #0a111e 48%, #05080e 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.game-shell {
  width: min(1100px, calc(100% - 28px)); margin: 0 auto; padding: 28px 0 36px;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
header { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
h1 { margin: 2px 0 0; font-size: clamp(2rem, 6vw, 4.3rem); font-weight: 650; letter-spacing: -.05em; line-height: .9; }
.eyebrow { margin: 0; color: var(--accent); font: 700 .72rem/1.2 ui-monospace, monospace; letter-spacing: .18em; }

button {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 15px; color: var(--ink);
  background: rgba(131, 231, 255, .08); font: inherit; font-weight: 650; cursor: pointer;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: manipulation;
}
button:hover { border-color: rgba(131, 231, 255, .55); background: rgba(131, 231, 255, .14); }
button:active { transform: translateY(1px); }
.header-actions { display: flex; align-items: center; gap: 9px; }
.level-picker { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: .75rem; white-space: nowrap; }
.level-picker select { border: 1px solid var(--line); border-radius: 8px; padding: 9px 28px 9px 9px; color: var(--ink); background: #101b2a; font: 650 .82rem/1 ui-monospace, monospace; cursor: pointer; }
.landscape-button { display: none; }

.instruments { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 10px; }
.instruments div { padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.instruments span { display: block; margin-bottom: 3px; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; }
.instruments strong { font: 600 clamp(1rem, 3vw, 1.35rem)/1.1 ui-monospace, monospace; }

.viewport { position: relative; overflow: hidden; border: 1px solid var(--line); border-radius: 15px; box-shadow: 0 26px 80px rgba(0,0,0,.38); }
canvas { display: block; width: 100%; height: auto; background: #030711; touch-action: none; user-select: none; -webkit-user-select: none; }
.message { position: absolute; inset: 50% auto auto 50%; width: min(88%, 460px); transform: translate(-50%, -50%); padding: 22px; border: 1px solid rgba(131,231,255,.45); border-radius: 14px; background: rgba(3,8,18,.9); text-align: center; backdrop-filter: blur(8px); }
.message strong { display: block; margin-bottom: 6px; color: var(--accent); font-size: 1.7rem; }
.message button { margin-top: 15px; border-color: rgba(131,231,255,.5); }
.hidden { display: none; }

.instructions { display: flex; justify-content: space-between; gap: 20px; color: var(--muted); font-size: .88rem; }
.instructions p:first-child { color: var(--ink); }
kbd { display: inline-block; min-width: 26px; padding: 3px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; text-align: center; color: var(--ink); background: var(--panel); }
.touch-controls {
  display: none; grid-template-columns: 68px 68px 1fr 120px;
  grid-template-areas: "left right gap thrust"; gap: 7px; margin-top: 10px;
}
.touch-controls, .touch-controls * { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.touch-controls button { min-height: 54px; touch-action: none; }
#turnLeft { grid-area: left; }
#turnRight { grid-area: right; }
#thrust { grid-area: thrust; }

@media (max-width: 700px) {
  .game-shell { width: min(100% - 12px, 1100px); padding-top: 10px; }
  header { align-items: center; }
  .header-actions { align-items: stretch; flex-direction: column; }
  .level-picker { justify-content: flex-end; }
  .landscape-button { display: block; }
  .level-picker select { padding-block: 7px; }
  header button { padding: 8px 10px; font-size: .82rem; }
  h1 { font-size: clamp(1.8rem, 11vw, 3rem); }
  .eyebrow { font-size: .58rem; }
  .instruments { grid-template-columns: repeat(3, 1fr); gap: 5px; margin-bottom: 6px; }
  .instruments div { min-width: 0; padding: 6px 7px; border-radius: 8px; }
  .instruments span { margin-bottom: 1px; font-size: .55rem; letter-spacing: .035em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .instruments strong { font-size: clamp(.72rem, 3.7vw, .95rem); white-space: nowrap; }
  .instructions { display: block; }
  .instructions p:last-child { display: none; }
  .touch-controls { display: grid; }
}

@media (orientation: landscape) and (max-height: 560px) {
  html, body { width: 100%; height: 100%; overflow: hidden; }
  body { background: #030711; }
  .game-shell {
    position: relative; width: 100vw; height: 100dvh; margin: 0; padding: 0;
    overflow: hidden;
  }

  header {
    position: absolute; z-index: 8; left: 50%; bottom: max(7px, env(safe-area-inset-bottom));
    transform: translateX(-50%); margin: 0; pointer-events: none;
  }
  header > div:first-child, .level-picker { display: none; }
  .header-actions { display: block; }
  header #restart {
    min-height: 38px; padding: 7px 11px; border-color: rgba(169, 210, 255, .3);
    background: rgba(3, 8, 18, .62); font-size: .68rem; pointer-events: auto;
    backdrop-filter: blur(5px);
  }
  .landscape-button { display: none; }

  .instruments {
    position: absolute; z-index: 7; top: max(5px, env(safe-area-inset-top));
    left: auto; right: max(7px, env(safe-area-inset-right)); width: min(42vw, 420px);
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px;
    margin: 0; pointer-events: none;
  }
  .instruments div {
    min-width: 0; padding: 4px 6px; border-radius: 6px;
    background: rgba(3, 8, 18, .68); backdrop-filter: blur(5px);
  }
  .instruments span {
    margin: 0; font-size: clamp(.42rem, 1.25vw, .56rem); letter-spacing: .02em;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .instruments strong { font-size: clamp(.62rem, 2.1vw, .88rem); white-space: nowrap; }

  .viewport {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    border: 0; border-radius: 0; box-shadow: none; background: #030711;
  }
  canvas { width: auto; height: 100dvh; max-width: 100vw; object-fit: contain; }
  .message { z-index: 9; width: min(58%, 430px); padding: 14px; }
  .message strong { font-size: 1.25rem; }

  .instructions { display: none; }
  .touch-controls {
    position: absolute; z-index: 8; left: max(9px, env(safe-area-inset-left));
    right: max(9px, env(safe-area-inset-right)); bottom: max(7px, env(safe-area-inset-bottom));
    display: grid; grid-template-columns: 76px 76px 1fr 132px;
    grid-template-areas: "left right gap thrust"; gap: 7px; margin: 0;
    pointer-events: none;
  }
  .touch-controls button {
    min-height: 62px; padding: 9px; background: rgba(3, 8, 18, .72);
    border-color: rgba(131, 231, 255, .4); backdrop-filter: blur(5px);
    font-size: 1rem; pointer-events: auto;
  }
  #thrust { font-size: 1.08rem; }
}
