/* Jackrabbit Text Adventure — minimal monospace shell */

:root {
  --bg: #0c0d10;
  --fg: #d8d8d2;
  --dim: #8a8a82;
  --accent: #f0c674;
  --echo: #7fa9c7;
  --death: #d27b7b;
  --bar-bg: #16181c;
  --bar-fg: #c8c8c2;
  --border: #2a2c31;
  --font: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
  --font-size: 15px;
  --line-height: 1.45;
  --letter-spacing: normal;
  --word-spacing: normal;
}

/* ---- Colour schemes (Irlen / dyslexia friendly) -------------------------- */
/* `dark` is the :root default above, so it needs no override block. Each
   scheme only re-declares the custom properties; every rule below reads
   through them, so switching `data-theme` recolours the page in place. */

:root[data-theme="dark-soft"] {
  --bg: #1b1d22;
  --fg: #c4c6c0;
  --dim: #8b8d86;
  --accent: #d8b870;
  --echo: #8fb0c4;
  --death: #cf9090;
  --bar-bg: #232631;
  --bar-fg: #b8bab4;
  --border: #343842;
}

:root[data-theme="yellow"] {
  --bg: #f5edb8;
  --fg: #2c1a00;
  --dim: #7a6025;
  --accent: #5c3d00;
  --echo: #6b4f15;
  --death: #8b1500;
  --bar-bg: #c09820;
  --bar-fg: #1a0f00;
  --border: #9a7a10;
}

:root[data-theme="goldenrod"] {
  --bg: #f0d870;
  --fg: #1e1000;
  --dim: #6b4a18;
  --accent: #4a2e00;
  --echo: #5a3e10;
  --death: #8b1500;
  --bar-bg: #b8900a;
  --bar-fg: #0f0800;
  --border: #907010;
}

:root[data-theme="peach"] {
  --bg: #f8dfc8;
  --fg: #281008;
  --dim: #7a4025;
  --accent: #5a2808;
  --echo: #6a3818;
  --death: #8b1500;
  --bar-bg: #d07040;
  --bar-fg: #140805;
  --border: #a86030;
}

:root[data-theme="rose"] {
  --bg: #f0d8d8;
  --fg: #200a0a;
  --dim: #6a3038;
  --accent: #4a1820;
  --echo: #5a2828;
  --death: #8b1500;
  --bar-bg: #c06070;
  --bar-fg: #100505;
  --border: #a84858;
}

:root[data-theme="green"] {
  --bg: #d5edd5;
  --fg: #0a1e0a;
  --dim: #2e5830;
  --accent: #183818;
  --echo: #224022;
  --death: #8b1500;
  --bar-bg: #5a9860;
  --bar-fg: #050f05;
  --border: #3a7040;
}

:root[data-theme="aqua"] {
  --bg: #c8ede8;
  --fg: #061e1b;
  --dim: #2e6860;
  --accent: #104040;
  --echo: #1c5248;
  --death: #8b1500;
  --bar-bg: #45a89e;
  --bar-fg: #020d0c;
  --border: #3a8880;
}

:root[data-theme="turquoise"] {
  --bg: #c8e8ee;
  --fg: #051520;
  --dim: #285868;
  --accent: #0e3848;
  --echo: #1c4858;
  --death: #8b1500;
  --bar-bg: #3888a0;
  --bar-fg: #020810;
  --border: #2e6878;
}

:root[data-theme="blue-grey"] {
  --bg: #d0d8e8;
  --fg: #0a1020;
  --dim: #384e68;
  --accent: #1c3050;
  --echo: #2c4460;
  --death: #8b1500;
  --bar-bg: #6080a0;
  --bar-fg: #040810;
  --border: #4a6080;
}

:root[data-theme="purple"] {
  --bg: #e5d8f0;
  --fg: #150a20;
  --dim: #543568;
  --accent: #2e1848;
  --echo: #402858;
  --death: #8b1500;
  --bar-bg: #9868c8;
  --bar-fg: #080412;
  --border: #683890;
}

:root[data-theme="grey"] {
  --bg: #e0e0dc;
  --fg: #0e0e0c;
  --dim: #4e4e4a;
  --accent: #282824;
  --echo: #3c3c38;
  --death: #8b1500;
  --bar-bg: #888880;
  --bar-fg: #050505;
  --border: #606060;
}

/* ---- Reading fonts ------------------------------------------------------- */
/* `default` is the :root monospace above. The others bump size / spacing,
   which helps many dyslexic and Irlen readers as much as colour does. */

:root[data-font="sans"] {
  --font: "Segoe UI", "Helvetica Neue", Arial, system-ui, sans-serif;
  --font-size: 17px;
  --line-height: 1.6;
  --letter-spacing: 0.01em;
  --word-spacing: 0.04em;
}

:root[data-font="dyslexic"] {
  /* Uses OpenDyslexic / Atkinson Hyperlegible if the reader has them
     installed, else a friendlier-than-default system fallback. */
  --font: "OpenDyslexic", "Atkinson Hyperlegible", "Comic Sans MS", Verdana, system-ui, sans-serif;
  --font-size: 17px;
  --line-height: 1.7;
  --letter-spacing: 0.03em;
  --word-spacing: 0.08em;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: var(--font-size);
  line-height: var(--line-height);
  letter-spacing: var(--letter-spacing);
  word-spacing: var(--word-spacing);
  /* iOS Safari rubber-bands the whole page even when an inner element scrolls;
     locking body overflow keeps the chrome (header/input) from bouncing. The
     #output region does the scrolling. */
  overflow: hidden;
  /* Kill the grey flash iOS paints over tapped buttons/links. */
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: relative;
  display: flex;
  flex-direction: column;
  /* 100vh on mobile is the full viewport *behind* the URL bar and ignores the
     on-screen keyboard, so the column overflows and the whole page scrolls
     (header or input drifts off-screen). 100dvh tracks the *visible* viewport —
     it shrinks for the URL bar and the keyboard — keeping header + input pinned.
     100vh is the fallback for browsers without dynamic viewport units. */
  height: 100vh;
  height: 100dvh;
  max-width: 960px;
  margin: 0 auto;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

#status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.75rem;
  align-items: center;
  /* Pad for the notch / status bar on iPhones (viewport-fit=cover). */
  padding: max(0.6rem, env(safe-area-inset-top)) 1rem 0.6rem;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  background: var(--bar-bg);
  color: var(--bar-fg);
  border-bottom: 1px solid var(--border);
  font-size: 0.95em;
  flex: 0 0 auto;
}

#status-bar .status-sep { color: var(--dim); }
#status-score { color: var(--accent); }
#status-location { color: var(--accent); }
#status-alias { color: var(--accent); font-weight: 600; }
#status-alias-wrap[hidden] { display: none; }

/* Accessibility controls cluster to the right of the status bar. */
#a11y-controls {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
#a11y-controls select {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-family: var(--font);
  font-size: 0.9em;
  padding: 0.1rem 0.3rem;
}
#a11y-controls select:focus-visible,
#a11y-controls button:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}
#a11y-controls button {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-family: var(--font);
  font-size: 0.9em;
  padding: 0.1rem 0.5rem;
  cursor: pointer;
}

/* Per-colour customisation panel: floats below the status bar, anchored to the
   right of the #app column. All chrome reads through the theme variables, so it
   restyles live as colours are edited. */
#customise-panel {
  position: absolute;
  top: 2.8rem;
  right: 0.75rem;
  z-index: 20;
  width: 320px;
  max-width: calc(100% - 1.5rem);
  padding: 0.8rem;
  background: var(--bar-bg);
  color: var(--bar-fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  font-size: 0.9em;
}
#customise-panel[hidden] { display: none; }

.customise-grid { display: flex; flex-direction: column; gap: 0.35rem; }
.customise-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.1rem 0;
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.customise-row:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}
.customise-swatch {
  flex: 0 0 auto;
  width: 30px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: 3px;
}
.customise-label { flex: 1 1 auto; }

/* The real colour input is parked to the left of the panel, in the empty game
   area, so the browser-positioned OS dialog opens there — clear of the list.
   Invisible but still "rendered" (opacity, not display:none) so .click() opens
   the native picker. */
.customise-launcher {
  position: absolute;
  top: 0.5rem;
  left: -260px;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.customise-save {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.7rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
}
.customise-save input[type="text"] {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.15rem 0.4rem;
  font-family: var(--font);
  font-size: 0.95em;
}
.customise-save button {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-family: var(--font);
  font-size: 0.9em;
  padding: 0.15rem 0.6rem;
  cursor: pointer;
}
.customise-save button:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}
.customise-save .customise-delete { color: var(--death); }
.customise-save .customise-delete[hidden] { display: none; }

.customise-io {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.5rem;
}
.customise-io button {
  flex: 1;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-family: var(--font);
  font-size: 0.9em;
  padding: 0.15rem 0.6rem;
  cursor: pointer;
}
.customise-io button:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}
.customise-io-msg {
  margin: 0.4rem 0 0;
  min-height: 1.1em;
  font-size: 0.85em;
  color: var(--dim);
}
.customise-io-msg.error { color: var(--death); }

#output {
  flex: 1 1 auto;
  min-height: 0; /* let the scroll region shrink inside the flex column */
  overflow-y: auto;
  overscroll-behavior: contain; /* don't chain scroll to the page/URL bar */
  -webkit-overflow-scrolling: touch;
  padding: 1rem;
  white-space: pre-wrap;
  word-wrap: break-word;
}

#output .echo {
  color: var(--echo);
  margin-top: 0.4rem;
}

#output .system { color: var(--dim); font-style: italic; }
#output .death { color: var(--death); }
#output .heading { color: var(--accent); font-weight: bold; }
#output .block { margin-bottom: 0.8rem; }

/* The "more" pager bar: a full-width row between the scroll region and the input,
   shown only while a long passage is being read page by page. */
#more-bar {
  flex: 0 0 auto;
  width: 100%;
  border: none;
  border-top: 1px solid var(--border);
  background: var(--accent);
  color: var(--bg);
  font: inherit;
  font-weight: bold;
  letter-spacing: 0.03em;
  padding: 0.45rem 1rem;
  text-align: center;
  cursor: pointer;
}
#more-bar[hidden] { display: none; }
#more-bar:focus-visible { outline: 2px solid var(--fg); outline-offset: -4px; }

#output a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}
#output a:hover { color: #ffd98a; }
#output a:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 2px;
}

#input-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  /* Pad for the home indicator on the bottom edge (viewport-fit=cover). */
  padding: 0.6rem 1rem max(0.6rem, env(safe-area-inset-bottom));
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  border-top: 1px solid var(--border);
  background: var(--bar-bg);
  flex: 0 0 auto;
}

#input-form .prompt { color: var(--accent); }

#input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  /* iOS adds a rounded inset chrome to text inputs; strip it. */
  -webkit-appearance: none;
  appearance: none;
  color: var(--fg);
  font-family: var(--font);
  /* iOS Safari auto-zooms when a focused input's text is < 16px. The body font
     can be 15px, so pin the input to >=16px to suppress the focus zoom. */
  font-size: max(1em, 16px);
  caret-color: var(--accent);
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

/* ---- The slot machine ---------------------------------------------------- */
/* An animated reel-spin popup for the EZ1 casino. Driven entirely by
   src/ui/slot-machine.ts; pure cosmetic theatre over the text outcome. All
   colours read through the theme variables, so it recolours with the scheme. */

.slot-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.72);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  outline: none;
}
.slot-overlay[hidden] { display: none; }

.slot-cabinet {
  --slot-cell: clamp(62px, 21vw, 92px);
  width: min(92vw, 460px);
  padding: 1.1rem 1.1rem 1.3rem;
  text-align: center;
  background:
    radial-gradient(120% 80% at 50% -10%, color-mix(in srgb, var(--accent) 22%, var(--bar-bg)), var(--bar-bg) 60%);
  border: 3px solid var(--accent);
  border-radius: 18px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55), inset 0 0 0 1px var(--border);
  color: var(--bar-fg);
}

.slot-marquee {
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: 0.28em;
  text-indent: 0.28em; /* balance the trailing letter-spacing */
  color: var(--accent);
  text-shadow: 0 0 10px color-mix(in srgb, var(--accent) 60%, transparent);
  margin-bottom: 0.9rem;
}

.slot-reels {
  display: flex;
  gap: 0.55rem;
  justify-content: center;
  padding: 0.6rem;
  background: var(--bg);
  border-radius: 12px;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.45);
}

.slot-reel {
  width: var(--slot-cell);
  height: var(--slot-cell);
  overflow: hidden;
  border-radius: 8px;
  background:
    linear-gradient(var(--bg), color-mix(in srgb, var(--bg) 80%, #000 20%));
  /* Frame via inset shadow (not border) so the window stays exactly one cell
     tall — the reel-stop maths in slot-machine.ts depends on it. */
  box-shadow: inset 0 0 0 2px var(--border), inset 0 0 18px rgba(0, 0, 0, 0.6);
}

.slot-strip {
  display: flex;
  flex-direction: column;
  will-change: transform;
}

.slot-cell {
  height: var(--slot-cell);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--slot-cell) * 0.56);
  line-height: 1;
  user-select: none;
}
.slot-cell-text {
  font-family: var(--font);
  font-weight: 800;
  font-size: calc(var(--slot-cell) * 0.34);
  letter-spacing: 0.04em;
  color: var(--fg);
}
.slot-cell-seven { color: var(--death); }

.slot-reel-spinning { filter: blur(0.6px); }

/* The win line across the reel window. */
.slot-payline {
  height: 2px;
  margin: -1px auto 0;
  width: calc(3 * var(--slot-cell) + 1.1rem + 1.2rem);
  max-width: 100%;
  background: color-mix(in srgb, var(--death) 70%, transparent);
  opacity: 0.55;
}

.slot-readout { margin-top: 1rem; min-height: 3.2rem; }
.slot-result {
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent);
  min-height: 1.2em;
}
.slot-pay {
  font-size: 1.6rem;
  font-weight: 800;
  margin: 0.15rem 0;
  color: var(--fg);
}
.slot-balance { color: var(--dim); font-size: 0.9em; }

.slot-hint {
  margin-top: 0.9rem;
  font-size: 0.8em;
  font-style: italic;
  color: var(--dim);
  min-height: 1.1em;
}

/* A win glows; the jackpot strobes. Motion gated for reduced-motion readers. */
.slot-cabinet.win { border-color: var(--accent); }
.slot-cabinet.win .slot-pay { color: var(--accent); }

@media (prefers-reduced-motion: no-preference) {
  .slot-cabinet.win {
    animation: slot-win-glow 0.7s ease-in-out 3 alternate;
  }
  .slot-cabinet.jackpot {
    animation: slot-jackpot 0.28s steps(2, jump-none) 8 alternate;
  }
  .slot-cabinet.jackpot .slot-marquee {
    animation: slot-marquee-flash 0.32s ease-in-out infinite alternate;
  }
  .slot-hint { animation: slot-hint-pulse 1.3s ease-in-out infinite; }
}

@keyframes slot-win-glow {
  from { box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55), inset 0 0 0 1px var(--border); }
  to {
    box-shadow:
      0 18px 60px rgba(0, 0, 0, 0.55),
      inset 0 0 0 1px var(--border),
      0 0 26px color-mix(in srgb, var(--accent) 75%, transparent);
  }
}
@keyframes slot-jackpot {
  from { border-color: var(--accent); }
  to { border-color: var(--death); }
}
@keyframes slot-marquee-flash {
  from { opacity: 1; text-shadow: 0 0 10px color-mix(in srgb, var(--accent) 60%, transparent); }
  to { opacity: 0.65; text-shadow: 0 0 22px var(--accent); }
}
@keyframes slot-hint-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}
