:root {
  color-scheme: dark;
  --ink: #172a32;
  --paper: #f5e8c8;
  --sky: #78bdc3;
  --orange: #ee6b3b;
  --yellow: #f4c95d;
  --blue: #2d6173;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #13262e;
  color: var(--paper);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  overscroll-behavior: none;
}

body {
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 12%, rgba(244, 201, 93, .2), transparent 34%),
    repeating-linear-gradient(135deg, rgba(255, 255, 255, .018) 0 2px, transparent 2px 7px),
    #13262e;
}

button { font: inherit; }

#flyout-nav { z-index: 1500; }

#game-shell {
  position: relative;
  width: min(calc(100vw - 24px), calc((100vh - 24px) * 16 / 9));
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: var(--sky);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .44), 0 0 0 1px rgba(245, 232, 200, .22);
  outline: none;
}

#game-shell:focus-visible { box-shadow: 0 0 0 4px var(--yellow), 0 24px 70px rgba(0, 0, 0, .44); }

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--sky);
  touch-action: none;
}

#hud {
  position: absolute;
  z-index: 5;
  top: 10px;
  left: 50%;
  display: flex;
  width: min(870px, calc(100% - 82px));
  align-items: stretch;
  justify-content: center;
  gap: 7px;
  transform: translateX(-50%);
  pointer-events: none;
}

.hud-card {
  min-width: 70px;
  padding: 7px 8px 6px;
  border: 2px solid var(--ink);
  border-radius: 9px 9px 13px 9px;
  background: rgba(245, 232, 200, .92);
  color: var(--ink);
  box-shadow: 3px 3px 0 rgba(23, 42, 50, .72);
  text-align: center;
  transform: rotate(-.5deg);
}

.hud-card:nth-child(even) { transform: rotate(.6deg); }
.hud-card.wide { min-width: 112px; }
.hud-label { display: block; font-size: .57rem; font-weight: 900; letter-spacing: .13em; text-transform: uppercase; }
.hud-card strong { display: block; margin-top: 1px; font-family: Consolas, monospace; font-size: .98rem; line-height: 1; }
#health { color: #c84630; }
#strikes { color: #c84630; letter-spacing: .08em; }
#customer-card { background: #d9ead5; }
#customer-card.at-risk { background: #ffb8a0; }
#customer-status { position: absolute; bottom: 10px; left: 12px; padding: 5px 9px; border-radius: 4px; background: #172a32dd; color: #fff8e7; font: 800 11px/1.2 Consolas, monospace; pointer-events: none; }
#traffic-warning { position: absolute; z-index: 6; right: 12px; bottom: 40px; padding: 6px 9px; border: 2px solid var(--ink); border-radius: 5px; background: var(--yellow); color: var(--ink); font: 900 12px/1.2 Consolas, monospace; pointer-events: none; }
#traffic-warning[hidden] { display: none; }

#route-meter {
  position: absolute;
  z-index: 5;
  top: 67px;
  left: 50%;
  width: min(500px, 52%);
  height: 7px;
  overflow: hidden;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: rgba(245, 232, 200, .8);
  transform: translateX(-50%);
  pointer-events: none;
}

#route-fill { display: block; width: 100%; height: 100%; background: linear-gradient(90deg, var(--orange), var(--yellow)); transform-origin: left; }

#sound-status {
  position: absolute;
  z-index: 5;
  right: 11px;
  bottom: 9px;
  padding: 4px 7px;
  border: 1px solid rgba(23, 42, 50, .56);
  border-radius: 5px;
  background: rgba(245, 232, 200, .72);
  color: var(--ink);
  font: 900 .55rem/1 Consolas, monospace;
  letter-spacing: .08em;
  pointer-events: none;
}

#attempt-action {
  position: absolute;
  z-index: 12;
  left: 50%;
  bottom: 104px;
  min-width: 190px;
  min-height: 48px;
  padding: 10px 20px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: var(--orange);
  color: #fffbea;
  box-shadow: 0 5px 0 var(--ink);
  font-weight: 1000;
  letter-spacing: .08em;
  text-transform: uppercase;
  transform: translateX(-50%);
  cursor: pointer;
}

#attempt-action:hover { background: #f47a4c; }
#attempt-action:active { transform: translate(-50%, 3px); box-shadow: 0 2px 0 var(--ink); }
#attempt-action:focus-visible { outline: 4px solid var(--yellow); outline-offset: 3px; }
#attempt-action[hidden] { display: none; }

#help-button {
  position: fixed;
  z-index: 1400;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  display: none;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 2px solid rgba(245, 232, 200, .7);
  border-radius: 50%;
  background: rgba(23, 42, 50, .62);
  color: #fff5d8;
  box-shadow: 0 7px 20px rgba(0, 0, 0, .26);
  font-size: 1.18rem;
  font-weight: 1000;
  cursor: pointer;
  backdrop-filter: blur(7px);
}

#help-button:hover { background: rgba(238, 107, 59, .82); }
#help-button:focus-visible,
#instruction-close:focus-visible,
.control-button:focus-visible { outline: 4px solid var(--yellow); outline-offset: 3px; }
@media (pointer: fine) { #help-button { display: grid; } }

#instruction-modal {
  position: fixed;
  z-index: 2000;
  inset: 0;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(9, 23, 29, .78);
  backdrop-filter: blur(9px);
}

#instruction-modal.is-visible { display: grid; }

.instruction-card {
  width: min(570px, 94vw);
  max-height: calc(100dvh - 28px);
  overflow-y: auto;
  padding: clamp(20px, 4vw, 34px);
  border: 3px solid var(--ink);
  border-radius: 8px 18px 10px 15px;
  background:
    radial-gradient(circle, rgba(23, 42, 50, .1) 1px, transparent 1.5px) 0 0 / 8px 8px,
    var(--paper);
  color: var(--ink);
  box-shadow: 10px 10px 0 rgba(238, 107, 59, .82), 0 28px 80px rgba(0, 0, 0, .48);
  text-align: center;
  transform: rotate(-.35deg);
}

.instruction-card .kicker { margin: 0 0 4px; color: #b13f2e; font-size: .7rem; font-weight: 1000; letter-spacing: .2em; text-transform: uppercase; }
.instruction-card h1 { margin: 0; font: 1000 clamp(1.8rem, 7vw, 3rem)/.95 Impact, "Arial Black", sans-serif; letter-spacing: .03em; text-transform: uppercase; }
.instruction-card > p:not(.kicker) { margin: 14px auto; max-width: 52ch; line-height: 1.45; }
.instruction-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; margin: 17px 0; }
.instruction-grid > div { display: flex; min-height: 59px; align-items: center; justify-content: center; gap: 7px; padding: 8px; border: 2px solid rgba(23, 42, 50, .25); border-radius: 8px; background: rgba(255, 255, 255, .3); }
.instruction-grid b { font-size: .77rem; text-transform: uppercase; }
.key { display: inline-grid; min-width: 29px; min-height: 28px; place-items: center; padding: 3px 6px; border: 2px solid var(--ink); border-radius: 5px; background: #fff9e8; box-shadow: 0 3px 0 var(--ink); font: 1000 .72rem/1 Consolas, monospace; }
.wide-key { min-width: 54px; }
.tip { padding: 9px 12px; border-left: 5px solid var(--orange); background: rgba(238, 107, 59, .1); text-align: left; }

#instruction-close {
  width: 100%;
  min-height: 50px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: var(--orange);
  color: #fffbea;
  box-shadow: 0 5px 0 var(--ink);
  font-weight: 1000;
  letter-spacing: .11em;
  text-transform: uppercase;
  cursor: pointer;
}

#instruction-close:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }

#touch-controls {
  position: fixed;
  z-index: 38;
  inset: 0;
  display: none;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  pointer-events: none;
}

.virtual-joystick,
.actions { pointer-events: auto; }
.actions { display: flex; flex-direction: column; gap: 8px; }

.control-button {
  width: 82px;
  height: 82px;
  display: grid;
  place-items: center;
  align-content: center;
  border: 3px solid #fff0c6;
  border-radius: 50%;
  background: rgba(192, 66, 43, .86);
  color: #fff9e9;
  box-shadow: 0 6px 0 #682c25, 0 10px 25px rgba(0, 0, 0, .32);
  font-weight: 1000;
  touch-action: none;
}

.control-button span { font-size: 1.55rem; line-height: 1; }
.control-button small { margin-top: 3px; font-size: .55rem; letter-spacing: .08em; }
.control-button.pressed { transform: translateY(4px) scale(.97); box-shadow: 0 2px 0 #682c25, 0 5px 12px rgba(0, 0, 0, .24); background: #ee6b3b; }

#portrait-note {
  position: fixed;
  z-index: 4;
  display: none;
  color: rgba(245, 232, 200, .78);
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.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; }

body.touch-device #game-shell { border-width: 1px; border-radius: 10px; }
body.touch-device #sound-status { display: none; }
body.touch-device #hud .hud-card:first-child { display: none; }
body.touch-device .hud-card { min-width: 0; flex: 1; padding: 4px 3px; border-width: 1px; box-shadow: 2px 2px 0 rgba(23, 42, 50, .65); }
body.touch-device .hud-card.wide { min-width: 0; }
body.touch-device #customer-status { font-size: 8px; bottom: 4px; left: 4px; }
body.touch-device #traffic-warning { right: 4px; bottom: 27px; padding: 4px 5px; font-size: 9px; border-width: 1px; }
body.touch-device .hud-label { font-size: .45rem; }
body.touch-device #customer-card .hud-label,
body.touch-device .hud-card.wide .hud-label { font-size: 0; }
body.touch-device #customer-card .hud-label::after { content: "Subs"; font-size: .45rem; }
body.touch-device .hud-card.wide .hud-label::after { content: "Delivered"; font-size: .42rem; }
body.touch-device .hud-card strong { font-size: .72rem; }
body.touch-device #hud { top: 5px; width: calc(100% - 22px); gap: 4px; }
body.touch-device #route-meter { top: 43px; height: 5px; }
body.touch-device #attempt-action { bottom: 66px; min-width: 166px; min-height: 42px; font-size: .78rem; }

@media (max-width: 599px) and (orientation: portrait) {
  body { align-content: start; }
  body.touch-device #game-shell { width: 100vw; height: 56.25vw; margin-top: max(58px, env(safe-area-inset-top)); border-radius: 0; }
  body.touch-device #portrait-note { top: calc(max(58px, env(safe-area-inset-top)) + 58vw); display: block; }
  body.touch-device #touch-controls { align-items: end; padding-bottom: max(34px, env(safe-area-inset-bottom)); }
}

@media (max-height: 430px) {
  .instruction-card { padding: 16px 22px; }
  .instruction-card > p:not(.kicker) { margin: 8px auto; font-size: .86rem; }
  .instruction-grid { margin: 9px 0; gap: 6px; }
  .instruction-grid > div { min-height: 43px; padding: 5px; }
  .key { min-height: 23px; min-width: 25px; }
  #instruction-close { min-height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  .instruction-card { transform: none; }
}
