* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --paper: #edede8;
  --card: #f6f6f2;
  --navy: #16233d;
  --navy-soft: #4a5a76;
  --accent: #b3502e;
  --water: #c3d2da;
  --line: rgba(22, 35, 61, 0.16);
}

html, body {
  overscroll-behavior: none;
}

body {
  background: var(--paper);
  color: var(--navy);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

/* FlightQ-family NavBar: sticky, page-colored (no divider), centered
   uppercase wordmark with a small subtitle, side slots either side. */
.topbar {
  position: sticky;
  top: 0;
  /* above the endgame overlay (60): More Games and profile stay clickable
     while the results card is open */
  z-index: 70;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: var(--paper);
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 16px 8px;
  min-height: 44px;
}

.nav-center { text-align: center; }

.wordmark {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin: 0;
}

.nav-sub {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--navy-soft);
  margin: 0;
}

.nav-side { display: flex; align-items: center; min-width: 72px; }
.nav-right { justify-content: flex-end; }

.nav-link {
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  font-size: 14px;
  font-weight: 600;
  color: var(--navy-soft);
  background: none;
  border: none;
  padding: 0 4px;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: color 0.12s;
}

/* FlightQ ExploreLink pattern: desktop (1024px+) gets a plain link to the
   homepage hub; the tap-to-open dropdown trigger is mobile/tablet only. */
#link-moregames { display: none; }

@media (min-width: 1024px) {
  #link-moregames { display: inline-flex; }
  #btn-moregames { display: none; }
}

.nav-link:hover { color: var(--navy); }

.nav-link svg { transition: transform 0.15s; }
.nav-link.open svg { transform: rotate(180deg); }

/* Profile icon link, right slot on every game page (FlightQ pattern). */
.nav-icon {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  color: var(--navy-soft);
  transition: color 0.12s;
}

.nav-icon:hover { color: var(--navy); }

/* Shared hairline game list (left rail + More games dropdown), matching the
   FlightQ GameSidebar: thin dividers, label + blurb, trailing arrow. */
.game-list { list-style: none; margin: 0; padding: 0; }

.game-list a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--navy);
  transition: background 0.12s;
}

.game-list li:not(:last-child) a { border-bottom: 1px solid var(--line); border-bottom-left-radius: 0; border-bottom-right-radius: 0; }

.game-list a:hover { background: rgba(22, 35, 61, 0.06); }

.game-list .g-label { font-size: 14px; font-weight: 600; }
.game-list .g-blurb { font-size: 12px; color: var(--navy-soft); margin-top: 1px; }
.game-list .g-main { flex: 1; min-width: 0; }
.game-list .g-arrow { color: var(--navy-soft); transition: transform 0.12s; }
.game-list a:hover .g-arrow { transform: translateX(2px); color: var(--navy); }

/* Desktop-only far-left More Games rail (from 1280px), like the FlightQ
   float-left rail: hugs the viewport edge, never overlaps the game column. */
#left-rail {
  display: none;
}

/* Contrail's content column is 1020px (wider than FlightQ's 47.5rem game
   column), so the rail appears once there is real room beside it and sizes
   against our own column, never overlapping it. */
@media (min-width: 1400px) {
  #left-rail {
    display: block;
    position: fixed;
    left: 16px;
    top: 76px;
    width: min(300px, calc((100vw - 1020px) / 2 - 28px));
    z-index: 10;
  }
}

/* More games dropdown, anchored under the LEFT trigger. The trigger hides
   once the left rail takes over (1400px), matching the FlightQ pattern of
   the dropdown being the mobile/tablet path. */
#moregames-panel {
  position: fixed;
  top: 58px;
  left: 12px;
  z-index: 75;
  width: min(320px, calc(100vw - 24px));
  max-height: 70vh;
  overflow-y: auto;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(22, 35, 61, 0.15);
  padding: 6px;
}

#moregames-panel[hidden] { display: none; }

/* Dropdown rows in the FlightQ More Games menu style (ExploreLink): dark
   color-tile + name + blurb, no hairline dividers between game rows, one
   divider under the Homepage row. */
.menu-list { list-style: none; margin: 0; padding: 0; }

.menu-list a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 12px;
  text-decoration: none;
  color: var(--navy);
  transition: background 0.12s;
}

.menu-list a:hover { background: rgba(22, 35, 61, 0.06); }

.menu-list .m-tile {
  width: 36px;
  height: 36px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 8px;
}

.menu-list .m-main { min-width: 0; }
.menu-list .m-label { display: block; font-size: 14px; font-weight: 600; }
.menu-list .m-blurb { display: block; font-size: 12px; line-height: 1.35; color: var(--navy-soft); }

.menu-divider { height: 1px; background: var(--line); margin: 6px 8px; }

main {
  max-width: 1020px;
  margin: 0 auto;
  padding: 12px 16px 32px;
}

#menu h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 30px;
  margin: 18px 0 6px;
}

.menu-sub {
  color: var(--navy-soft);
  font-size: 15px;
  max-width: 560px;
  margin-bottom: 22px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: inherit;
  color: var(--navy);
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.card:hover {
  border-color: var(--navy);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(22, 35, 61, 0.10);
}

.card-map {
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 6px;
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-diff {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--accent);
}

.card-day {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--card);
  background: var(--navy);
  border-radius: 999px;
  padding: 3px 9px;
}

.card-city {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 24px;
  font-weight: 700;
}

.card-airports {
  font-size: 13px;
  font-weight: 600;
  color: var(--navy-soft);
}

.card-blurb {
  font-size: 13px;
  color: var(--navy-soft);
}

.card-best {
  font-size: 12px;
  font-weight: 700;
  margin-top: 6px;
}

/* Full city pool: collapsible per-tier lists under the flagship cards. */
#city-pool { margin-top: 22px; }

.pool-tier {
  border-top: 1px solid var(--line);
  padding: 4px 0;
}

.pool-tier summary {
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 2px;
  color: var(--navy);
  list-style-position: inside;
}

.pool-tier summary:hover { color: var(--accent); }

.city-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 2px 14px;
}

.city-pill {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--navy);
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  transition: border-color 0.12s, transform 0.12s;
}

.city-pill:hover {
  border-color: var(--navy);
  transform: translateY(-1px);
}

.menu-help, .game-help {
  margin-top: 16px;
  font-size: 13px;
  color: var(--navy-soft);
}

/* The stage is sized so the whole board always fits the viewport: capped by
   both the column width and the remaining height. The aspect ratio is set by
   the game (landscape 1.6, portrait 2/3) via --board-aspect. */
#stage {
  position: relative;
  width: min(100%, calc((100dvh - 175px) * var(--board-aspect, 1.6)));
  margin: 0 auto;
  border: 2px solid var(--navy);
  border-radius: 10px;
  overflow: hidden;
  touch-action: none;
  background: var(--paper);
  user-select: none;
  -webkit-user-select: none;
}

/* Three zones: tabs | city (true center) | stats. The 1fr side columns are
   equal, so the city name centers on the board regardless of side widths. */
#hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 8px 2px;
  font-size: 14px;
  width: min(100%, calc((100dvh - 175px) * var(--board-aspect, 1.6)));
  margin: 0 auto;
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-self: start;
}

.hud-center {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

/* Difficulty tabs: today's three cities as a segmented control, the same
   recipe as Strata's mode switcher (pill track, filled active segment). */
#tier-tabs {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 4px;
  padding: 3px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}

.tier-tab {
  border: none;
  background: transparent;
  color: var(--navy-soft);
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  padding: 6px 12px;
  border-radius: 7px;
  cursor: pointer;
  transition: color 0.12s, background 0.12s;
}

.tier-tab:hover { color: var(--navy); }

.tier-tab[aria-selected="true"] {
  background: var(--navy);
  color: var(--card);
}

.hud-day {
  font-size: 12px;
  font-weight: 600;
  color: var(--navy-soft);
  white-space: nowrap;
}

#hud-city {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
  font-weight: 700;
}

.pill {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--card);
  background: var(--navy);
  border-radius: 999px;
  padding: 3px 10px;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 18px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  justify-self: end;
}

.hud-right strong { font-size: 16px; }

.hud-btn {
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  align-self: center;
}

#board {
  display: block;
  width: 100%;
  height: auto;
}

#overlay[hidden] { display: none; }

/* Viewport-fixed, not stage-absolute: on phones the stage is shorter than the
   overlay content, and an absolutely positioned overlay clips the title and
   pushes the buttons past the board edge where they can't be tapped. */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(237, 237, 232, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px;
}

#overlay-inner {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 32px 42px;
  width: min(540px, 100%);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(22, 35, 61, 0.15);
}

#overlay-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 26px;
  margin-bottom: 2px;
}

#overlay-reason {
  font-size: 14px;
  color: var(--navy-soft);
  margin-bottom: 12px;
}

#overlay-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  margin-bottom: 4px;
}

#overlay-score-num {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 44px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.overlay-score-label {
  font-size: 13px;
  color: var(--navy-soft);
}

#overlay-record {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--card);
  background: var(--accent);
  border-radius: 999px;
  padding: 3px 10px;
}

#overlay-stats {
  font-size: 13px;
  color: var(--navy-soft);
  margin-bottom: 14px;
}

#overlay-board {
  text-align: left;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  margin-bottom: 16px;
}

#overlay-board-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--navy-soft);
  margin-bottom: 8px;
}

/* Leaderboard scope tabs, the segmented-control recipe at list size. */
#lb-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 3px;
  border: 1.5px solid var(--line);
  border-radius: 9px;
  background: var(--paper);
  margin-bottom: 8px;
}

.lb-tab {
  border: none;
  background: transparent;
  color: var(--navy-soft);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.12s, background 0.12s;
}

.lb-tab:hover { color: var(--navy); }

.lb-tab[aria-selected="true"] {
  background: var(--navy);
  color: var(--card);
}

#lb-note {
  font-size: 13px;
  color: var(--navy-soft);
  padding: 10px 4px;
}

#overlay-board-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

#overlay-board-list li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 5px 8px;
  border-radius: 7px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

#overlay-board-list li.current {
  background: rgba(179, 80, 46, 0.10);
}

#overlay-board-list .lb-rank {
  color: var(--navy-soft);
  font-size: 12px;
  font-weight: 700;
  width: 20px;
}

#overlay-board-list .lb-score {
  font-weight: 700;
  width: 56px;
}

#overlay-board-list .lb-sub {
  color: var(--navy-soft);
  font-size: 12px;
  flex: 1;
}

#overlay-board-list .lb-date {
  color: var(--navy-soft);
  font-size: 12px;
}

#overlay-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 9px;
  border: 1.5px solid var(--navy);
  background: transparent;
  color: var(--navy);
  cursor: pointer;
}

.btn.primary {
  background: var(--navy);
  color: var(--card);
}

.btn:hover { opacity: 0.85; }

.game-help {
  text-align: center;
}

/* Embedded in the /contrail page's iframe: the game's own FlightQ-family
   topbar IS the page header (the AirportQ pattern); links break out of the
   frame via target=_top, set in main.js. */

@media (max-width: 640px) {
  .wordmark { font-size: 16px; }
  .nav-sub { display: none; }
  main { padding: 8px 8px 20px; }
  #hud, #stage { width: min(100%, calc((100dvh - 150px) * var(--board-aspect, 1.6))); }
  /* Phones: full-width difficulty tabs on top, then one tidy row with the
     city name left and the score cluster right. */
  #hud {
    grid-template-columns: 1fr auto;
    grid-template-areas: "tabs tabs" "city stats";
    row-gap: 7px;
  }
  .hud-left { grid-area: tabs; width: 100%; }
  #tier-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    width: 100%;
  }
  .tier-tab { padding: 7px 0; text-align: center; }
  .hud-center { grid-area: city; justify-self: start; min-width: 0; }
  .hud-right {
    grid-area: stats;
    justify-self: end;
    justify-content: flex-end;
    gap: 12px;
    font-size: 12px;
  }
  #hud-city {
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .hud-right { gap: 8px; font-size: 12px; }
  .hud-right strong { font-size: 14px; }
  .pill { font-size: 10px; padding: 2px 8px; }
  .tier-tab { font-size: 11px; letter-spacing: 1px; }
  .hud-day { display: none; }
  .hud-btn { font-size: 11px; padding: 4px 9px; white-space: nowrap; }
  .game-help { font-size: 11px; margin-top: 10px; }
  #overlay-inner { padding: 20px; }
}

@media (max-height: 500px) {
  /* Landscape phones: give nearly everything to the board. One compact HUD
     row (no wrapping; a wrapped HUD eats the board's height budget), and the
     width formula budgets for that single 30px row. */
  .topbar { display: none; }
  main { padding: 4px 8px; }
  .game-help { display: none; }
  #hud, #stage { width: min(100%, calc((100dvh - 52px) * var(--board-aspect, 1.6))); }
  #hud {
    padding: 3px 2px;
    column-gap: 8px;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "tabs city stats";
  }
  .hud-left { grid-area: tabs; gap: 6px; }
  .hud-center { grid-area: city; justify-self: stretch; justify-content: center; }
  .hud-right { grid-area: stats; }
  #hud-city {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .hud-day { display: none; }
  .hud-right { width: auto; justify-content: flex-end; gap: 8px; font-size: 11px; flex: none; }
  .hud-right strong { font-size: 13px; }
  .tier-tab { font-size: 9.5px; letter-spacing: 0.8px; padding: 4px 7px; }
  .hud-btn { font-size: 10px; padding: 3px 8px; white-space: nowrap; }
}
