/* Delve: an endless descent drawn in squares. Black, white and grays only;
 * the board is the page. Chrome follows the minimal family brief: a mono
 * readout at top center, 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 grays of the floor: in sight, and remembered. Walls are a rule
     along the floor's edge, darker in sight. A resting enemy, and a strike
     that has fallen, are drawn in --rest. */
  --floor: #d9d9d9;
  --fog: #ececec;
  --wall: #6f6f6f;
  --wall-fog: #bdbdbd;
  --rest: #666666;
  --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;
    --wall: #9a9a9a;
    --wall-fog: #4a4a4a;
    --rest: #8c8c8c;
  }
}
: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;
  --wall: #9a9a9a;
  --wall-fog: #4a4a4a;
  --rest: #8c8c8c;
}

*, *::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); }
/* What you carry: a blade and a bow, a line glyph and a count each. */
.hud-gear { display: inline-flex; align-items: center; gap: 3px; }
.hud-gear[hidden] { display: none; }
.hud-gear svg { width: 14px; height: 14px; }

/* ---------- board ---------- */
.board {
  position: fixed;
  inset: 0 max(0px, env(safe-area-inset-right)) 0 max(0px, env(safe-area-inset-left));
  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; }

/* ---------- the end of a run: one boxed arrow, as the other Minimal games end ----------
 * The board fills the page, so the arrow stands where there is always room:
 * centered on the toolbar's row between its two groups, as the shared frame
 * places a Next disc when no gap is left beside the board. The outcome line
 * stays in the strip just above it. */
body { --control-next-bottom: max(6px, env(safe-area-inset-bottom)); }
.completion {
  position: fixed;
  z-index: 5;
  left: 50%;
  bottom: var(--control-next-bottom);
  transform: translateX(-50%);
  display: flex;
  justify-content: center;
  animation: next-reveal 0.45s 0.15s both;
}
.completion[hidden] { display: none; }
/* The shared frame clears borders on its icons, so the box is an outline. */
#next-btn { outline: 1px solid var(--ink); outline-offset: -1px; }
@keyframes next-reveal {
  from { opacity: 0; translate: 0 4px; }
  to { opacity: 1; translate: 0 0; }
}

/* ---------- 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: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.
 * The same query as the shared control frame's, so the two agree. */
@media (max-height: 520px) and (min-width: 560px) {
  .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; }
  /* Here the toolbar is a column at the right: the arrow stands in it, centered between its groups. */
  body { --control-next-left: calc(100% - 32px - max(8px, env(safe-area-inset-right))); --control-next-bottom: calc(50% - 24px); }
  .completion { left: var(--control-next-left); }
  .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-mark::before, .key .k-heavy::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-heavy::before { background:
  linear-gradient(45deg, transparent 36%, var(--ink) 36%, var(--ink) 64%, transparent 64%),
  linear-gradient(-45deg, transparent 36%, var(--ink) 36%, var(--ink) 64%, transparent 64%); }
.key .k-rest::before { width: 10px; height: 10px; border-radius: 50%; background: var(--rest); }
.key i svg { width: 18px; height: 18px; }
.key .k-hit { background: var(--ink); }
.key .k-hit::before { width: 14px; height: 14px; border: 2px solid var(--bg); }
.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); }

/* The three enemies and the three things to find, drawn as on the board. */
.foes { margin: 16px 0 0; padding-top: 12px; border-top: 1px solid var(--line); display: grid; gap: 12px; }
.foes figure { margin: 0; display: grid; grid-template-columns: 92px 1fr; align-items: center; gap: 12px; }
.foes svg { width: auto; height: 28px; justify-self: start; }
.foes .tall svg { height: 56px; }
.foes figcaption { color: var(--sub); }
.foes b { color: var(--text); font-weight: 400; }
.f-floor { fill: var(--floor); }
.f-ink { fill: var(--ink); }
.f-ring, .f-line { fill: none; stroke: var(--ink); stroke-width: 2; }
.f-mark { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; }
.f-heavy { fill: none; stroke: var(--ink); stroke-width: 4; stroke-linecap: round; }

@media (max-width: 480px) { .sheet-body { padding: 16px; } .sheet-head { padding: 8px 12px; } .foes figure { grid-template-columns: 76px 1fr; } }
@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; --rest: GrayText; --wall: CanvasText; --wall-fog: GrayText; }
  .key i, .foes svg { forced-color-adjust: none; }
}
