:root {
  color-scheme: light;
  --ink: #171717;
  --muted: #5e6674;
  --paper: #f8f6ef;
  --panel: #ffffff;
  --accent: #236d63;
  --road: #575c66;
  --line: #f3d46b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: #f4f4f4;
  font-family: Arial, Helvetica, sans-serif;
  background: #000;
  overflow-x: hidden;
}

.game-shell {
  width: min(1240px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 18px 0 20px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.topbar > div:first-child {
  min-width: 0;
}

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

h1 {
  margin: 0;
  font-size: clamp(28px, 3.4vw, 42px);
  letter-spacing: 0;
}

p {
  margin: 4px 0 0;
  color: #c6cad2;
  font-size: 15px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hud {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  justify-content: flex-end;
  white-space: nowrap;
}

.mode-switch {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 6px;
  border: 1px solid #c9ced7;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.mode-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  position: relative;
  width: 58px;
  height: 26px;
  border-radius: 5px;
  background: linear-gradient(90deg, #236d63 0 50%, #1d66d2 50% 100%);
  border: 2px solid #2c3440;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, .28);
}

.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 25px;
  height: 18px;
  border-radius: 3px;
  background: linear-gradient(#fdfdfd, #cfd4dc);
  border: 1px solid #ffffff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .45);
  transition: transform .16s ease;
}

.mode-switch input:checked + .switch-track {
  background: linear-gradient(90deg, #236d63 0 50%, #1d66d2 50% 100%);
}

.mode-switch input:checked + .switch-track .switch-thumb {
  transform: translateX(27px);
}

label {
  color: #c6cad2;
  font-size: 13px;
  font-weight: 700;
}

select,
button {
  min-height: 38px;
  border: 1px solid #c9ced7;
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
}

select {
  max-width: 300px;
  padding: 0 28px 0 9px;
}

button {
  padding: 0 12px;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

.button-blue {
  background: #1d66d2;
  border-color: #78a6f3;
  color: #fff;
}

.button-green {
  background: #198754;
  border-color: #6fc89e;
  color: #fff;
}

.button-dark {
  background: #2c3440;
  border-color: #697386;
  color: #fff;
}

.mobile-fullscreen {
  display: none;
}

.meter {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  border: 1px solid #d8dce4;
  border-radius: 6px;
  background: rgba(255, 255, 255, .78);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  padding: 0 8px;
  white-space: nowrap;
}

.best-meter {
  background: #f2cc45;
  border-color: #fff1a5;
  color: #171717;
}

.stage-wrap {
  position: relative;
  border: 2px solid #1b1b1b;
  border-radius: 8px;
  overflow: hidden;
  background: var(--paper);
  box-shadow: 0 12px 28px rgba(20, 20, 20, .16);
}

.stage-wrap:fullscreen,
.stage-wrap:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.stage-wrap:fullscreen canvas,
.stage-wrap:-webkit-full-screen canvas {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--paper);
  touch-action: none;
  user-select: none;
}

.hidden {
  display: none !important;
}

.arcade-intro {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 32px;
  background: rgba(0, 0, 0, .72);
}

.arcade-panel {
  width: min(780px, 92%);
  padding: 28px 34px;
  border: 3px solid #f2cc45;
  border-radius: 8px;
  background: linear-gradient(160deg, rgba(18, 21, 29, .97), rgba(30, 43, 50, .97));
  color: #fff;
  text-align: center;
  box-shadow: 0 22px 58px rgba(0, 0, 0, .55);
}

.arcade-panel h2 {
  margin: 0;
  color: #f8df73;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(42px, 6vw, 76px);
  font-style: italic;
  letter-spacing: 0;
  text-shadow: 0 3px 0 #623b12, 0 0 18px rgba(248, 223, 115, .42);
}

.arcade-credit {
  margin: 2px 0 20px;
  color: #dce8ff;
  font-size: clamp(18px, 2.2vw, 26px);
  font-weight: 700;
}

.arcade-copy {
  margin: 0 auto 20px;
  max-width: 690px;
  color: #f5f7fb;
  font-size: clamp(15px, 1.6vw, 18px);
  line-height: 1.45;
}

.arcade-controls {
  display: grid;
  gap: 6px;
  margin: 0 auto 22px;
  max-width: 660px;
  padding: 14px 16px;
  border: 1px solid rgba(242, 204, 69, .55);
  border-radius: 6px;
  background: rgba(255, 255, 255, .08);
  color: #eef2f8;
  font-size: 14px;
  line-height: 1.35;
}

.arcade-controls strong {
  color: #f8df73;
  font-size: 16px;
}

.arcade-controls b {
  color: #f8df73;
}

.arcade-start {
  min-width: 160px;
}

.intro-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.intro-fullscreen {
  display: inline-flex;
}

.rotate-overlay {
  display: none;
}

.rotate-card {
  padding: 22px 26px;
  border: 2px solid #f2cc45;
  border-radius: 8px;
  background: #111;
  color: #fff;
  text-align: center;
  box-shadow: 0 16px 38px rgba(0, 0, 0, .45);
}

.rotate-card strong,
.rotate-card span {
  display: block;
}

.rotate-card strong {
  font-size: 26px;
  margin-bottom: 8px;
}

.rotate-card span {
  color: #d6dae1;
  font-size: 16px;
}

@media (max-width: 720px) {
  .game-shell {
    width: min(100vw - 18px, 1180px);
    padding-top: 10px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .hud {
    justify-content: flex-start;
  }
}

@media (pointer: coarse) and (orientation: landscape) {
  body {
    width: 100vw;
    height: 100vh;
    min-height: 100vh;
    overflow: hidden;
  }

  .game-shell {
    width: 100vw;
    height: 100vh;
    padding: 4px;
    display: flex;
    flex-direction: column;
  }

  .topbar {
    flex: 0 0 auto;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
  }

  .title-row {
    gap: 6px;
  }

  h1 {
    font-size: 18px;
  }

  .mode-switch {
    min-height: 28px;
    gap: 4px;
    padding: 0 4px;
    font-size: 11px;
  }

  .switch-track {
    width: 44px;
    height: 20px;
    border-width: 1px;
  }

  .switch-thumb {
    top: 2px;
    left: 2px;
    width: 19px;
    height: 14px;
  }

  .mode-switch input:checked + .switch-track .switch-thumb {
    transform: translateX(21px);
  }

  .hud {
    gap: 4px;
    min-width: 0;
  }

  label {
    font-size: 11px;
  }

  select,
  button,
  .meter {
    min-height: 28px;
    font-size: 11px;
    border-radius: 5px;
  }

  select {
    max-width: 210px;
    padding-left: 6px;
  }

  button,
  .meter {
    padding: 0 7px;
  }

  .mobile-fullscreen {
    display: inline-flex;
    align-items: center;
  }

  .stage-wrap {
    flex: 1 1 auto;
    min-height: 0;
    border-width: 1px;
    border-radius: 5px;
    box-shadow: none;
  }

  canvas {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
  }

  .arcade-intro {
    padding: 8px;
  }

  .arcade-panel {
    width: min(92vw, 720px);
    max-height: calc(100vh - 18px);
    overflow: auto;
    padding: 10px 14px;
  }

  .arcade-panel h2 {
    font-size: 34px;
  }

  .arcade-credit {
    margin-bottom: 8px;
    font-size: 15px;
  }

  .arcade-copy {
    margin-bottom: 8px;
    font-size: 12px;
    line-height: 1.28;
  }

  .arcade-controls {
    gap: 3px;
    margin-bottom: 8px;
    padding: 8px 10px;
    font-size: 11px;
    line-height: 1.25;
  }

  .intro-actions {
    position: sticky;
    bottom: 0;
    padding-top: 2px;
    background: linear-gradient(180deg, rgba(18, 21, 29, 0), rgba(18, 21, 29, .94) 35%);
  }

  .arcade-start {
    min-height: 30px;
    margin-top: 2px;
    box-shadow: 0 -6px 12px rgba(18, 21, 29, .72);
  }
}

@media (pointer: coarse) and (orientation: landscape) and (max-height: 430px) {
  .arcade-panel {
    width: min(96vw, 760px);
    padding: 8px 12px;
  }

  .arcade-panel h2 {
    font-size: 28px;
  }

  .arcade-credit {
    margin-bottom: 5px;
    font-size: 13px;
  }

  .arcade-copy {
    margin-bottom: 6px;
    font-size: 11px;
    line-height: 1.2;
  }

  .arcade-controls {
    grid-template-columns: 1fr;
    gap: 2px;
    margin-bottom: 6px;
    padding: 6px 8px;
    font-size: 10px;
  }
}

@media (pointer: coarse) and (orientation: portrait) {
  .rotate-overlay {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 24px;
    background: #000;
  }
}
