/*
 * One full-bleed night canvas; the title and status float top-left, the dock runs along the bottom. On phones the city
 * gets a window of its own and the dock follows it, so the page scrolls down to the legend.
 */
@font-face {
  font-family: "Instrument Serif";
  src: url("fonts/InstrumentSerif-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Instrument Serif";
  src: url("fonts/InstrumentSerif-Italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/JetBrainsMono-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/JetBrainsMono-SemiBold.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

:root {
  --night: #07080d;
  --ink: #f0e7d8;
  --dim: #a39a8a;
  --ember: #ff9a3c;
  --core: #ffe3ad;
  --panel: rgba(13, 14, 21, .82);
  --line: rgba(240, 231, 216, .16);
  --display: "Instrument Serif", Georgia, "Times New Roman", serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --gutter-l: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
  /* Phones: the city's window takes at least this share of the small viewport, and never less than the floor. */
  --screen-h: 100vh;
  --city-share: .6;
  --city-floor: 320px;
  /* Room left under the buttons on the first screen, so the page shows it goes on. */
  --city-peek: 14px;
  color-scheme: dark;
}
@supports (height: 100svh) {
  :root { --screen-h: 100svh; }
}
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--night);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.45;
  overflow: hidden;
}
.app { position: relative; height: 100%; overflow: hidden; }

#city {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#city:active { cursor: grabbing; }
#city:focus-visible { outline: 2px solid var(--core); outline-offset: -2px; }


.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 14px calc(var(--gutter-r) + 56px) 0 var(--gutter-l);
  pointer-events: none;
  text-shadow: 0 1px 10px rgba(0, 0, 0, .9);
}
.hud .title { display: flex; align-items: center; gap: 12px; }
.hud .title button {
  pointer-events: auto;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--dim);
  background: var(--panel);
  text-shadow: none;
}
.hud h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(30px, 6vw, 52px);
  line-height: 1;
  letter-spacing: .005em;
}
.streak, .status {
  margin: 4px 0 0;
  font-family: var(--display);
  font-style: italic;
  font-size: clamp(17px, 3vw, 24px);
  color: var(--core);
}
.streak:empty, .status:empty, .lines p:empty { display: none; }
.hud .lines { margin-top: 6px; font-variant-numeric: tabular-nums; }
.hud .lines p { margin: 0; max-width: 72ch; }
.dim { color: var(--dim); }
/* The watch bar: one segment a block, toned by barSegments in hud.ts. */
.watchbar { margin-top: 8px; max-width: 420px; font-variant-numeric: tabular-nums; }
.watchbar .segs { display: grid; grid-template-columns: repeat(var(--blocks, 21), 1fr); gap: 3px; }
.watchbar .segs i { height: 14px; border-radius: 2px; background: var(--dim); }
.watchbar .segs i.win { background: var(--ember); }
.watchbar .segs i.gone { background: var(--line); }
.watchbar .segs i.win.gone { background: transparent; box-shadow: inset 0 0 0 1px var(--ember); }
.watchbar .segs i.here { outline: 2px solid var(--core); outline-offset: 1px; }
.watchbar .cap { display: flex; justify-content: space-between; gap: 8px; margin: 5px 0 0; }
.watchbar.open .cap span:first-child { color: var(--ember); }
#stoke.pulse:enabled { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 154, 60, .55); } 60% { box-shadow: 0 0 0 10px rgba(255, 154, 60, 0); } }
@media (prefers-reduced-motion: reduce) { #stoke.pulse:enabled { animation: none; } }

.zoom {
  position: absolute;
  top: 14px;
  right: var(--gutter-r);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
button, .button {
  font: inherit;
  color: var(--ink);
  background: rgba(240, 231, 216, .06);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 8px 12px;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.3;
}
button:hover, .button:hover { background: rgba(240, 231, 216, .12); }
button:focus-visible, .button:focus-visible, input:focus-visible, .card:focus-visible {
  outline: 2px solid var(--core);
  outline-offset: 2px;
}
button:disabled { cursor: default; color: var(--dim); background: transparent; }
button.primary { background: var(--ember); border-color: var(--ember); color: #1b0f04; font-weight: 600; }
button.primary:hover { background: #ffae5e; }
button.primary:disabled { background: transparent; border-color: var(--line); color: var(--dim); font-weight: 400; }
button[aria-pressed="true"] { border-color: var(--ember); color: var(--core); background: rgba(255, 154, 60, .14); }
.zoom button { width: 36px; height: 36px; padding: 0; font-size: 18px; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }

/* The dock: what a visitor does, then the legend. */
.dock {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 12px var(--gutter-r) max(14px, env(safe-area-inset-bottom, 0px)) var(--gutter-l);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.says { margin: 0 0 0 6px; color: var(--core); flex: 1 1 220px; }
/* The dock's line sits on its own row under the buttons, so it reads the same at every width. */
.actions .says { margin: 0 0 0 2px; flex: 1 0 100%; }
.says:empty { display: none; }
.legend { margin: 0; max-width: 95ch; color: var(--dim); font-size: 11.5px; text-wrap: pretty; }
.legend b { color: var(--ink); font-weight: 600; }

/* A tower's or the flame's card, above the dock. */
.card {
  position: absolute;
  right: var(--gutter-r);
  bottom: calc(var(--dock-h, 120px) + 12px);
  width: min(380px, calc(100% - 32px));
  max-height: calc(100% - var(--dock-h, 120px) - 172px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-sizing: border-box;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.card .top { display: flex; gap: 12px; align-items: center; padding-right: 36px; min-width: 0; }
.card h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 26px; line-height: 1.05; }
.card .sub { margin: 2px 0 0; color: var(--core); }
.card .tail { margin: 2px 0 0; color: var(--dim); font-size: 11.5px; }
.card dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 3px 14px; font-variant-numeric: tabular-nums; }
.card dl:empty, .card ul:empty, .card .note:empty { display: none; }
.card dt { color: var(--dim); }
.card dd { margin: 0; }
.card ul { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 2px; }
.card ul.marks { color: var(--core); }
.card .history { display: flex; flex-direction: column; gap: 4px; padding-top: 8px; border-top: 1px solid var(--line); }
.card .history h3 { margin: 0; font-family: var(--display); font-style: italic; font-weight: 400; font-size: 18px; line-height: 1.2; color: var(--core); }
.card .history ul { gap: 5px; }
.card .history li { font-variant-numeric: tabular-nums; }
.card .note { margin: 0; color: var(--dim); font-size: 11.5px; overflow-wrap: anywhere; }
.card .btns:not(:has(:is(button, a):not([hidden]))) { display: none; }
#cardSigil { border: 1px solid var(--line); flex: none; image-rendering: pixelated; }
.x { position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; padding: 0; font-size: 16px; }

/* The pay sheet. The invoice QR sits on warm paper, the one bright surface on the page. */
.sheet {
  width: min(420px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  box-sizing: border-box;
  margin: auto;
  padding: 20px 18px 18px;
  color: var(--ink);
  background: #0d0e15;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.45;
}
.sheet::backdrop { background: rgba(3, 3, 6, .72); }
.sheet h2 { margin: 0 40px 12px 0; font-family: var(--display); font-weight: 400; font-size: 28px; line-height: 1.05; }
.sheet section { display: flex; flex-direction: column; gap: 12px; }
.sheet p { margin: 0; }
.sheet .lead { font-family: var(--display); font-style: italic; font-size: 21px; line-height: 1.2; color: var(--core); }
.sheet label { color: var(--dim); }
.sheet input {
  font: inherit;
  color: var(--ink);
  background: rgba(240, 231, 216, .06);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 9px 10px;
  font-variant-numeric: tabular-nums;
}
.sheet .key {
  display: block;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 3px;
  overflow-wrap: anywhere;
  user-select: all;
  -webkit-user-select: all;
  max-height: 7.5em;
  overflow-y: auto;
  font-size: 12px;
}
.sheet .fine { color: var(--dim); font-size: 11.5px; }
.sheet .tail { margin-top: 2px; color: var(--dim); font-size: 11.5px; }
.sheet .tail:empty { display: none; }
.sheet .err { color: var(--ember); }
.sheet .err:empty { display: none; }
.sheet .help { color: var(--ink); }
/* The dock's flex basis would make this line a tall box in the step's column. */
.sheet [data-step="invite"] .says { flex: none; margin: 0; }
/* The note is shown whole before it is sent, so it does not scroll. */
.sheet #inviteNote { max-height: none; }
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choices button { flex: 1 1 0; padding-inline: 6px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.about { width: min(520px, calc(100% - 32px)); }
.about .story { display: flex; flex-direction: column; gap: 10px; }
.about .ask { margin-top: 8px; font-family: var(--display); font-style: italic; font-size: 22px; line-height: 1.2; color: var(--core); }
.about .fine { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); }
/* The News panel: the city's notes read like the status lines, newest first with the newest marked in ember. */
.news { width: min(520px, calc(100% - 32px)); overflow-y: auto; }
.news .msg { margin: 0; color: var(--dim); }
.news .msg:empty, .news .items:empty { display: none; }
.news .items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.news .items li { display: flex; flex-direction: column; gap: 3px; padding-left: 12px; border-left: 1px solid var(--line); }
.news .items li:first-child { border-left-color: var(--ember); }
.news .text { font-family: var(--display); font-style: italic; font-size: 19px; line-height: 1.25; color: var(--core); overflow-wrap: anywhere; }
.news .meta { color: var(--dim); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.news .follow { margin: 16px 0 0; padding-top: 12px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.news .follow .button { flex: none; white-space: nowrap; }
.news .web { color: var(--dim); font-size: 11.5px; }
.news .web:hover { color: var(--ink); }
.news .web:focus-visible { outline: 2px solid var(--core); outline-offset: 2px; }
.qr { align-self: center; padding: 0; line-height: 0; box-shadow: 0 0 0 1px rgba(255, 227, 173, .4), 0 0 42px rgba(255, 154, 60, .28); }
#qr, #phonesQr { image-rendering: pixelated; }
/* The keeper's phones step: a new phone's link above the list of linked phones. */
.sheet .phonelink { display: flex; flex-direction: column; gap: 12px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.sheet h3 { margin: 0; font-family: var(--display); font-style: italic; font-weight: 400; font-size: 18px; line-height: 1.2; color: var(--core); }
.phones { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.phones:empty { display: none; }
.phones li { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-variant-numeric: tabular-nums; }
.phones button { flex: none; padding: 4px 10px; }

/* Fingers need room: 44 px targets on touch and phone-sized screens. */
@media (pointer: coarse), (max-width: 560px) {
  button, .button, .sheet input { min-height: 44px; box-sizing: border-box; }
  .button { display: inline-flex; align-items: center; }
  .zoom button, .x { width: 44px; height: 44px; }
  .hud { padding-right: calc(var(--gutter-r) + 60px); }
}
@media (max-width: 560px) {
  .card { left: var(--gutter-l); right: var(--gutter-r); width: auto; }
  .hud .lines { font-size: 12px; }
  .legend { font-size: 11px; }
}

/* Phones: a guaranteed window for the city, the buttons right under it, the legend below the fold. */
@media (max-width: 640px) {
  :root {
    --city-h: max(var(--city-floor), calc(var(--screen-h) * var(--city-share)), calc(var(--screen-h) - var(--actions-h, 120px) - var(--city-peek)));
  }
  html, body { height: auto; }
  body { overflow: visible; }
  /* A sheet or panel holds the page still behind it. */
  html:has(dialog[open]) { overflow: hidden; }
  .app { height: auto; overflow: visible; overflow-x: clip; }
  #city { position: relative; inset: auto; height: var(--city-h); }
  .hud { padding: 10px var(--gutter-r) 0 var(--gutter-l); }
  .hud .title { gap: 8px; }
  .hud h1 { font-size: 28px; white-space: nowrap; }
  .hud .title button { padding: 4px 8px; }
  .streak { margin-top: 2px; font-size: 18px; line-height: 1.25; }
  .hud .lines { margin-top: 3px; line-height: 1.35; }
  .watchbar { margin-top: 5px; max-width: none; }
  .watchbar .segs i { height: 10px; }
  .watchbar .cap { margin-top: 3px; font-size: 12px; line-height: 1.35; }
  .zoom { top: calc(var(--city-h) - 2 * 44px - 6px - 12px); }
  .dock { position: relative; padding-top: 10px; }
  .actions { gap: 8px; }
  #stoke { order: 1; flex: 1 0 100%; white-space: nowrap; font-size: 12.5px; }
  .says { order: 2; margin: 0; flex-basis: 100%; }
  .card {
    position: fixed;
    bottom: max(12px, env(safe-area-inset-bottom, 0px));
    max-height: calc(var(--screen-h) - 24px);
    /* The dock follows the city in the page here, so the card lies over it and scrolls on its own. */
    z-index: 2;
    background: rgba(13, 14, 21, .96);
    overscroll-behavior: contain;
  }
}
