/* Jet Stream: ink on parchment over the sky (SPEC §2). */
:root {
  color-scheme: light;
  --paper: rgba(250, 243, 226, .9);
  --paper-solid: #faf3e2;
  --edge: rgba(70, 52, 38, .22);
  --ink: #2f2730;
  --dim: #7a6a5c;
  --post: #c4402c;
  --sky: #2f6fa8;
  --serif: "Fraunces", "Iowan Old Style", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --st: env(safe-area-inset-top, 0px);
  --sr: env(safe-area-inset-right, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --sl: env(safe-area-inset-left, 0px);
}
html, body { margin: 0; height: 100%; overflow: hidden; background: #cfe5f2; color: var(--ink); font-family: var(--serif); user-select: none; -webkit-user-select: none; }
#view, #hud { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#view { touch-action: none; cursor: grab; }
#hud { pointer-events: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
kbd { font: 600 11px var(--mono); background: rgba(47, 39, 48, .08); border: 1px solid rgba(47, 39, 48, .25); border-radius: 3px; padding: 1px 5px; white-space: nowrap; }
.card { box-sizing: border-box; background: var(--paper); border: 1px solid var(--edge); border-radius: 4px; padding: 10px 14px; box-shadow: 0 2px 10px rgba(60, 40, 20, .18); }
.route { font: 600 10px var(--mono); letter-spacing: .16em; text-transform: uppercase; color: var(--post); }
.k { font: 600 9.5px var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--dim); }
.v { font: 600 16px var(--mono); font-variant-numeric: tabular-nums; }

#docket { position: fixed; top: calc(14px + var(--st)); left: calc(14px + var(--sl)); max-width: 230px; }
#docket .name { font: 700 17px/1.15 var(--serif); margin: 3px 0 6px; }
#docket .row { display: flex; align-items: baseline; gap: 8px; padding-top: 5px; border-top: 1px dashed var(--edge); }

#fade { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
#toast { position: fixed; left: 50%; bottom: calc(26px + var(--sb)); transform: translate(-50%, 8px); width: max-content; max-width: min(520px, calc(100vw - 28px));
  font-size: 15px; font-style: italic; line-height: 1.35; text-align: center; opacity: 0; transition: opacity .4s, transform .4s; pointer-events: none; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }

.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; box-sizing: border-box;
  background: rgba(207, 229, 242, .35); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); overflow-y: auto; }
.sheet { width: min(560px, 100%); padding: 22px 26px; max-height: calc(100vh - 32px); overflow-y: auto; }
.sheet.small { width: min(360px, 100%); }
.sheet h1 { font: 700 46px/1 var(--serif); margin: 6px 0 10px; letter-spacing: -.01em; }
.sheet h2 { font: 700 28px/1 var(--serif); margin: 0 0 14px; }
.lede { font-size: 16px; line-height: 1.5; margin: 0 0 16px; max-width: 62ch; }
.note { font-size: 13px; line-height: 1.5; color: var(--dim); font-style: italic; margin: 14px 0 0; }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }
.buttons button, .setting button { background: transparent; border: 1px solid rgba(47, 39, 48, .35); border-radius: 3px; padding: 8px 14px; font: 600 12px var(--mono); }
.buttons button.primary, .setting button.on { background: var(--ink); color: var(--paper-solid); border-color: var(--ink); }
.buttons button:hover { border-color: var(--ink); }
.keys { border-collapse: collapse; width: 100%; font-size: 14px; line-height: 1.4; }
.keys td { padding: 5px 0; border-top: 1px dashed var(--edge); vertical-align: top; }
.keys td:first-child { width: 112px; padding-right: 10px; }
.setting { display: flex; align-items: center; gap: 6px; margin-top: 14px; }
.setting .k { margin-right: 6px; }

@media (max-width: 720px) {
  #docket { max-width: 170px; padding: 8px 10px; }
  #docket .name { font-size: 14px; }
  .sheet { padding: 18px 18px; }
  .sheet h1 { font-size: 36px; }
  .lede { font-size: 15px; }
}
.touch-only { display: none; }
@media (pointer: coarse) { .touch-only { display: block; color: var(--post); } }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

/* ---------- phase 3: the post ---------- */
.sheet.wide { width: min(760px, 100%); }
.lede.small { font-size: 14px; margin: 0; }
.buttons.end { margin: 18px 0 0; }
#docket .bag { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0 0 7px; }
#docket .bag[hidden] { display: none; }
.bag-item svg { width: 20px; height: 16px; fill: var(--paper-solid); stroke: var(--ink); stroke-width: 1.4; display: block; }
.bag-item.done svg { fill: var(--post); stroke: var(--post); opacity: .45; }
.bag-item.broken svg { stroke: var(--post); stroke-dasharray: 2 2; }
.bag .bundles { margin-left: 2px; }
#clock.over { color: var(--post); }
#docket .row .k:last-child { margin-left: auto; }

/* the board: routes pinned up as dockets */
.routes { display: grid; grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); gap: 14px; margin: 6px 0 18px; }
.docket { position: relative; display: flex; flex-direction: column; gap: 4px; min-height: 128px; text-align: left; padding: 16px 12px 12px; background: var(--paper-solid);
  border: 1px solid var(--edge); border-radius: 2px; box-shadow: 0 2px 6px rgba(60, 40, 20, .2); transform: rotate(-1deg); transition: transform .15s, box-shadow .15s; }
.docket:nth-child(even) { transform: rotate(1.2deg); }
.docket::before { content: ""; position: absolute; top: 6px; left: 50%; width: 9px; height: 9px; margin-left: -4.5px; border-radius: 50%; background: var(--post); box-shadow: 0 1px 2px rgba(0, 0, 0, .35); }
.docket:not(.shut):hover, .docket:not(.shut):focus-visible { transform: rotate(0) translateY(-2px); box-shadow: 0 6px 14px rgba(60, 40, 20, .25); outline: none; }
.docket.shut { opacity: .5; cursor: default; }
.d-title { font: 700 18px/1.15 var(--serif); }
.d-teach { font-size: 13px; line-height: 1.35; color: var(--dim); font-style: italic; }
.d-new { margin-top: auto; }
.mini-stamp { margin-top: auto; align-self: flex-start; display: inline-flex; flex-direction: column; padding: 3px 7px; border: 2px solid currentColor; border-radius: 3px;
  font: 700 10px var(--mono); letter-spacing: .1em; text-transform: uppercase; transform: rotate(-4deg); }
.mini-stamp small { font-weight: 600; letter-spacing: .04em; opacity: .85; }
.stamp-first { color: var(--post); } .stamp-second { color: var(--sky); } .stamp-delivered { color: #3f7a4a; } .stamp-late { color: var(--dim); }
.keys-box { margin: 4px 0 0; }
.keys-box summary { cursor: pointer; padding: 4px 0; }

/* the docket for a route */
.items { display: flex; flex-direction: column; gap: 6px; margin: 0 0 14px; }
.items[hidden] { display: none; }
.item { display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 10px; padding: 7px 0; border-top: 1px dashed var(--edge); font-size: 15px; }
.item svg, .items-table svg { width: 22px; height: 17px; fill: var(--paper-solid); stroke: var(--ink); stroke-width: 1.4; }
.facts { display: grid; gap: 0; margin: 0; }
.facts > div { display: grid; grid-template-columns: 110px 1fr; gap: 10px; padding: 6px 0; border-top: 1px dashed var(--edge); }
.facts dt { padding-top: 3px; }
.facts dd { margin: 0; font-size: 14.5px; line-height: 1.4; }
.free .setting:first-child { margin-top: 16px; }

/* the receipt */
.receipt-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.receipt-head > div:first-child { min-width: 0; }
.receipt-head h2 { margin: 4px 0 6px; }
.stamp { flex: none; width: 128px; height: 128px; border-radius: 50%; border: 3px double currentColor; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; transform: rotate(-11deg); box-sizing: border-box; padding: 10px; position: relative; }
.stamp::after { content: ""; position: absolute; inset: 7px; border-radius: 50%; border: 1px solid currentColor; opacity: .7; }
.stamp-top, .stamp-bottom { font: 600 8.5px var(--mono); letter-spacing: .16em; text-transform: uppercase; }
.stamp-mark { font: 700 19px/1.05 var(--serif); margin: 6px 0; text-transform: uppercase; letter-spacing: .02em; }
.receipt-body { display: grid; grid-template-columns: minmax(0, 1fr) 240px; gap: 20px; margin-top: 16px; align-items: start; }
.items-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.items-table td { padding: 7px 0; border-top: 1px dashed var(--edge); vertical-align: top; font-size: 14.5px; line-height: 1.35; }
.items-table td.ic { width: 32px; }
.items-table td.score { width: 44px; text-align: right; font: 700 18px var(--mono); }
.items-table .said { color: var(--dim); font-size: 13px; }
.items-table tr.undone b { color: var(--post); }
.why { list-style: none; padding: 0; margin: 12px 0 0; font-size: 13.5px; line-height: 1.45; }
.why li:not(.k)::before { content: "· "; color: var(--post); font-weight: 700; }
.chart { width: 100%; max-width: 240px; aspect-ratio: 1; border: 1px solid var(--edge); border-radius: 2px; }

@media (max-width: 720px) {
  .receipt-body { grid-template-columns: 1fr; }
  .chart { max-width: 260px; }
  .stamp { width: 104px; height: 104px; }
  .stamp-mark { font-size: 16px; }
  .facts > div { grid-template-columns: 92px 1fr; }
  .routes { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}

/* ---------- phase 4: the chart, and free flight's choices ---------- */
.setting.wrap { align-items: flex-start; }
.setting.wrap .k { padding-top: 9px; min-width: 44px; }
.choices { display: flex; flex-wrap: wrap; gap: 6px; }
.choices button { background: transparent; border: 1px solid rgba(47, 39, 48, .35); border-radius: 3px; padding: 8px 12px; font: 600 12px var(--mono); }
.choices button.on { background: var(--ink); color: var(--paper-solid); border-color: var(--ink); }
.chart-sheet { width: min(1100px, 100%); padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.chart-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.chart-head .note { margin: 4px 0 0; max-width: 60ch; }
.chart-head .buttons { margin: 0; }
.buttons button.on { border-color: var(--ink); box-shadow: inset 0 -2px 0 var(--ink); }
#c-canvas { width: 100%; height: min(68vh, 640px); border: 1px solid var(--edge); border-radius: 2px; display: block; }
.fragile { font: 600 10px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--post); border: 1px solid currentColor; border-radius: 3px; padding: 1px 4px; margin-left: 6px; vertical-align: 2px; white-space: nowrap; }

/* ---------- phase 5: phones ---------- */
#docket .fps { padding-top: 4px; }
#settings .setting.wrap .k { min-width: 92px; }
#settings .note { margin: 6px 0 0; }
p.how { font-size: 14px; line-height: 1.45; margin: 0 0 12px; max-width: 62ch; }
@media (pointer: coarse) { p.how { color: var(--ink); } .keys-box { display: none; } }
/* the controls, shown on a touch screen while flying */
#touch { display: none; }
body.touch.playing #touch { display: block; }
#t-zone { position: fixed; left: 0; bottom: 0; width: 48vw; height: 62vh; touch-action: none; }
#t-stick { position: fixed; left: calc(24px + var(--sl)); bottom: calc(24px + var(--sb)); width: 130px; height: 130px; border-radius: 50%; box-sizing: border-box;
  border: 1.5px solid rgba(47, 39, 48, .35); background: rgba(250, 243, 226, .35); opacity: .7; pointer-events: none; }
#t-stick.on { opacity: 1; }
#t-knob { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%; background: var(--paper); border: 1.5px solid var(--ink); box-sizing: border-box; }
body.tilt #t-zone, body.tilt #t-stick { display: none; }
#t-tilt { display: none; position: fixed; left: calc(24px + var(--sl)); bottom: calc(44px + var(--sb)); width: 84px; height: 84px; border-radius: 50%; border: 1.5px dashed rgba(47, 39, 48, .45); pointer-events: none; }
body.tilt #t-tilt { display: block; }
#t-tilt span { position: absolute; left: 0; right: 0; bottom: -20px; text-align: center; font: 600 10px var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--dim); }
#t-dot { position: absolute; left: 50%; top: 50%; width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%; background: var(--ink); }
#t-brake { position: fixed; right: calc(20px + 138px + 12px + var(--sr)); bottom: calc(24px + var(--sb)); width: 46px; height: 166px; border-radius: 6px; box-sizing: border-box;
  border: 1px solid rgba(47, 39, 48, .35); background: var(--paper); overflow: hidden; touch-action: none; }
#t-brake.on { border-color: var(--ink); }
#t-fill { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: rgba(47, 111, 168, .38); }
#t-brake span { position: absolute; left: 0; right: 0; top: 8px; text-align: center; font: 600 8.5px var(--mono); letter-spacing: .04em; text-transform: uppercase; }
#t-buttons { position: fixed; right: calc(20px + var(--sr)); bottom: calc(24px + var(--sb)); display: grid; grid-template-columns: repeat(2, 64px); gap: 10px; }
#t-buttons button { height: 44px; border-radius: 6px; border: 1px solid rgba(47, 39, 48, .35); background: var(--paper); font: 600 11px var(--mono); letter-spacing: .06em; text-transform: uppercase; touch-action: none; padding: 0; }
#t-buttons #t-motor { grid-column: span 2; height: 58px; font-size: 12px; }
#t-motor.on { background: var(--ink); color: var(--paper-solid); border-color: var(--ink); }
#t-motor.flat { opacity: .5; }
#t-drop.ready { background: var(--post); color: var(--paper-solid); border-color: var(--post); }
body:not(.letters) #t-drop { visibility: hidden; }
/* the words that come up stay clear of the controls */
@media (pointer: coarse) and (orientation: portrait) { body.touch.playing #toast { bottom: calc(214px + var(--sb)); } }
@media (pointer: coarse) and (orientation: landscape) { body.touch.playing #toast { bottom: calc(14px + var(--sb)); max-width: calc(100vw - 2 * (236px + max(var(--sl), var(--sr)))); font-size: 14px; } }
@media (pointer: coarse) { #s-steer-row.touch-only { color: inherit; } }

/* ---------- phase 6: the replay ---------- */
#replay { position: fixed; left: 50%; bottom: calc(14px + var(--sb)); transform: translateX(-50%); width: min(780px, calc(100vw - 28px - var(--sl) - var(--sr))); }
.replay-bar { display: flex; flex-direction: column; gap: 8px; padding: 10px 14px; }
.rp-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.rp-row button { background: transparent; border: 1px solid rgba(47, 39, 48, .35); border-radius: 3px; padding: 6px 10px; font: 600 11.5px var(--mono); }
.rp-row button.primary, .rp-row .choices button.on { background: var(--ink); color: var(--paper-solid); border-color: var(--ink); }
.rp-row .choices { gap: 4px; }
.rp-row .choices button { padding: 6px 8px; }
#rp-play { min-width: 64px; }
#rp-time { margin-right: 6px; font-variant-numeric: tabular-nums; }
#rp-seek { width: 100%; accent-color: var(--post); }
body.replay #toast { bottom: calc(150px + var(--sb)); }
.choices button:disabled { opacity: .4; cursor: not-allowed; }
