/* Variables, page layout, panels and the shared button styles.
 *
 * One of the stylesheets split out of the old style.css. index.html links them
 * in the order they had in that file, so the cascade is unchanged - keep
 * that order when adding a rule, or a later sheet may win where it used to lose. */

:root {
  /* The edges controls keep inside: a phone's safe area, but on the side away
     from the Dynamic Island (js/safe-edges.js marks which side it is) only
     enough to clear the rounded corner. Held sideways, iOS reports the same
     inset on both sides though the notch or island is on one; on every iPhone
     from the X on, the screen's corner radius R is close to that inset, and a
     rectangle in such a corner is wholly on screen once it stands R(1 - 1/sqrt
     2), about 0.3R, in from both edges. So the far side gives up --side-trim,
     0.7 of the inset - but only when both sides report the same inset. Where
     they differ the insets are each side's own (Android: a cutout on one side,
     a button bar on the other) and are kept as reported: the trim falls to
     nothing a hundred times faster than the sides part. The top and bottom
     corners are the town's and HUD's own to clear (tools/verify-edge-to-edge.js
     measures them against the outline of each iPhone shape). */
  --edge-top: env(safe-area-inset-top);
  --edge-right: env(safe-area-inset-right);
  --edge-bottom: env(safe-area-inset-bottom);
  --edge-left: env(safe-area-inset-left);
  --side-trim: max(0px, min(env(safe-area-inset-left), env(safe-area-inset-right)) * 0.7
    - max(env(safe-area-inset-left) - env(safe-area-inset-right), env(safe-area-inset-right) - env(safe-area-inset-left)) * 100);
  /* The screen less a phone's notch, status bar and home bar (all zero on a
     desktop): what a window may fill. See "edge to edge" below. */
  --safe-vw: calc(100vw - var(--edge-left) - var(--edge-right));
  --safe-dvh: calc(100dvh - var(--edge-top) - var(--edge-bottom));
  --ink: #0b0d10;
  --coal: #15191c;
  --stone: #252a2e;
  --stone-light: #3b4143;
  --parchment: #e5d6b3;
  --muted: #998f78;
  --gold: #c89948;
  --gold-dark: #6f4b22;
  --crimson: #b94343;
  --crimson-dark: #4b171b;
  --moss: #6f9e4f;
  --ember: #d96a2b;
  --panel: rgba(11, 13, 16, 0.94);
  /* One frame per window. Inside it, sections are told apart by space and a
     thin rule, rows by a faint fill, and only what can be pressed has an edge.
     It used to be gold boxes inside gold boxes inside the window's own. */
  --rule: rgba(200, 153, 72, 0.16);
  --row: rgba(255, 255, 255, 0.025);
  --row-hover: rgba(255, 255, 255, 0.05);
  --edge: rgba(200, 153, 72, 0.24);
  --edge-strong: rgba(200, 153, 72, 0.55);
  --empty-edge: rgba(153, 143, 120, 0.28);
  /* Under a panel's gold border: a dark hairline and a soft shadow. It was
     three more solid rings and a hard offset shadow - four frames per panel. */
  --pixel-shadow: 0 0 0 1px #08090a, 0 10px 28px rgba(0, 0, 0, 0.55);
}
:root[data-island="left"] { --edge-right: calc(env(safe-area-inset-right) - var(--side-trim)); }
:root[data-island="right"] { --edge-left: calc(env(safe-area-inset-left) - var(--side-trim)); }

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--ink);
  color: var(--parchment);
  font-family: Consolas, "Lucida Console", "Courier New", monospace;
  font-weight: 700;
  letter-spacing: 0.03em;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* Pixel icons (js/icons.js), drawn on a 9px grid: 9px, or a whole multiple
 * of it, or the pixels smear. */
.px-icon { display: inline-block; flex: none; width: 9px; height: 9px; fill: currentColor; vertical-align: -1px; }
.px-icon.x2 { width: 18px; height: 18px; vertical-align: -4px; }
.px-icon.x3 { width: 27px; height: 27px; vertical-align: middle; }
/* Inked utility symbols share the text colour, with room for open counters. */
.utility-icon { display: inline-block; flex: none; width: 24px; height: 24px; fill: none; vertical-align: middle; pointer-events: none; }
/* An empty gear slot: the Recruit's piece for it, flattened to a shadow. */
.gear-silhouette { filter: brightness(0) invert(0.3); opacity: 0.5; }

#game-container {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--ink);
}
/* Added to an iPhone's home screen, the page opened with a black bar across
 * the top, held upright, until the phone had been turned a few times. iOS
 * gets the screen wrong on a cold start there: a page whose html and body are
 * 100% high can fall back to the layout that stops under the status bar, and
 * 100dvh is wrong until a turn makes it look again; 100vh is right from the
 * first frame, and in an app with no browser bars it is the whole screen.
 * (Reported by developers, not documented by Apple: the guide is
 * gist.github.com/fozzedout/5e77925381991a9570151550992baf14.) A browser tab
 * keeps 100dvh, the height its own bars leave. js/safe-edges.js also nudges
 * iOS to measure again once the page is up. */
@media (display-mode: standalone), (display-mode: fullscreen) {
  html, body, #game-container { height: 100vh; }
}

/* Edge to edge. The picture runs under a phone's notch and into its rounded
 * corners; what is pressed or read stays inside the safe area. The whole game
 * used to be padded in by the safe area, and on an iPhone held sideways - most
 * of all added to the home screen, with no browser bars - that left a strip of
 * ink down each side and along the foot.
 * So the canvas fills the screen and the overlay is inset instead: every HUD
 * position inside it is measured from the same edges as before. A layer in
 * the overlay that paints the whole screen (the town, the guide's dimming)
 * reaches back out by the same amounts - see #city-ui and #onboarding-overlay.
 * The top counts too: added to a home screen the page runs under the status
 * bar (index.html), and upright that is the notch and the clock. */
#viewport { position: relative; width: 100%; height: 100%; overflow: hidden; }
canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
#ui-overlay {
  position: absolute;
  top: var(--edge-top);
  left: var(--edge-left);
  right: var(--edge-right);
  bottom: var(--edge-bottom);
  pointer-events: none;
}
/* Beside the overlay rather than in it: the same inset, as a margin, keeps
 * each one where its own rules put it. Only the sides they are placed from
 * take effect. */
#btn-report-field, #btn-chat-field, #chat-feed {
  margin: var(--edge-top) var(--edge-right) var(--edge-bottom) var(--edge-left);
}
.hidden { display: none !important; }

.pixel-panel {
  color: var(--parchment);
  background: linear-gradient(180deg, rgba(255,255,255,0.035), transparent 38%), var(--panel);
  border: 2px solid var(--gold);
  border-radius: 2px;
  box-shadow: var(--pixel-shadow);
}

/* ---------- shared buttons ---------- */

button {
  min-width: 48px;
  min-height: 48px;
  padding: 11px 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  color: var(--parchment);
  background: linear-gradient(180deg, rgba(255,255,255,0.07), transparent 42%), #202528;
  /* One edge - the gold outline, which the button's states recolour - and a
     shadow to sit on. There were four: a dark border, the outline, an inner
     bevel and a hard offset shadow, on every button in the game. */
  border: 1px solid #111416;
  border-radius: 2px;
  outline: 2px solid var(--gold-dark);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
  cursor: pointer;
  font: inherit;
  font-size: 15px;
  text-transform: uppercase;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

button:hover:not(:disabled) { color: #fff3d3; background-color: #30373a; outline-color: var(--gold); }
button:focus-visible { outline: 3px solid #f1c66f; outline-offset: 3px; }
button:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.45);
}
button:disabled { opacity: 0.42; cursor: default; }

.primary {
  color: #fff3d3;
  background: linear-gradient(180deg, rgba(255,255,255,0.09), transparent 42%), #705022;
  outline-color: var(--gold);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
}
.primary:hover:not(:disabled) { background-color: #8b6328; }
.danger { background-color: var(--crimson-dark); outline-color: #8d3337; box-shadow: 0 2px 0 rgba(0, 0, 0, 0.45); }
.glyph { font-size: 22px; line-height: 1; text-shadow: 2px 2px 0 #000; }
.turn-left,
.turn-right { font-size: 29px; transform: none; }
