:root {
  --bg: #111;
  --panel: #1b1b1b;
  --line: #333;
  --text: #eee;
  --dim: #888;
  --accent: #6c6;      /* Apple II green */
  --accent-2: #b5f;    /* Apple II violet */
  --warn: #fc6;
  --danger: #f44;
  --win: #6c6;

  /* Everything stacked above and below the picture, so the whole game fits
     the window's height: page padding, title, gaps, the picture's border
     and the messages/inventory row (as tall as the 2 rows of inventory). */
  --below-height: 160px;
  --around-picture: calc(32px + 50px + 2 * 12px + 2px + var(--below-height));
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  display: flex;
  justify-content: center;
  gap: 16px;
  padding: 16px;
}

/* As wide as possible, up to the picture's 1056px, but no wider than lets the
   picture (1056x632) and everything around it fit the window's height. */
#game {
  width: min(100%, 1056px, max(320px, calc((100vh - var(--around-picture)) * 1056 / 632 + 2px)));
  width: min(100%, 1056px, max(320px, calc((100dvh - var(--around-picture)) * 1056 / 632 + 2px)));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#title {
  display: flex;
  justify-content: center;
}
#title img {
  display: block;
  max-width: 100%;
  height: auto;
}

#screen {
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  background: #000;
  border: 1px solid var(--line);
  display: block;
}

/* Click point: centre of each 32x32 cursor image (the lens for the magnifier). */
#screen.cursor-use { cursor: pointer; }
#screen.cursor-take { cursor: url("../assets/images/cursors/hand-open.png") 16 16, grab; }
#screen.cursor-walk { cursor: url("../assets/images/cursors/walk.png") 16 16, pointer; }
#screen.cursor-examine { cursor: url("../assets/images/cursors/magnifier.png") 13 12, zoom-in; }
#screen.cursor-locked { cursor: url("../assets/images/cursors/locked.png") 16 16, not-allowed; }
#screen.cursor-push { cursor: url("../assets/images/cursors/push.png") 16 16, move; }
#screen.cursor-climb-up { cursor: url("../assets/images/cursors/climb-up.png") 16 16, n-resize; }
#screen.cursor-climb-down { cursor: url("../assets/images/cursors/climb-down.png") 16 16, s-resize; }

/* Messages on the left, wrapping before the fixed-width inventory on the right. */
#below {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: start;
  height: var(--below-height);
}

/* A fixed height: the oldest messages are dropped when they don't fit (ui.js). */
#messages {
  font-size: 18px;
  height: 100%;
  overflow: hidden;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  overflow-wrap: break-word;
}
#messages p { margin: 0 0 0.25em; color: var(--dim); }
#messages p.latest { color: var(--text); }
#messages p.error { color: var(--warn); }
#messages p.death { color: var(--danger); }
#messages p.win { color: var(--win); }

/* Game over: dims the picture, with a panel in the middle. */
#screen-wrap { position: relative; }
#game-over {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.65);
}
#game-over[hidden] { display: none; }
#game-over .panel {
  background: #000;
  border: 2px solid var(--text);
  padding: 24px 32px;
  max-width: 60%;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
#game-over .panel p { margin: 0 0 16px; }
#game-over .choices { display: flex; gap: 16px; justify-content: center; }
#game-over button { min-width: 6em; text-transform: uppercase; }

button {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.4em 0.5em;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }

/* 6 slots, 3 wide by 2 tall, always taking the same space. `direction: rtl`
   makes the grid fill from the top right leftwards, then the next row from
   the right; the contents are switched back to left-to-right. */
#inventory {
  display: grid;
  grid-template-columns: repeat(3, 96px);
  grid-template-rows: repeat(2, 76px);   /* 2 x 76 + 8 = --below-height */
  gap: 8px;
  direction: rtl;
}
#inventory > * { direction: ltr; }
/* While messages are typing, the inventory can't be clicked (see ui.js). */
body.typing #inventory { pointer-events: none; }
#inventory .slot {
  border: 1px solid var(--line);
  border-radius: 4px;
}
#inventory .slot.empty { border-style: dashed; }
#inventory .item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px;
  min-width: 0;
  overflow: hidden;
}
#inventory .item span {
  font-size: 0.8em;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#inventory .item img {
  height: 40px;
  max-width: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}
#inventory .item.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}
/* An item the held item can be used on: glows green on hover. */
#inventory .item.usable:hover {
  border-color: #6c6;
  box-shadow: 0 0 10px 2px #6c6;
}

#debug {
  width: 300px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  flex: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 12px;
  font-size: 0.85em;
  align-self: flex-start;
}
#debug h2 { margin: 0 0 8px; font-size: 1.1em; }
#debug h3 { margin: 14px 0 6px; font-size: 1em; color: var(--accent); }
#debug select { width: 100%; font: inherit; }
#debug .flags { display: flex; flex-direction: column; gap: 2px; }
#debug .coords { margin: 0; color: var(--accent-2); }
#debug .area { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
#debug .hint { color: var(--dim); margin: 6px 0 0; }
#debug .warnings { margin: 0; padding-left: 1.2em; color: var(--warn); }
#debug .warnings li { margin-bottom: 4px; }

@media (max-width: 800px) {
  body { flex-direction: column; padding: 16px; }
  #debug { width: 100%; }
}
