:root {
  --ink: #102a3b;
  --ink-soft: #294654;
  --paper: #fffaf0;
  --cream: #f5eddb;
  --blue: #45c9d1;
  --blue-dark: #147e91;
  --coral: #f46f58;
  --lime: #d8ec70;
  --white: #fffdf8;
  --line: rgba(16, 42, 59, 0.18);
  --shadow: 0 24px 80px rgba(31, 45, 49, 0.2);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 0%, rgba(255, 255, 255, 0.96), transparent 32rem),
    radial-gradient(circle at 92% 100%, rgba(69, 201, 209, 0.16), transparent 30rem),
    linear-gradient(145deg, #fff9eb 0%, #e9dcc2 100%);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
  font: inherit;
}

button:focus-visible,
a:focus-visible,
canvas:focus-visible {
  outline: 3px solid var(--blue-dark);
  outline-offset: 3px;
}

.app {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 14px clamp(14px, 3vw, 44px) 24px;
}

.topbar {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  position: relative;
  width: 43px;
  height: 43px;
  flex: 0 0 auto;
}

.brand-mark i,
.brand-mark b {
  position: absolute;
  inset: 0;
  border: 2px solid var(--ink);
  border-radius: 13px;
}

.brand-mark i {
  transform: translate(4px, 4px);
  background: var(--blue);
}

.brand-mark b {
  display: grid;
  place-items: center;
  background: var(--lime);
  font-size: 24px;
}

.brand-copy strong,
.brand-copy small {
  display: block;
  line-height: 1;
}

.brand-copy strong {
  font-size: 14px;
  letter-spacing: 0.08em;
}

.brand-copy small {
  margin-top: 5px;
  color: var(--blue-dark);
  font-size: 8px;
  font-weight: 900;
  letter-spacing: 0.24em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.route-status {
  margin-right: 8px;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.15em;
  white-space: nowrap;
}

.route-status i {
  width: 7px;
  height: 7px;
  display: inline-block;
  margin-right: 7px;
  border-radius: 50%;
  background: #58b96d;
  box-shadow: 0 0 0 5px rgba(88, 185, 109, 0.14);
}

.route-status i.active {
  background: var(--blue);
  box-shadow: 0 0 0 5px rgba(69, 201, 209, 0.14);
}

.route-status i.paused {
  background: #e4a94e;
  box-shadow: 0 0 0 5px rgba(228, 169, 78, 0.14);
}

.route-status i.complete {
  background: var(--lime);
  box-shadow: 0 0 0 5px rgba(216, 236, 112, 0.18);
}

.round-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.48);
  cursor: pointer;
  font-size: 15px;
  font-weight: 900;
  transition: transform 140ms ease, background 140ms ease;
}

.round-button:hover {
  transform: translateY(-2px);
  background: white;
}

.round-button:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  transform: none;
}

.game-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: 9 / 16;
  border: 2px solid var(--ink);
  border-radius: 22px;
  background: #9fdcd5;
  box-shadow: var(--shadow);
  isolation: isolate;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
}

.screen.is-visible {
  display: flex;
}

.start-screen {
  align-items: center;
  justify-content: space-between;
  gap: clamp(20px, 5vw, 80px);
  padding: clamp(24px, 4.6vw, 70px);
  background:
    linear-gradient(90deg, rgba(245, 237, 219, 0.985) 0%, rgba(245, 237, 219, 0.96) 54%, rgba(245, 237, 219, 0.58) 75%, rgba(245, 237, 219, 0.05) 100%);
}

.start-card {
  width: min(690px, 61%);
}

.eyebrow {
  margin: 0 0 12px;
  color: #d95444;
  font-size: clamp(9px, 0.85vw, 12px);
  font-weight: 950;
  letter-spacing: 0.22em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1,
h2 {
  letter-spacing: -0.055em;
  text-transform: uppercase;
}

h1 {
  margin-bottom: 17px;
  font-size: clamp(43px, 6.1vw, 90px);
  line-height: 0.84;
}

h1 em {
  color: var(--blue-dark);
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
  text-transform: none;
}

.start-lede {
  margin-bottom: 21px;
  color: var(--ink-soft);
  font-size: clamp(13px, 1.25vw, 18px);
  line-height: 1.42;
}

.mission-loop {
  max-width: 690px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 12px;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}

.legend-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-bottom: 18px;
  color: var(--ink-soft);
  font-size: clamp(7px, 0.66vw, 9px);
  font-weight: 850;
  letter-spacing: 0.05em;
}

.legend-strip b {
  margin-right: 5px;
  color: var(--blue-dark);
  font-size: 0.9em;
  letter-spacing: 0.11em;
}

.mission-loop > div {
  position: relative;
  min-height: 72px;
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  gap: 9px;
  padding: 10px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.3);
}

.step-number {
  position: absolute;
  top: 5px;
  right: 7px;
  color: rgba(16, 42, 59, 0.38);
  font-size: 7px;
  font-weight: 950;
  letter-spacing: 0.12em;
}

.step-icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--ink);
  border-radius: 50%;
  font-size: 18px;
  font-weight: 900;
}

.step-icon.kit {
  background: var(--blue);
}

.step-icon.arrow {
  background: var(--lime);
}

.step-icon.home {
  background: var(--coral);
}

.mission-loop p {
  margin: 0;
  line-height: 1.1;
}

.mission-loop strong,
.mission-loop small {
  display: block;
}

.mission-loop strong {
  font-size: clamp(8px, 0.75vw, 11px);
  letter-spacing: 0.08em;
}

.mission-loop small {
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: clamp(7px, 0.7vw, 10px);
}

.start-actions {
  display: flex;
  align-items: center;
  gap: 18px;
}

.primary-button,
.outline-button {
  min-height: 52px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 950;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.primary-button {
  min-width: 220px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 7px 0 23px;
  background: var(--lime);
  box-shadow: 5px 5px 0 var(--ink);
}

.primary-button b {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--ink);
  font-size: 19px;
}

.outline-button {
  padding: 0 23px;
  background: transparent;
}

.primary-button:hover,
.outline-button:hover {
  transform: translateY(-2px);
}

.primary-button:hover {
  box-shadow: 7px 7px 0 var(--ink);
}

.outline-button:hover {
  background: rgba(255, 255, 255, 0.5);
}

.keys {
  display: grid;
  gap: 5px;
  margin: 0;
  color: var(--ink-soft);
  font-size: 8px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

kbd {
  display: inline-block;
  padding: 3px 6px;
  border: 1px solid rgba(16, 42, 59, 0.5);
  border-bottom-width: 2px;
  border-radius: 5px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.62);
  font: inherit;
}

.shift-card {
  width: clamp(205px, 20vw, 290px);
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(18px, 2.2vw, 31px);
  border: 1px solid rgba(16, 42, 59, 0.35);
  border-radius: 18px;
  background: rgba(255, 250, 240, 0.9);
  box-shadow: 12px 12px 0 rgba(16, 42, 59, 0.12);
  transform: rotate(1.5deg);
}

.shift-card-head {
  display: flex;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--ink);
  font-size: 8px;
  font-weight: 950;
  letter-spacing: 0.12em;
}

.shift-card ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

.shift-card li {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 7px;
  padding: clamp(6px, 0.75vw, 10px) 2px;
  border-bottom: 1px dashed rgba(16, 42, 59, 0.23);
  font-size: clamp(9px, 0.86vw, 12px);
}

.shift-card li span,
.shift-card li i {
  color: rgba(16, 42, 59, 0.54);
  font-size: 8px;
  font-style: normal;
  font-weight: 900;
}

.shift-card li.active {
  color: var(--blue-dark);
}

.shift-card li.active span {
  width: 19px;
  height: 19px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--ink);
  background: var(--lime);
}

.shift-card > p {
  margin: 17px 0 0;
  color: var(--ink-soft);
  font: italic clamp(9px, 0.8vw, 11px)/1.45 Georgia, serif;
}

.pause-screen,
.results-screen {
  align-items: center;
  justify-content: center;
  padding: 28px;
  background: rgba(16, 42, 59, 0.66);
  backdrop-filter: blur(9px);
}

.modal {
  width: min(810px, 92%);
  border: 2px solid var(--ink);
  border-radius: 21px;
  background: var(--cream);
  box-shadow: 10px 10px 0 rgba(0, 0, 0, 0.2);
}

.modal.compact {
  width: min(450px, 92%);
  padding: 38px;
  text-align: center;
}

.modal-icon {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  margin: 0 auto 17px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--blue);
  font-size: 27px;
}

.modal.compact h2 {
  margin-bottom: 10px;
  font-size: clamp(32px, 4vw, 53px);
  line-height: 0.95;
}

.modal.compact > p:not(.eyebrow) {
  margin-bottom: 24px;
  color: var(--ink-soft);
  font-size: 13px;
}

.results-modal {
  padding: clamp(24px, 3.2vw, 42px);
}

.results-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 22px;
}

.results-heading h2 {
  max-width: 500px;
  margin-bottom: 20px;
  font-size: clamp(30px, 4.1vw, 60px);
  line-height: 0.88;
}

.rank-stamp {
  min-width: 132px;
  padding: 11px 13px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  text-align: center;
  transform: rotate(3deg);
}

.rank-stamp span,
.rank-stamp strong {
  display: block;
}

.rank-stamp span {
  margin-bottom: 5px;
  font-size: 7px;
  font-weight: 900;
  letter-spacing: 0.14em;
}

.rank-stamp strong {
  color: var(--blue-dark);
  font: 800 clamp(12px, 1.2vw, 17px)/1 Georgia, serif;
}

.main-result {
  display: flex;
  align-items: center;
  gap: 17px;
  margin-bottom: 17px;
  padding: 14px 18px;
  border-radius: 14px;
  color: white;
  background: var(--ink);
}

.result-snowflake {
  width: 51px;
  height: 51px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  color: var(--ink);
  background: var(--lime);
  font-size: 26px;
}

.main-result > div:last-child {
  display: flex;
  align-items: center;
  gap: 15px;
}

.main-result strong {
  color: var(--lime);
  font-size: clamp(35px, 4vw, 58px);
  line-height: 0.9;
}

.main-result span {
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.11em;
  line-height: 1.35;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 16px;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}

.stat-grid > div {
  min-height: 62px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 10px 13px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.stat-grid span,
.stat-grid strong {
  display: block;
}

.stat-grid span {
  margin-bottom: 4px;
  color: var(--ink-soft);
  font-size: 7px;
  font-weight: 900;
  letter-spacing: 0.13em;
}

.stat-grid strong {
  font-size: clamp(17px, 1.8vw, 25px);
}

.result-note {
  margin: 0 0 18px;
  color: var(--ink-soft);
  font-size: 10px;
  line-height: 1.45;
}

.result-actions {
  display: flex;
  gap: 13px;
}

.touch-controls {
  position: absolute;
  z-index: 8;
  right: 18px;
  bottom: 17px;
  display: none;
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(3, 48px);
  gap: 3px;
}

.touch-controls button,
.touch-controls > span {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--ink);
  border-radius: 13px;
}

.touch-controls button {
  color: white;
  background: rgba(16, 42, 59, 0.88);
  box-shadow: 3px 3px 0 rgba(255, 255, 255, 0.48);
  font-size: 20px;
  font-weight: 900;
  touch-action: none;
}

.touch-controls button.is-pressed {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 rgba(255, 255, 255, 0.48);
  background: var(--blue-dark);
}

.touch-controls > span {
  grid-column: 2;
  grid-row: 2;
  border-color: rgba(16, 42, 59, 0.35);
  background: rgba(255, 255, 255, 0.5);
}

.touch-controls .up {
  grid-column: 2;
  grid-row: 1;
}

.touch-controls .left {
  grid-column: 1;
  grid-row: 2;
}

.touch-controls .right {
  grid-column: 3;
  grid-row: 2;
}

.touch-controls .down {
  grid-column: 2;
  grid-row: 3;
}

.drop-button {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 6px 4px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.48);
  cursor: pointer;
  font-size: 8px;
  font-weight: 950;
  letter-spacing: 0.1em;
}

.drop-button kbd {
  color: var(--ink);
  background: var(--lime);
  border-color: var(--ink);
}

.drop-button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

footer {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: rgba(16, 42, 59, 0.64);
  font-size: 8px;
  font-weight: 900;
  letter-spacing: 0.16em;
}

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

@media (pointer: coarse) {
  .touch-controls.is-active {
    display: grid;
  }
}

@media (max-width: 980px) {
  .start-screen {
    padding: 26px 32px;
  }

  .start-card {
    width: 69%;
  }

  .shift-card {
    width: 25%;
    padding: 16px;
  }

  .shift-card > p {
    display: none;
  }

  .start-actions {
    gap: 12px;
  }
}

@media (max-width: 740px) {
  .app {
    padding: 8px 8px 14px;
  }

  .topbar {
    min-height: 53px;
  }

  .brand-mark {
    width: 35px;
    height: 35px;
  }

  .brand-copy strong {
    font-size: 11px;
  }

  .brand-copy small,
  .route-status,
  footer span:first-child {
    display: none;
  }

  .round-button {
    width: 34px;
    height: 34px;
  }

  .drop-button {
    min-width: 34px;
    min-height: 34px;
    justify-content: center;
    padding: 3px;
  }

  .drop-button > span {
    display: none;
  }

  .game-frame {
    border-radius: 15px;
  }

  .touch-controls {
    right: 8px;
    bottom: 8px;
    grid-template-columns: repeat(3, 34px);
    grid-template-rows: repeat(3, 34px);
  }

  .touch-controls button,
  .touch-controls > span {
    width: 34px;
    height: 34px;
    border-radius: 9px;
  }

  .start-screen {
    align-items: flex-start;
    padding: 14px 18px;
    overflow-y: auto;
    background: rgba(245, 237, 219, 0.97);
  }

  .start-card {
    width: 100%;
  }

  h1 {
    margin-bottom: 9px;
    font-size: clamp(36px, 8.5vw, 50px);
  }

  .eyebrow {
    margin-bottom: 7px;
  }

  .start-lede br {
    display: none;
  }

  .start-lede {
    margin-bottom: 10px;
    font-size: 11px;
  }

  .mission-loop {
    margin-bottom: 7px;
  }

  .mission-loop > div {
    min-height: 50px;
    grid-template-columns: 31px 1fr;
    gap: 6px;
    padding: 7px;
  }

  .step-icon {
    width: 30px;
    height: 30px;
    font-size: 14px;
  }

  .start-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .legend-strip {
    gap: 4px 12px;
    margin-bottom: 8px;
    font-size: 6px;
  }

  .keys {
    display: none;
  }

  .primary-button {
    min-height: 47px;
    min-width: 205px;
  }

  .primary-button b {
    width: 34px;
    height: 34px;
  }

  .shift-card {
    display: none;
  }

  .pause-screen,
  .results-screen {
    padding: 13px;
  }

  .results-modal {
    max-height: 96%;
    padding: 19px;
    overflow-y: auto;
  }

  .rank-stamp {
    min-width: 105px;
  }

  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .result-actions {
    flex-wrap: wrap;
  }

  footer {
    justify-content: center;
    text-align: center;
  }
}

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

/* Mobile-first game shell -------------------------------------------------- */

.orientation-gate {
  display: none;
}

[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

.game-frame,
.touch-controls,
.touch-controls button {
  -webkit-user-select: none;
  user-select: none;
}

@media (pointer: coarse) {
  html,
  body {
    overscroll-behavior: none;
  }

  .app {
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
  }

  .topbar {
    min-height: 56px;
  }

  .route-status {
    display: none;
  }

  .round-button,
  .drop-button {
    width: 48px;
    min-width: 48px;
    height: 48px;
    min-height: 48px;
  }

  .drop-button {
    padding: 3px;
    justify-content: center;
  }

  .drop-button > span {
    display: none;
  }

  .primary-button,
  .outline-button {
    min-height: 48px;
  }

  .touch-controls.is-active {
    right: max(9px, env(safe-area-inset-right));
    bottom: max(9px, env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(3, 48px);
    grid-template-rows: repeat(3, 48px);
    gap: 3px;
  }

  .touch-controls button,
  .touch-controls > span {
    width: 48px;
    height: 48px;
    border-radius: 14px;
  }

  .touch-controls button {
    background: rgba(16, 42, 59, 0.8);
    backdrop-filter: blur(5px);
    touch-action: none;
  }
}

/* Width/height fallback keeps touch controls available in mobile browser
   emulation and on compact hybrid devices that report a fine primary pointer. */
@media (max-width: 600px), (max-height: 560px) {
  .touch-controls.is-active {
    right: max(9px, env(safe-area-inset-right));
    bottom: max(9px, env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(3, 48px);
    grid-template-rows: repeat(3, 48px);
    gap: 3px;
  }

  .touch-controls button,
  .touch-controls > span {
    width: 48px;
    height: 48px;
    border-radius: 14px;
  }

  .touch-controls button {
    background: rgba(16, 42, 59, 0.8);
    backdrop-filter: blur(5px);
    touch-action: none;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  html,
  body {
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  .app {
    height: 100vh;
    height: 100dvh;
    display: grid;
    grid-template-rows: 54px minmax(0, 1fr);
    align-items: center;
    padding-top: max(2px, env(safe-area-inset-top));
    padding-bottom: max(2px, env(safe-area-inset-bottom));
  }

  .topbar {
    min-height: 52px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .brand-copy small {
    display: none;
  }

  .round-button,
  .drop-button {
    width: 46px;
    min-width: 46px;
    height: 46px;
    min-height: 46px;
  }

  .game-frame {
    width: min(100%, calc(177.7778vh - 110px));
    width: min(100%, calc(177.7778dvh - 110px));
    max-width: none;
    max-height: calc(100dvh - 62px);
    justify-self: center;
    align-self: center;
    border-radius: 15px;
  }

  body.game-session .app {
    grid-template-rows: minmax(0, 1fr);
    padding-top: max(0px, env(safe-area-inset-top));
    padding-bottom: max(0px, env(safe-area-inset-bottom));
  }

  body.game-session .topbar {
    display: none;
  }

  body.game-session .game-frame {
    width: min(100%, 177.7778vh);
    width: min(100%, 177.7778dvh);
    max-height: 100vh;
    max-height: 100dvh;
  }

  body.game-session .touch-controls {
    grid-template-columns: repeat(3, 44px);
    grid-template-rows: repeat(3, 44px);
  }

  body.game-session .touch-controls button,
  body.game-session .touch-controls > span {
    width: 44px;
    height: 44px;
    border-radius: 13px;
  }

  .start-screen {
    align-items: flex-start;
    padding: clamp(12px, 3dvh, 20px) clamp(18px, 4vw, 38px);
    overflow-y: auto;
    background: rgba(245, 237, 219, 0.97);
  }

  .start-card {
    width: 100%;
  }

  .start-screen h1 {
    margin-bottom: 7px;
    font-size: clamp(36px, 8.5dvh, 58px);
  }

  .start-lede {
    margin-bottom: 9px;
    font-size: clamp(9px, 2.4dvh, 13px);
  }

  .mission-loop {
    margin-bottom: 6px;
  }

  .mission-loop > div {
    min-height: 48px;
    padding: 6px 8px;
  }

  .legend-strip {
    margin-bottom: 7px;
    font-size: 6px;
  }

  .shift-card,
  .keys,
  footer {
    display: none;
  }
}

@media (orientation: portrait) and (max-width: 600px) {
  body:not(.allow-portrait) .orientation-gate {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding:
      max(28px, env(safe-area-inset-top))
      max(24px, env(safe-area-inset-right))
      max(28px, env(safe-area-inset-bottom))
      max(24px, env(safe-area-inset-left));
    text-align: center;
    background:
      radial-gradient(circle at 50% 20%, rgba(69, 201, 209, 0.22), transparent 18rem),
      var(--cream);
  }

  .phone-turn {
    width: 108px;
    height: 62px;
    display: grid;
    place-items: center;
    margin-bottom: 28px;
    border: 3px solid var(--ink);
    border-radius: 17px;
    background: var(--blue);
    box-shadow: 8px 8px 0 var(--ink);
    transform: rotate(-8deg);
  }

  .phone-turn span {
    font-size: 37px;
    font-weight: 900;
  }

  .orientation-gate h2 {
    max-width: 420px;
    margin-bottom: 14px;
    font-size: clamp(38px, 11vw, 58px);
    line-height: 0.9;
  }

  .orientation-gate > p:not(.eyebrow) {
    max-width: 390px;
    margin-bottom: 26px;
    color: var(--ink-soft);
    font-size: 15px;
    line-height: 1.45;
  }

  .orientation-actions {
    width: min(330px, 100%);
    display: grid;
    gap: 14px;
  }

  .orientation-actions .primary-button,
  .orientation-actions .outline-button {
    width: 100%;
  }

  body.allow-portrait .orientation-gate {
    display: none;
  }

  body.allow-portrait .start-screen {
    align-items: center;
    justify-content: center;
    padding: 12px 16px;
    overflow: hidden;
  }

  body.allow-portrait .start-card {
    width: 100%;
  }

  body.allow-portrait .start-screen .eyebrow,
  body.allow-portrait .mission-loop,
  body.allow-portrait .legend-strip,
  body.allow-portrait .shift-card,
  body.allow-portrait .keys {
    display: none;
  }

  body.allow-portrait .start-screen h1 {
    margin-bottom: 7px;
    font-size: clamp(31px, 9vw, 38px);
    line-height: 0.82;
  }

  body.allow-portrait .start-lede {
    margin-bottom: 9px;
    font-size: 10px;
    line-height: 1.25;
  }

  body.allow-portrait .start-actions {
    display: block;
  }

  body.allow-portrait .start-actions .primary-button {
    width: min(230px, 100%);
  }
}

:fullscreen body,
:-webkit-full-screen body {
  overflow: hidden;
  background: var(--cream);
}

:fullscreen .app,
:-webkit-full-screen .app {
  width: 100%;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: 62px minmax(0, 1fr);
  align-items: center;
  padding:
    max(4px, env(safe-area-inset-top))
    max(8px, env(safe-area-inset-right))
    max(4px, env(safe-area-inset-bottom))
    max(8px, env(safe-area-inset-left));
  background: var(--cream);
}

:fullscreen .game-frame,
:-webkit-full-screen .game-frame {
  width: min(100%, calc(177.7778vh - 128px));
  width: min(100%, calc(177.7778dvh - 128px));
  height: auto;
  max-width: 100%;
  max-height: calc(100dvh - 72px);
  justify-self: center;
  align-self: center;
}

:fullscreen footer,
:-webkit-full-screen footer {
  display: none;
}

/* Portrait-first game shell ---------------------------------------------- */

.app {
  width: min(560px, 100%);
  padding: 8px max(8px, env(safe-area-inset-right)) 16px max(8px, env(safe-area-inset-left));
}

.game-frame {
  width: min(100%, calc((100dvh - 92px) * 0.5625));
  aspect-ratio: 9 / 16;
  margin-inline: auto;
}

.orientation-gate,
body:not(.allow-portrait) .orientation-gate {
  display: none !important;
}

.start-screen {
  align-items: flex-start;
  justify-content: flex-start;
  padding: clamp(24px, 6vw, 38px) clamp(20px, 6vw, 32px);
  overflow-y: auto;
  background:
    radial-gradient(circle at 85% 12%, rgba(69, 201, 209, 0.22), transparent 13rem),
    rgba(245, 237, 219, 0.985);
}

.start-card {
  width: 100%;
}

.start-screen h1 {
  margin-bottom: 16px;
  font-size: clamp(43px, 12vw, 63px);
  line-height: 0.86;
}

.start-lede {
  margin-bottom: 18px;
  font-size: clamp(12px, 3.5vw, 15px);
}

.mission-loop {
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 14px;
}

.mission-loop > div {
  min-height: 92px;
  grid-template-columns: 1fr;
  align-content: center;
  justify-items: center;
  gap: 7px;
  padding: 12px 7px 9px;
  text-align: center;
}

.mission-loop strong {
  font-size: 9px;
}

.mission-loop small {
  font-size: 8px;
}

.legend-strip {
  display: grid;
  gap: 5px;
  margin-bottom: 18px;
  font-size: 8px;
}

.start-actions {
  display: block;
}

.start-actions .primary-button {
  width: 100%;
}

.shift-card,
.keys,
footer {
  display: none;
}

body.game-session .topbar {
  display: flex;
}

:fullscreen .app,
:-webkit-full-screen .app {
  width: min(560px, 100%);
  grid-template-rows: 58px minmax(0, 1fr);
}

:fullscreen .game-frame,
:-webkit-full-screen .game-frame {
  width: auto;
  height: min(calc(100vh - 70px), calc(100dvh - 70px));
  max-height: calc(100dvh - 70px);
  aspect-ratio: 9 / 16;
}

@media (max-width: 600px), (pointer: coarse) {
  html,
  body {
    overflow-x: hidden;
  }

  .app {
    min-height: 100dvh;
    padding-top: max(4px, env(safe-area-inset-top));
    padding-bottom: max(6px, env(safe-area-inset-bottom));
  }

  .topbar {
    min-height: 54px;
  }

  .brand-copy,
  .route-status,
  .drop-button > span {
    display: none;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
  }

  .topbar-actions {
    gap: 5px;
  }

  .round-button,
  .drop-button {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
  }

  .game-frame {
    width: min(100%, calc((100dvh - 70px) * 0.5625));
    border-radius: 18px;
  }

  .touch-controls.is-active,
  body.game-session .touch-controls.is-active {
    left: 50%;
    right: auto;
    bottom: max(10px, env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(4, 48px);
    grid-template-rows: 48px;
    gap: 5px;
    transform: translateX(-50%);
  }

  .touch-controls .left {
    grid-column: 1;
    grid-row: 1;
  }

  .touch-controls .up {
    grid-column: 2;
    grid-row: 1;
  }

  .touch-controls .down {
    grid-column: 3;
    grid-row: 1;
  }

  .touch-controls .right {
    grid-column: 4;
    grid-row: 1;
  }

  .touch-controls > span {
    display: none;
  }

  .touch-controls button,
  body.game-session .touch-controls button {
    width: 48px;
    height: 48px;
    border-radius: 15px;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  .app,
  body.game-session .app {
    width: min(520px, 100%);
    height: 100dvh;
    display: grid;
    grid-template-rows: 52px minmax(0, 1fr);
  }

  .topbar,
  body.game-session .topbar {
    display: flex;
  }

  .game-frame,
  body.game-session .game-frame {
    width: auto;
    height: calc(100dvh - 58px);
    max-height: calc(100dvh - 58px);
    aspect-ratio: 9 / 16;
  }

  .start-screen {
    padding: 18px 16px;
  }

  .start-screen h1 {
    font-size: 38px;
  }
}
