/* City2City. An airmail-and-ticket look: cool paper, navy ink, and the red and blue
   of an airmail envelope. The globe is the loud part; everything else stays quiet. */

:root {
  --paper: #edf1f4;
  --surface: #f9fbfc;
  --ink: #17213a;
  --ink-soft: #5b6680;
  --rule: #cdd6e0;
  --red: #c8312b;
  --blue: #22489a;
  --on-blue: #ffffff;

  /* How each flight went: closer, no closer, further, not booked. */
  --good: #2e8b57;
  --same: #c9971c;
  --worse: #d9692a;
  --miss: var(--red);

  --start: var(--blue);
  --end: var(--red);
  --route: var(--red);
  --reveal: var(--blue);

  --globe-ocean: #c6d9e6;
  --globe-land: #fbfbf8;
  --globe-coast: #8ea6bc;
  --globe-border: #c9d2dc;
  --globe-grid: rgba(34, 72, 154, 0.13);
  --globe-halo: rgba(23, 33, 58, 0.35);
  --globe-shade: 0.9 1.04 0.84;

  --font: 'Archivo', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --stripe: 7px;
  color-scheme: light;
}

/* Dark: follows the device, unless the page is told otherwise with data-theme. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0e1420;
    --surface: #161e2d;
    --ink: #e6ebf2;
    --ink-soft: #9aa6ba;
    --rule: #2c3a52;
    --red: #f06a5f;
    --blue: #8caef5;
    --on-blue: #0e1420;
    --good: #5cc28a;
    --same: #e3b544;
    --worse: #f08d4f;
    --globe-ocean: #13223a;
    --globe-land: #2b3b57;
    --globe-coast: #6c88ae;
    --globe-border: #40536f;
    --globe-grid: rgba(140, 174, 245, 0.1);
    --globe-halo: rgba(140, 174, 245, 0.4);
    --globe-shade: 0.78 1.12 0.7;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0e1420;
  --surface: #161e2d;
  --ink: #e6ebf2;
  --ink-soft: #9aa6ba;
  --rule: #2c3a52;
  --red: #f06a5f;
  --blue: #8caef5;
  --on-blue: #0e1420;
  --good: #5cc28a;
  --same: #e3b544;
  --worse: #f08d4f;
  --globe-ocean: #13223a;
  --globe-land: #2b3b57;
  --globe-coast: #6c88ae;
  --globe-border: #40536f;
  --globe-grid: rgba(140, 174, 245, 0.1);
  --globe-halo: rgba(140, 174, 245, 0.4);
  --globe-shade: 0.78 1.12 0.7;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

/* The airmail edge. */
body::before {
  content: '';
  display: block;
  height: var(--stripe);
  background: repeating-linear-gradient(-45deg,
    var(--red) 0 13px, var(--paper) 13px 19px, var(--blue) 19px 32px, var(--paper) 32px 38px);
}

button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* --- Top bar ------------------------------------------------------------- */

.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px clamp(16px, 3vw, 28px);
  height: 64px;
}
.wordmark {
  margin: 0;
  font-size: 27px;
  font-weight: 850;
  font-stretch: 125%;
  font-variation-settings: 'wdth' 125;
  letter-spacing: -0.015em;
  line-height: 1;
}
.edition {
  margin: 0 0 0 6px;
  flex: 1;
  color: var(--ink-soft);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn {
  width: 38px;
  height: 38px;
  flex: none;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--rule);
  border-radius: 50%;
  background: transparent;
  font-weight: 750;
  font-size: 17px;
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--ink); }

/* --- Layout -------------------------------------------------------------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 420px);
  height: calc(100dvh - 64px - var(--stripe));
  min-height: 560px;
}
.globe {
  position: relative;
  min-height: 0;
  overflow: hidden;
}
.globe canvas { position: absolute; inset: 0; display: block; }
.globe-trip { cursor: grab; touch-action: none; }
.globe-trip.dragging { cursor: grabbing; }
.side {
  min-height: 0;
  overflow-y: auto;
  padding: 8px clamp(16px, 2.4vw, 28px) 28px 0;
}

/* --- The ticket ------------------------------------------------------------- */

.ticket {
  --pad: 24px;
  position: relative;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 16px;
  padding: 22px var(--pad) 22px;
}

.route-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 8px;
}
.end { display: flex; flex-direction: column; min-width: 0; }
.end.to { text-align: right; }
.code {
  font-size: 46px;
  font-weight: 850;
  font-stretch: 125%;
  font-variation-settings: 'wdth' 125;
  line-height: 1;
  letter-spacing: 0.01em;
}
.end.from .code { color: var(--start); }
.end.to .code { color: var(--end); }
.city {
  margin-top: 6px;
  font-size: 17px;
  font-weight: 650;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.place { font-size: 13px; color: var(--ink-soft); line-height: 1.3; }
.route-mark {
  width: 26px;
  height: 24px;
  margin-top: 12px;
  fill: var(--ink);
  opacity: 0.8;
}

/* The tear-off line, with a notch cut from each edge. */
.perforation {
  position: relative;
  margin: 20px calc(-1 * var(--pad)) 18px;
  border-top: 2px dashed var(--rule);
}
.perforation::before, .perforation::after {
  content: '';
  position: absolute;
  top: -12px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--paper);
  border: 1px solid var(--rule);
}
.perforation::before { left: -12px; clip-path: inset(0 0 0 50%); }
.perforation::after { right: -12px; clip-path: inset(0 50% 0 0); }

.status {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 14px;
  min-height: 60px;
}
.hops {
  font-size: 60px;
  font-weight: 850;
  font-stretch: 112%;
  font-variation-settings: 'wdth' 112;
  line-height: 0.9;
  color: var(--blue);
  min-width: 0.6em;
}
.hops-text { font-size: 15px; line-height: 1.35; }
.hops-text b { font-weight: 700; }

/* --- Guessing ---------------------------------------------------------------- */

.guess { position: relative; margin-top: 18px; }
.guess label { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 6px; }
.guess-row { display: flex; gap: 8px; }
.guess input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 18px;
  padding: 11px 14px;
  color: var(--ink);
  background: var(--paper);
  border: 1.5px solid var(--ink);
  border-radius: 10px;
}
.guess input::placeholder { color: var(--ink-soft); opacity: 0.8; }
.guess input:focus-visible { outline-offset: 1px; }
.fly {
  padding: 0 20px;
  border: 0;
  border-radius: 10px;
  background: var(--blue);
  color: var(--on-blue);
  font-weight: 750;
  font-stretch: 112%;
  font-variation-settings: 'wdth' 112;
  font-size: 17px;
  cursor: pointer;
}
.fly:disabled, .guess input:disabled { opacity: 0.55; cursor: default; }

.suggestions {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  top: calc(100% - 4px);
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 12px;
  box-shadow: 0 14px 30px -12px rgba(14, 20, 32, 0.35);
  max-height: 340px;
  overflow-y: auto;
}
.suggestions li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 12px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.suggestions li[aria-selected='true'] { background: var(--paper); }
.opt-name { font-weight: 650; }
.opt-place { grid-column: 1; font-size: 13px; color: var(--ink-soft); }
.opt-code {
  grid-row: 1 / span 2;
  grid-column: 2;
  align-self: center;
  font-weight: 800;
  font-stretch: 125%;
  font-variation-settings: 'wdth' 125;
  font-size: 14px;
  color: var(--ink-soft);
}
.opt-here { color: var(--ink-soft); font-weight: 400; font-size: 13px; }

.note { min-height: 1.4em; margin: 8px 0 0; font-size: 14px; }
.note.miss { color: var(--red); }

.aids { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-top: 4px; }
.link-btn {
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font-size: 14px;
  text-decoration: underline;
  text-decoration-color: var(--rule);
  text-underline-offset: 3px;
  cursor: pointer;
}
.link-btn:hover { color: var(--ink); text-decoration-color: currentColor; }
.link-btn span { font-weight: 650; }
.link-btn.confirm { color: var(--red); text-decoration-color: currentColor; }

/* --- The log of flights ------------------------------------------------------- */

.log {
  list-style: none;
  margin: 22px 0 0;
  padding: 0;
  border-top: 1px solid var(--rule);
}
.log:empty { display: none; }
.log li {
  display: grid;
  grid-template-columns: 16px 1fr auto;
  gap: 0 12px;
  align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px solid var(--rule);
}
.mark {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  align-self: center;
  background: var(--ink-soft);
}
.mark.good { background: var(--good); }
.mark.same { background: var(--same); }
.mark.worse { background: var(--worse); }
.mark.miss { background: none; border: 2px solid var(--miss); }
/* Flights the travel agent booked are round. */
.mark.agent { border-radius: 50%; }
.log .what { font-weight: 650; }
.log .how { display: block; font-size: 13px; color: var(--ink-soft); font-weight: 400; }
.log .time { font-size: 14px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.log li.miss .what { color: var(--red); }
.log li.miss .time { color: var(--red); }

.clock { margin: 12px 0 0; font-size: 14px; color: var(--ink-soft); }
.clock:empty { display: none; }
.clock b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* --- Result ------------------------------------------------------------------- */

.result-title {
  margin: 0 0 14px;
  font-size: 26px;
  font-weight: 800;
  font-stretch: 112%;
  font-variation-settings: 'wdth' 112;
  line-height: 1.15;
}
.figures {
  display: grid;
  grid-template-columns: 0.8fr 1.1fr 1.4fr;
  gap: 12px;
  margin: 0;
}
.figures div { min-width: 0; }
.figures dt { font-size: 12px; color: var(--ink-soft); line-height: 1.25; }
.figures dd {
  margin: 2px 0 0;
  font-size: 26px;
  font-weight: 800;
  font-stretch: 112%;
  font-variation-settings: 'wdth' 112;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 16px 0 0; }
.chips .mark { width: 18px; height: 18px; border-radius: 4px; }
.chips .mark.agent { border-radius: 50%; }
.best { margin: 14px 0 0; font-size: 14px; }
.best:empty { display: none; }
.share {
  width: 100%;
  margin-top: 16px;
  padding: 13px;
  border: 0;
  border-radius: 10px;
  background: var(--blue);
  color: var(--on-blue);
  font-weight: 750;
  font-size: 17px;
  cursor: pointer;
}
.next { margin: 12px 0 0; font-size: 14px; color: var(--ink-soft); text-align: center; }

/* --- Dialogs -------------------------------------------------------------------- */

dialog {
  width: min(460px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  padding: 26px 26px 22px;
  border: 1px solid var(--rule);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
}
dialog::backdrop { background: rgba(14, 20, 32, 0.45); }
dialog h2 {
  margin: 0 0 12px;
  font-size: 24px;
  font-weight: 800;
  font-stretch: 112%;
  font-variation-settings: 'wdth' 112;
}
dialog h3 { margin: 22px 0 10px; font-size: 15px; font-weight: 700; }
dialog p, dialog li { font-size: 15px; }
dialog ul { padding-left: 1.1em; }
dialog li { margin: 6px 0; }
dialog .small { font-size: 13px; color: var(--ink-soft); }
.close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}
.close:hover { background: var(--paper); }
#stats-figures { grid-template-columns: repeat(4, 1fr); }
.opt-place b { font-weight: 600; color: var(--ink); }
.bars { display: grid; gap: 6px; }
.bar-track { display: block; }
.bar-row { display: grid; grid-template-columns: 92px 1fr; gap: 10px; align-items: center; font-size: 14px; }
.bar-fill {
  display: inline-block;
  min-width: 26px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--rule);
  color: var(--ink);
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.bar-fill.today { background: var(--blue); color: var(--on-blue); }

/* The way back to the other games. */
.colophon { margin: 14px 6px 0; font-size: 13px; color: var(--ink-soft); }
.colophon a { color: var(--blue); text-underline-offset: 3px; }

/* --- The end screen: your trip, then everyone's ----------------------------------- */

.everyone-btn {
  width: 100%;
  margin-top: 8px;
  padding: 11px;
  border: 1.5px solid var(--blue);
  border-radius: 10px;
  background: transparent;
  color: var(--blue);
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
}
dialog.end-screen { width: min(540px, calc(100vw - 24px)); overflow-y: auto; }
.end-trip { margin: 0 0 4px; font-size: 14px; color: var(--ink-soft); }
dialog.end-screen h2 { margin-bottom: 6px; text-wrap: balance; outline: none; }
.end-mine { margin: 0; font-size: 15px; }
.end-mine b { font-variant-numeric: tabular-nums; }
.end-everyone { margin-top: 20px; padding-top: 4px; border-top: 2px dashed var(--rule); }
.end-everyone h3 { margin-top: 16px; }
.end-everyone p { margin: 8px 0; }
.end-everyone .quiet { color: var(--ink-soft); }
.end-everyone b { font-variant-numeric: tabular-nums; }
.tally {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 7px 12px;
  align-items: center;
  margin: 14px 0;
  font-size: 14px;
}
.tally .track { height: 16px; border-radius: 4px; background: var(--paper); overflow: hidden; }
.tally .fill { display: block; height: 100%; min-width: 3px; border-radius: 4px; background: var(--rule); }
.tally .n { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.tally .mine { font-weight: 700; color: var(--ink); }
.tally .mine .fill, .tally .fill.mine { background: var(--blue); }
.routes { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.routes li { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; font-size: 14px; }
.routes .names { min-width: 0; overflow-wrap: anywhere; }
.routes .pct { font-weight: 700; font-variant-numeric: tabular-nums; }
.routes .yours { font-size: 12px; color: var(--blue); font-weight: 700; }
.routes .track { grid-column: 1 / -1; height: 5px; border-radius: 3px; background: var(--paper); overflow: hidden; }
.routes .fill { display: block; height: 100%; background: var(--route); }
dialog.end-screen .share { margin-top: 20px; }
.share-text {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--paper);
  font: inherit;
  font-size: 14px;
  white-space: pre-wrap;
  user-select: all;
}

/* --- Phones and narrow windows ---------------------------------------------------- */

@media (max-width: 860px) {
  .layout {
    display: block;
    height: auto;
    min-height: 0;
  }
  .globe { height: min(52vh, 460px); min-height: 280px; }
  .side { padding: 0 12px 28px; overflow: visible; }
  .typing .side { padding-bottom: 70vh; }
  .guess { scroll-margin-top: 10px; }
  .ticket { --pad: 18px; padding: 18px var(--pad); }
  .code { font-size: 40px; }
  .bar { height: 56px; }
  .wordmark { font-size: 23px; }
}

@media (max-width: 380px) {
  .code { font-size: 34px; }
  .hops { font-size: 50px; }
  .edition { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
