:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --panel: #0f1318;
  --ink: #e5e9f0;
  --muted: #6c7586;
  --accent: #5fffd7;     /* omz-cyan — input border, brand highlights */
  --danger: #ff5c5c;
  --border: rgba(216, 225, 238, 0.14);
  --shadow: rgba(0, 0, 0, 0.45);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;

  /* oh-my-zsh / agnoster-flavoured ANSI palette ----------------------------
     Mapped to common text-adventure line kinds so each kind reads at a
     glance instead of being a wall of grey.                               */
  --omz-black:    #1a1d22;
  --omz-red:      #ff5c5c;
  --omz-green:    #87ff5f;
  --omz-yellow:   #ffd75f;
  --omz-blue:     #5fafff;
  --omz-magenta:  #ff87d7;
  --omz-cyan:     #5fffd7;
  --omz-white:    #e5e9f0;
  --omz-grey:     #6c7586;
  --omz-bright-green:  #afff87;
  --omz-bright-yellow: #ffff87;
  --omz-bright-cyan:   #87ffff;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: radial-gradient(1200px 800px at 20% 0%, #101827 0%, var(--bg) 55%);
  color: var(--ink);
  font-family: var(--mono);
  display: grid;
  place-items: center;
  padding: 18px;
  /* Stop iOS Safari from auto-bumping our font-size in portrait orientation. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.shell {
  width: min(920px, 100%);
  height: min(740px, 100dvh);
  border: 1px solid var(--border);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 35%),
    var(--panel);
  box-shadow: 0 20px 60px var(--shadow);
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  letter-spacing: 0.03em;
}

.meta {
  display: flex;
  gap: 14px;
  color: var(--muted);
  font-size: 13px;
}

/* === Scene panel (graphic layer) ====================================== */
/* A picture window above the transcript, keyed by the current room. It stays
   collapsed (height:0, invisible) until art exists at art/scenes/<id>.webp, so
   the game is completely unchanged until you start adding pictures. */
.scene {
  margin: 0;
  height: 0;
  opacity: 0;
  position: relative;
  background: #000 center / cover no-repeat;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  transition: height 0.35s ease, opacity 0.35s ease;
}
.scene.on {
  height: clamp(150px, 32vh, 300px);
  opacity: 1;
}
/* Soft scrim into the transcript (also matches the art's dark lower edge). */
.scene::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(11, 13, 16, 0) 55%, rgba(11, 13, 16, 0.9) 100%);
}
@media (max-width: 720px) {
  .scene.on { height: clamp(110px, 24vh, 200px); }
}

.screen {
  overflow: auto;
  padding: 16px;
}

.transcript {
  display: flex;
  flex-direction: column;
  gap: 10px;
  line-height: 1.45;
  font-size: 14px;
}

.line {
  white-space: pre-wrap;
  word-break: break-word;
}

/* oh-my-zsh palette mapped to text-adventure line kinds. Each kind reads at
   a glance: room headers in cyan, narration in soft white, hints dimmed,
   wins in green, warnings yellow, errors red, your input prompt in magenta. */
.line.user,
.line.command {
  color: var(--omz-magenta);
  font-weight: 600;
}

.line.system {
  color: var(--omz-white);
}

.line.error {
  color: var(--omz-red);
}

.line.location {
  color: var(--omz-bright-cyan);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.line.achievement {
  color: var(--omz-bright-green);
  font-weight: 600;
}

.line.subtle,
.line.hint {
  color: var(--omz-grey);
  font-style: italic;
}

.line.warning {
  color: var(--omz-bright-yellow);
}

/* Death — the most dramatic line in the game (demon consumes you, game over).
   Previously emitted with no matching rule, so it rendered as plain body text. */
.line.death {
  color: var(--omz-red);
  font-weight: 700;
  letter-spacing: 0.03em;
  text-shadow: 0 0 8px rgba(255, 92, 92, 0.4);
}

/* Lore — demon spine / barcode theology. Violet, the colour the whole
   confrontation is themed around. */
.line.lore {
  color: var(--omz-magenta);
  font-style: italic;
}

.prompt {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.promptLabel {
  color: var(--muted);
}

.commandInput {
  width: 100%;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--ink);
  padding: 10px 12px;
  border-radius: 10px;
  outline: none;
  font-family: var(--mono);
  font-size: 14px;
}

.commandInput:focus {
  border-color: rgba(140, 255, 210, 0.6);
  box-shadow: 0 0 0 3px rgba(140, 255, 210, 0.12);
}

.sendBtn {
  border: 1px solid var(--border);
  background: rgba(140, 255, 210, 0.12);
  color: var(--ink);
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-family: var(--mono);
}

.sendBtn:hover {
  border-color: rgba(140, 255, 210, 0.5);
  background: rgba(140, 255, 210, 0.16);
}

.footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.footerBtn {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink);
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 13px;
}

.footerBtn:hover {
  border-color: rgba(216, 225, 238, 0.3);
  background: rgba(255, 255, 255, 0.06);
}

/* ===================================================================== */
/*  Mobile / responsive                                                  */
/* ===================================================================== */

/* Tablet — let the shell stretch a bit before phone styles kick in. */
@media (max-width: 900px) {
  body { padding: 10px; }
  .shell {
    width: 100%;
    height: min(820px, calc(100dvh - 20px));
  }
}

/* Phone — lock the shell to the visible viewport so the whole game fits
   in portrait without scrolling, no zoom-in. Use stable `100svh` (small-
   viewport-height) instead of `100dvh` so the shell DOES NOT shrink when
   the iOS virtual keyboard appears — the keyboard slides over instead. */
@media (max-width: 720px) {
  /* Belt-and-braces: any input/textarea/select renders ≥16px on phone so
     iOS Safari never auto-zooms on focus, regardless of what's added later. */
  input, textarea, select { font-size: 16px !important; }

  html, body {
    height: 100%;
    height: 100svh;          /* stable across keyboard show/hide */
    overflow: hidden;
  }
  body {
    padding: 0;
    place-items: stretch;
    background: var(--bg);   /* skip the radial gradient on phone — flat is faster + less artifacty */
  }
  .shell {
    width: 100vw;
    max-width: 100vw;
    /* With viewport meta `interactive-widget=overlays-content`, the keyboard
       floats over the page without resizing the viewport. We then subtract
       `env(keyboard-inset-height)` so the shell shrinks from the bottom and
       the prompt input stays visible above the keyboard. Falls back to 0
       when no keyboard is showing or when the browser doesn't support it. */
    height: calc(100svh - env(keyboard-inset-height, 0px));
    max-height: calc(100svh - env(keyboard-inset-height, 0px));
    border: none;
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
    grid-template-rows: auto auto 1fr auto auto;
    /* Smooth out the resize when the keyboard slides in/out. */
    transition: height 0.18s ease;
  }

  /* Topbar — single tight row: brand left, score chips right (no labels). */
  .topbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 8px 10px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .topbar::-webkit-scrollbar { display: none; }
  .brand {
    font-size: 14px;
    flex: 0 0 auto;
    white-space: nowrap;
  }
  .meta {
    flex: 1 1 auto;
    justify-content: flex-end;
    gap: 8px;
    font-size: 11px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .meta::-webkit-scrollbar { display: none; }
  .meta span {
    white-space: nowrap;
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
  }

  .screen {
    padding: 10px 12px;
    -webkit-overflow-scrolling: touch;
  }
  .transcript {
    font-size: 13.5px;
    line-height: 1.4;
    gap: 8px;
  }

  /* Prompt row */
  .prompt {
    grid-template-columns: auto 1fr auto;
    gap: 8px;
    padding: 8px 10px;
  }
  .commandInput {
    font-size: 16px;       /* iOS no-zoom on focus */
    padding: 10px 12px;
    border-radius: 8px;
  }
  .sendBtn {
    font-size: 13px;
    padding: 10px 12px;
    min-height: 40px;
    border-radius: 8px;
  }

  /* Footer: 3-col grid x 2 rows for the 6 quick-action buttons. */
  .footer {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
    padding: 8px 10px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  }
  .footerBtn {
    font-size: 12.5px;
    padding: 10px 4px;
    min-height: 40px;
    border-radius: 6px;
    text-align: center;
  }
}

/* Tiny phones — tighten further. */
@media (max-width: 380px) {
  .topbar .brand { font-size: 13px; }
  .meta { font-size: 10.5px; gap: 5px; }
  .meta span { padding: 2px 5px; }
  .transcript { font-size: 13px; }
  .footerBtn { font-size: 11.5px; padding: 8px 2px; }
}

/* Landscape phone — keep the layout, just give the meta more room. */
@media (max-width: 900px) and (orientation: landscape) {
  .footer { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
