/**
 * Mythkeeper's Room — shell styling.
 *
 * The canvas is letterboxed by `resize()` in js/render.js: every frame it fits
 * the largest 960×540 box inside #stage and sets the canvas box exactly, so the
 * declared ratio in the registry, the CSS box and the drawing buffer always
 * agree — a 3D view that is stretched to its container is a room whose walls
 * lean. Everything clickable lives outside the canvas: the journal, the
 * pockets, the buttons and the walking pad. See docs/GAME_BUILDING_AGENT.md §2.
 *
 * Dark oak, one warm accent, tabular numbers: the mood of the room in the
 * chrome around it.
 */

:root {
  color-scheme: dark;
  --ink: #14100d;
  --ink-deep: #0d0a08;
  --panel: #211a14;
  --panel-2: #2c231a;
  --panel-3: #372b20;
  --line: #46372a;
  --text: #f2e9da;
  --muted: #b6a48d;
  --faint: #8b7a66;
  --amber: #f0b45e;
  --amber-deep: #8c6427;
  --candle: #ffd9a0;
  --danger: #e08a6c;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--ink-deep);
}

body {
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
}

/* ------------------------------------------------------------------ layout */

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 8px 12px 10px;
  gap: 8px;
}

#titlebar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

#titlebar h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--candle);
}

.tagline {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.meters {
  display: flex;
  gap: 14px;
}

.meter {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--faint);
}

.meter strong {
  font-size: 15px;
  letter-spacing: 0;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* The stage owns the leftover height; the canvas is centred inside it and
   sized in JS, so it can never be stretched or overflow. */
#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  border-radius: 10px;
  background: #0a0807;
  border: 1px solid var(--line);
}

#game {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: block;
  border-radius: 6px;
  cursor: crosshair;
  outline: none;
}

#game:focus-visible {
  box-shadow: 0 0 0 2px var(--amber);
}

#crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 16px;
  height: 16px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

#crosshair::before,
#crosshair::after {
  content: "";
  position: absolute;
  background: rgba(255, 232, 196, 0.75);
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.9);
}

#crosshair::before {
  left: 50%;
  top: 0;
  width: 1px;
  height: 100%;
  transform: translateX(-50%);
}

#crosshair::after {
  top: 50%;
  left: 0;
  height: 1px;
  width: 100%;
  transform: translateY(-50%);
}

#lookHint {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  margin: 0;
  padding: 4px 12px;
  font-size: 12px;
  white-space: nowrap;
  border-radius: 999px;
  background: rgba(16, 12, 9, 0.82);
  border: 1px solid var(--line);
  color: var(--muted);
}

/* --------------------------------------------------------------- the HUD */

#hud {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: flex-start;
}

.block {
  min-width: 0;
  flex: 1 1 320px;
}

.block h2 {
  margin: 0 0 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--faint);
}

#journal {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.myth {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 3px 11px;
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  transition: border-color 160ms ease, background 160ms ease;
}

.myth .numeral {
  font-family: Georgia, serif;
  color: var(--faint);
  font-weight: 700;
}

.myth .name {
  color: var(--muted);
}

.myth .value {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.myth.known {
  border-color: var(--amber-deep);
  background: var(--panel-2);
}

.myth.known .numeral,
.myth.known .name,
.myth.known .value {
  color: var(--amber);
}

#inventory {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 26px;
  align-items: center;
}

.empty {
  font-size: 12px;
  color: var(--faint);
  font-style: italic;
}

.item {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  cursor: pointer;
}

.item:hover {
  border-color: var(--amber-deep);
  background: var(--panel-3);
}

/* -------------------------------------------------------------- controls */

#controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#prompt,
#message {
  margin: 0;
  font-size: 13px;
  min-height: 17px;
}

#prompt {
  color: var(--text);
}

#message {
  color: var(--amber);
  font-size: 12.5px;
}

.row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

#controls button {
  padding: 7px 13px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  cursor: pointer;
  font-size: 13px;
}

#controls button:hover:not(:disabled) {
  border-color: var(--amber-deep);
  background: var(--panel-3);
}

#controls button:disabled {
  opacity: 0.45;
  cursor: default;
}

#controls button.primary {
  background: var(--amber);
  border-color: var(--amber);
  color: #2a1c08;
  font-weight: 650;
}

#controls button.primary:hover:not(:disabled) {
  background: var(--candle);
  border-color: var(--candle);
}

.row-pad {
  gap: 10px;
}

#dpad {
  display: grid;
  grid-template-columns: repeat(3, 34px);
  grid-template-rows: repeat(2, 30px);
  gap: 4px;
}

#dpad button {
  padding: 0;
  font-size: 13px;
  line-height: 1;
}

#dpad #dpadLeft {
  grid-column: 1;
  grid-row: 2;
}

#dpad #dpadBack {
  grid-column: 2;
  grid-row: 2;
}

#dpad #dpadRight {
  grid-column: 3;
  grid-row: 2;
}

#controls button.look {
  padding: 12px 18px;
  font-weight: 600;
  border-color: var(--amber-deep);
}

.legend {
  margin: 0;
  font-size: 11.5px;
  color: var(--faint);
  line-height: 1.5;
}

@media (max-height: 780px) {
  .tagline,
  .legend {
    display: none;
  }
}

/* ---------------------------------------------------------------- dialogs */

#modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(8, 6, 5, 0.72);
  backdrop-filter: blur(2px);
}

#modal[hidden] {
  display: none;
}

#modalPanel {
  position: relative;
  width: min(560px, 100%);
  max-height: min(78vh, 620px);
  overflow: auto;
  padding: 20px 20px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

#modalPanel h2 {
  margin: 0 0 10px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 19px;
  font-weight: 600;
  color: var(--candle);
}

#modalBody p {
  margin: 0 0 9px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
}

#modalBody p.escaped {
  margin-top: 12px;
  color: var(--amber);
  font-variant-numeric: tabular-nums;
}

#modalButtons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

#modalButtons button {
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--panel-3);
  cursor: pointer;
}

#modalButtons button:hover {
  border-color: var(--amber-deep);
}

#modalButtons button.primary {
  background: var(--amber);
  color: #2a1c08;
  border-color: var(--amber);
  font-weight: 650;
}

#modalClose {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 30px;
  height: 30px;
  font-size: 19px;
  line-height: 1;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

#modalClose:hover {
  background: var(--panel-3);
  color: var(--text);
}

/* The lock and the clock: the two dialogues that are a puzzle, not a page. */
.slots {
  display: flex;
  gap: 8px;
  margin: 4px 0 12px;
}

.slot {
  display: grid;
  place-items: center;
  width: 46px;
  height: 56px;
  font-family: Georgia, serif;
  font-size: 26px;
  border: 1px solid var(--amber-deep);
  border-radius: 8px;
  background: #0f0b08;
  color: var(--candle);
  font-variant-numeric: tabular-nums;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, minmax(56px, 1fr));
  gap: 6px;
  max-width: 300px;
}

.keypad button,
.clock-dial button {
  padding: 10px 0;
  font-size: 15px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--panel-3);
  cursor: pointer;
}

.keypad button:hover,
.clock-dial button:hover {
  border-color: var(--amber-deep);
  background: #3f3125;
}

.clock-dial {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.clock-dial .step {
  display: flex;
  align-items: center;
  gap: 10px;
}

.clock-dial .step span {
  width: 62px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--faint);
}

.clock-dial .step strong {
  min-width: 46px;
  text-align: center;
  font-size: 19px;
  font-variant-numeric: tabular-nums;
  color: var(--candle);
}

.clock-dial .step button {
  width: 42px;
  padding: 6px 0;
}

/* ----------------------------------------------------------------- motion */

.flash {
  animation: flash 900ms ease-out;
}

@keyframes flash {
  0% {
    filter: brightness(1.9);
  }
  100% {
    filter: brightness(1);
  }
}

.shake {
  animation: shake 380ms ease-in-out;
}

@keyframes shake {
  0%, 100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-7px);
  }
  45% {
    transform: translateX(6px);
  }
  70% {
    transform: translateX(-3px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .flash,
  .shake {
    animation: none;
  }
}
