/* Delve: an endless descent drawn in squares. Black, white and greys only;
 * the board is the page. Chrome follows the minimal family brief: a mono
 * readout at top centre, bare line icons in the bottom corners. */

@font-face {
  font-family: "Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("./fonts/IBMPlexMono-500.woff2") format("woff2");
}
@font-face {
  font-family: "Plex Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("./fonts/IBMPlexSans-400.woff2") format("woff2");
}

:root {
  color-scheme: light;
  --bg: #ffffff;
  --ink: #000000;
  --text: #111111;
  --sub: #5e5e5e;
  --line: #d4d4d4;
  --guide: #8f8f8f;
  --frame: #1c1c1c;
  --band: rgba(0, 0, 0, 0.05);
  --scrim: rgba(255, 255, 255, 0.84);
  --icon: #262626;
  /* The two greys of the floor: in sight, and remembered. */
  --floor: #d9d9d9;
  --fog: #ececec;
  --mono: "Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: "Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #000000;
    --ink: #ffffff;
    --text: #ededed;
    --sub: #a6a6a6;
    --line: #2f2f2f;
    --guide: #8f8f8f;
    --frame: #ededed;
    --band: rgba(255, 255, 255, 0.06);
    --scrim: rgba(0, 0, 0, 0.8);
    --icon: #dddddd;
    --floor: #2e2e2e;
    --fog: #141414;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --ink: #ffffff;
  --text: #ededed;
  --sub: #a6a6a6;
  --line: #2f2f2f;
  --guide: #8f8f8f;
  --frame: #ededed;
  --band: rgba(255, 255, 255, 0.06);
  --scrim: rgba(0, 0, 0, 0.8);
  --icon: #dddddd;
  --floor: #2e2e2e;
  --fog: #141414;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

button { font: inherit; color: inherit; }

/* ---------- top readout ---------- */
.hud {
  position: fixed;
  top: max(6px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 36px;
  padding: 0 10px;
  font: 500 13px/1 var(--mono);
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--sub);
  white-space: nowrap;
  pointer-events: none;
}
.hud svg { width: 14px; height: 14px; flex: none; }
.hud-depth { display: inline-flex; align-items: center; gap: 4px; }
/* Health: a row of squares, filled while you have it. */
.hud-hp { display: inline-flex; gap: 3px; }
.hud-hp i { display: block; width: 9px; height: 9px; border: 1.5px solid var(--sub); }
.hud-hp i.on { background: var(--sub); }

/* ---------- board ---------- */
.board {
  position: fixed;
  inset: 0;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  cursor: pointer;
  outline: none;
}
.board:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }
#map {
  position: absolute;
  left: 0; top: 0;
  transform-origin: 0 0;
  transition: transform 0.7s cubic-bezier(0.3, 0.7, 0.2, 1);
}
#map.instant { transition: none; }

/* ---------- strip: one line, only when something is new ---------- */
.strip {
  position: fixed;
  z-index: 4;
  left: 0; right: 0;
  margin: 0 auto;
  width: min(100%, 560px);
  bottom: calc(60px + env(safe-area-inset-bottom));
  padding: 8px max(16px, env(safe-area-inset-right)) 4px max(16px, env(safe-area-inset-left));
  text-align: center;
  pointer-events: none;
}
.strip p {
  margin: 0;
  font: 400 17px/22px var(--sans);
  color: var(--sub);
  text-wrap: pretty;
}
.strip p:empty { display: none; }

/* ---------- corner icons ---------- */
.bar {
  position: fixed;
  left: max(6px, env(safe-area-inset-left));
  right: max(6px, env(safe-area-inset-right));
  bottom: max(6px, env(safe-area-inset-bottom));
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
}
.group { display: flex; gap: 2px; pointer-events: auto; }
.ib {
  appearance: none;
  position: relative;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--icon);
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity 0.15s, transform 0.1s;
}
.ib svg { width: 24px; height: 24px; }
.ib:active { transform: scale(0.94); }
.ib[aria-disabled="true"] { opacity: 0.32; cursor: default; }
.ib .count {
  position: absolute;
  right: 6px; bottom: 6px;
  font: 500 11px/1 var(--mono);
  color: var(--icon);
}
.ib.pulse { animation: hint-pulse 1.2s ease-in-out 3; }
@keyframes hint-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.15; }
}
.ib:focus-visible, .text-action:focus-visible, .size-choice:focus-visible, .sheet-x:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}
@media (hover: hover) {
  .ib:hover:not([aria-disabled="true"]) { background: var(--band); }
}

/* Landscape phones: the bar becomes a right rail; the strip sits beside it. */
@media (max-height: 500px) and (orientation: landscape) {
  .bar {
    left: auto; top: 0; bottom: 0;
    right: 0;
    width: calc(64px + env(safe-area-inset-right));
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) 0;
    border-left: 1px solid var(--line);
    background: var(--bg);
  }
  .group { flex-direction: column; }
  .strip { right: calc(64px + env(safe-area-inset-right)); bottom: env(safe-area-inset-bottom); width: auto; }
  .hud { left: calc(50% - 32px); }
}

/* ---------- sheets ---------- */
dialog.sheet {
  width: min(32rem, calc(100vw - 16px));
  max-width: none;
  max-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  height: fit-content;
  padding: 0; margin: auto;
  border: 1px solid var(--frame);
  border-radius: 0;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
dialog.sheet[open] { display: block; }
dialog.sheet::backdrop { background: var(--scrim); }
.sheet-in { max-height: calc(100dvh - 18px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); display: flex; flex-direction: column; min-height: 0; width: 100%; font: 400 16px/1.45 var(--sans); }
.sheet-head { display: flex; flex: none; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--line); }
.sheet-head form { margin: 0; }
.sheet h2 { margin: 0; font: 500 16px/1.3 var(--mono); }
.sheet-x { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; background: none; color: var(--text); cursor: pointer; }
.sheet-x svg { width: 24px; height: 24px; }
.sheet-body { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 20px 24px; }
.sheet p { margin: 0 0 16px; }
.sheet h3 { margin: 0 0 8px; font: 500 1em/1.4 var(--sans); }
.sheet section + section { border-top: 1px solid var(--line); margin-top: 20px; padding-top: 20px; }
.sheet .sizes { display: flex; flex-wrap: wrap; gap: 4px; }
.text-action, .size-choice {
  appearance: none; min-width: 44px; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 0;
  background: none; color: var(--text); font: 500 16px/1.3 var(--mono); cursor: pointer; touch-action: manipulation;
}
.size-choice { padding: 8px; border-color: transparent; color: var(--sub); }
.size-choice[aria-pressed="true"] { border-color: var(--frame); color: var(--ink); }
.text-action:hover, .size-choice:hover { background: var(--band); }
.setting-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px; min-height: 44px; margin-top: 4px; }
.setting-row .value { font: 500 16px/1.3 var(--mono); color: var(--sub); }
.sheet-foot { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 20px; }
.foot-btn { display: inline-flex; align-items: center; min-height: 44px; font: 400 16px/1.4 var(--sans); color: var(--sub); text-underline-offset: 3px; background: none; border: 0; cursor: pointer; }

/* Controls, at a glance: `Tap — steps that way`. */
.controls { margin: 16px 0 0; padding-top: 12px; border-top: 1px solid var(--line); display: grid; gap: 6px; }
.controls div { display: flex; flex-wrap: wrap; gap: 0 8px; }
.controls dt { color: var(--text); }
.controls dt::after { content: " \2014"; color: var(--sub); }
.controls dd { margin: 0; color: var(--sub); }
kbd { font: 500 15px/1 var(--mono); }

/* The board's marks, drawn once in the Help sheet. */
.key { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 16px 0 0; padding-top: 12px; border-top: 1px solid var(--line); color: var(--sub); }
.key span { display: inline-flex; align-items: center; gap: 8px; }
.key i { display: inline-grid; place-items: center; width: 22px; height: 22px; background: var(--floor); position: relative; }
.key i::before { content: ""; display: block; }
.key .k-you::before { width: 14px; height: 14px; border: 2px solid var(--ink); }
.key .k-foe::before { width: 12px; height: 12px; background: var(--ink); }
.key .k-mark::before { width: 14px; height: 14px; background:
  linear-gradient(45deg, transparent 44%, var(--ink) 44%, var(--ink) 56%, transparent 56%),
  linear-gradient(-45deg, transparent 44%, var(--ink) 44%, var(--ink) 56%, transparent 56%); }
.key .k-stairs::before { width: 9px; height: 9px; border: 2px solid var(--ink); border-top: 0; border-left: 0; transform: translateY(-2px) rotate(45deg); }
.key .k-flask::before { width: 9px; height: 9px; border: 2px solid var(--ink); transform: rotate(45deg); }

@media (max-width: 480px) { .sheet-body { padding: 16px; } .sheet-head { padding: 8px 12px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }
@media (forced-colors: active) {
  :root { --ink: CanvasText; --text: CanvasText; --bg: Canvas; --line: GrayText; --guide: GrayText; --frame: CanvasText; --icon: ButtonText; --floor: GrayText; --fog: Canvas; }
  .key i { forced-color-adjust: none; }
}
