/* Endless Maze — ink & lamplight.
 * Near-black ground, parchment text, hairline brass rules.
 * Display: Cormorant Garamond. Working text: IBM Plex Mono.
 */

:root {
  --ink: #0b0a08;
  --ink-2: #121110;
  --ink-3: #1a1816;
  --parchment: #d8cfc0;
  --parchment-dim: #8d8576;
  --brass: #c9a227;
  --brass-dim: #6e5a1d;
  --blood: #c0554a;
  --region-accent: #8b93ad;
  --region-glow: #aab3d0;
  --hairline: 1px solid #2a2620;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  background: var(--ink);
  color: var(--parchment);
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 13px;
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-rows: 46px 1fr;
  grid-template-columns: 1fr 318px;
  grid-template-areas:
    'header header'
    'stage  panel';
  height: 100%;
  max-width: 1500px;
  margin: 0 auto;
  padding: 0 12px 12px;
  gap: 10px;
}

/* ---------------- header ---------------- */
#header {
  grid-area: header;
  display: flex;
  align-items: baseline;
  gap: 18px;
  border-bottom: var(--hairline);
  padding: 12px 4px 8px;
}
#btn-name { color: var(--brass) !important; border-color: var(--brass-dim) !important; }
#btn-name.hidden { display: none; }
#h-room {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 23px;
  font-weight: 600;
  letter-spacing: 0.4px;
  color: var(--parchment);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#h-region {
  color: var(--region-accent);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  white-space: nowrap;
}
#h-coords {
  color: var(--parchment-dim);
  font-size: 11px;
  margin-left: auto;
  white-space: nowrap;
}
#header .hbtns { display: flex; gap: 8px; margin-left: auto; }
#header button {
  background: none;
  border: 1px solid #2e2a23;
  color: var(--parchment-dim);
  font: inherit;
  font-size: 11px;
  padding: 3px 10px;
  cursor: pointer;
}
#header button:hover { color: var(--brass); border-color: var(--brass-dim); }

/* ---------------- stage ---------------- */
#stage {
  grid-area: stage;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at center, #131110 0%, #0b0a08 75%);
  border: var(--hairline);
  min-height: 0;
}
#game-canvas {
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 780 / 572;
  image-rendering: auto;
  display: block;
}

/* ---------------- chronicle + tavern, merged at the bottom ---------------- */
#chronicle {
  position: absolute;
  left: 10px;
  bottom: 10px;
  width: min(36%, 380px);
  display: flex;
  flex-direction: column;
  background: rgba(6, 5, 4, 0.5);
  border: 1px solid rgba(58, 52, 42, 0.45);
  border-radius: 3px;
  z-index: 8;
  transition: background 0.18s, border-color 0.18s;
}
#chronicle:focus-within { background: rgba(6, 5, 4, 0.93); border-color: #3a342a; }
#chron-feed {
  max-height: 20vh;
  min-height: 46px;
  overflow-y: auto;
  padding: 6px 10px 3px;
  font-size: 11px;
  line-height: 1.45;
}
#chronicle:focus-within #chron-feed { max-height: 34vh; min-height: 130px; }
#chron-bar {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 5px 7px 6px;
  border-top: 1px solid rgba(58, 52, 42, 0.4);
}
#chron-global {
  flex-shrink: 0;
  background: none;
  border: 1px solid #2e2a23;
  color: var(--parchment-dim);
  font: inherit;
  font-size: 10px;
  padding: 4px 8px;
  cursor: pointer;
  white-space: nowrap;
}
#chron-global:hover { color: var(--brass); border-color: var(--brass-dim); }
#chron-global.off { color: #6b6457; border-style: dashed; }
#chron-input {
  flex: 1;
  min-width: 0;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid #2e2a23;
  color: var(--parchment);
  font: inherit;
  font-size: 11.5px;
  padding: 5px 8px;
}
#chron-input:focus { outline: none; border-color: var(--brass-dim); }
#chron-input:disabled { opacity: 0.5; cursor: not-allowed; }
#chron-input::placeholder { color: #55503f; }

/* ---------------- spell quickbar (bottom-centre of stage) ---------------- */
#spellbar {
  position: absolute;
  bottom: 10px;
  right: 10px;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  max-width: 56%;
  z-index: 9;
}
.spell-slot {
  position: relative;
  min-width: 58px;
  background: rgba(12, 11, 10, 0.82);
  border: 1px solid #3a342a;
  border-left: 3px solid var(--sp, #c9a227);
  color: var(--parchment);
  font: inherit;
  font-size: 10px;
  padding: 4px 7px 5px;
  cursor: pointer;
  text-align: left;
  line-height: 1.25;
}
.spell-slot:hover { border-color: var(--brass-dim); border-left-color: var(--sp); }
.spell-slot .sk { color: var(--brass); font-weight: 700; margin-right: 4px; }
.spell-slot .sn { color: var(--parchment); display: block; margin-top: 1px; white-space: nowrap; }
.spell-slot .sc { position: absolute; top: 3px; right: 5px; color: var(--parchment-dim); font-size: 9px; }

/* ---------------- traveler panel ---------------- */
#panel {
  grid-area: panel;
  border: var(--hairline);
  background: var(--ink-2);
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.panel-h {
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--brass-dim);
  border-bottom: var(--hairline);
  padding-bottom: 4px;
  margin-bottom: 6px;
}
#p-name {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 20px;
  font-weight: 600;
}
#p-level { color: var(--parchment-dim); font-size: 11px; }

.bar {
  height: 10px;
  background: #060505;
  border: 1px solid #2a2620;
  position: relative;
  margin: 4px 0 2px;
}
.bar-fill {
  height: 100%;
  transition: width 0.25s ease;
}
#hp-fill { background: linear-gradient(180deg, #d0685c, #963f35); }
#xp-fill { background: linear-gradient(180deg, #d9b958, #8a6f1f); }
.bar-num {
  font-size: 10px;
  color: var(--parchment-dim);
  display: flex;
  justify-content: space-between;
}

.tallies {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  text-align: center;
}
.tally {
  border: var(--hairline);
  padding: 6px 2px;
  background: var(--ink-3);
}
.tally b { display: block; font-size: 15px; color: var(--parchment); font-weight: 600; }
.tally span { font-size: 9px; letter-spacing: 1px; text-transform: uppercase; color: var(--parchment-dim); }

.stat-row { display: flex; justify-content: space-between; font-size: 12px; }
.stat-row span:first-child { color: var(--parchment-dim); }

.panel-block { display: flex; flex-direction: column; gap: 6px; }
.panel-h-note { color: var(--parchment-dim); letter-spacing: 0; text-transform: none; font-size: 9px; }

/* status chips */
#status-row { display: flex; flex-wrap: wrap; gap: 4px; min-height: 0; }
#status-row:empty { display: none; }
.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 9.5px;
  padding: 2px 6px;
  border: 1px solid;
  border-radius: 10px;
  background: rgba(0,0,0,0.25);
  white-space: nowrap;
}
.status-chip .sct { opacity: 0.7; }

/* shield overlay on the vitality bar */
.bar-shield {
  position: absolute;
  top: 0; left: 0; height: 100%;
  background: repeating-linear-gradient(135deg, rgba(143,212,234,0.55) 0 4px, rgba(143,212,234,0.2) 4px 8px);
  pointer-events: none;
}

/* bearing two-column */
.bearing-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 16px; }

/* equipment grid */
#equip { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.eq-slot {
  border-left: 2px solid var(--region-accent);
  padding: 4px 7px;
  background: var(--ink-3);
  line-height: 1.25;
  cursor: pointer;
  min-height: 38px;
}
.eq-slot:hover { background: #211e1a; }
.eq-slot .eql { display: block; font-size: 8.5px; letter-spacing: 1px; text-transform: uppercase; color: var(--brass-dim); }
.eq-slot .eqn { font-size: 10.5px; color: var(--parchment); }
.eq-slot.empty { border-left-color: #2a2620; cursor: default; }
.eq-slot.empty .eqn { color: #5a5446; font-style: italic; }

#bag { display: flex; flex-direction: column; gap: 4px; }
.bag-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  padding: 3px 6px;
  background: var(--ink-3);
  border: var(--hairline);
}
.bag-empty { color: var(--parchment-dim); font-style: italic; font-size: 11px; }
.bag-actions { display: flex; gap: 4px; flex-shrink: 0; }
.bag-actions button, #btn-salve {
  background: none;
  border: 1px solid #3a342a;
  color: var(--parchment-dim);
  font: inherit;
  font-size: 10px;
  padding: 2px 7px;
  cursor: pointer;
}
.bag-actions button:hover, #btn-salve:hover:not(:disabled) { color: var(--brass); border-color: var(--brass-dim); }
#btn-salve { width: 100%; padding: 6px; margin-top: 4px; }
#btn-salve:disabled { opacity: 0.35; cursor: default; }

/* ---------------- chronicle lines ---------------- */
.log-line { color: var(--parchment-dim); text-shadow: 0 1px 3px rgba(0,0,0,0.9); }
.log-line.room {
  color: var(--parchment);
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 14px;
  margin-top: 4px;
}
.log-line.good { color: #a8c08a; }
.log-line.dim { color: #6b6457; font-style: italic; }
.log-line.discover { color: var(--region-glow); }
.log-line.mark { color: #d6b25c; }
.log-line.level { color: var(--brass); }
.log-line.death { color: var(--blood); }

/* ---------------- overlays ---------------- */
.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(6, 5, 4, 0.82);
  z-index: 50;
}
.overlay.open { display: flex; }
.ov-card {
  background: var(--ink-2);
  border: 1px solid #3a342a;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.8);
  padding: 26px 30px;
  max-width: 460px;
  width: calc(100% - 60px);
  max-height: 80%;
  overflow-y: auto;
  position: relative;
}
.ov-card h2 {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 4px;
}
.ov-sub { color: var(--parchment-dim); font-size: 11px; margin-bottom: 14px; }
.ov-close {
  position: absolute;
  top: 10px; right: 12px;
  background: none;
  border: none;
  color: var(--parchment-dim);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.ov-close:hover { color: var(--brass); }

.helps { display: grid; grid-template-columns: 92px 1fr; gap: 5px 14px; font-size: 12px; }
.helps kbd {
  font-family: inherit;
  border: 1px solid #3a342a;
  padding: 1px 7px;
  font-size: 11px;
  color: var(--brass);
  text-align: center;
}
.helps span { color: var(--parchment-dim); }
.help-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 18px; padding-top: 14px; border-top: var(--hairline); }
.help-toggles { display: flex; gap: 8px; }
.help-foot #btn-mute, .help-foot #btn-music {
  background: none; border: 1px solid #3a342a; color: var(--parchment-dim);
  font: inherit; font-size: 11px; padding: 4px 12px; cursor: pointer;
}
.help-foot #btn-mute:hover, .help-foot #btn-music:hover { color: var(--brass); border-color: var(--brass-dim); }

/* onboarding quick guide */
.guide-grid { display: flex; flex-direction: column; gap: 9px; margin: 4px 0 18px; }
.guide-item { display: grid; grid-template-columns: 74px 1fr; gap: 12px; align-items: baseline; }
.guide-item b {
  font-family: 'Cormorant Garamond', Georgia, serif; font-weight: 600; font-size: 16px;
  color: var(--brass); text-align: right;
}
.guide-item span { color: #c4bbaa; font-size: 12px; line-height: 1.5; }
.guide-item kbd {
  font-family: inherit; border: 1px solid #3a342a; padding: 0 5px;
  font-size: 10px; color: var(--brass);
}
.guide-item em { color: #cfc4ab; font-style: italic; }
#ov-guide .ov-actions { justify-content: center; }
#ov-guide .ov-actions button { padding: 9px 32px; }

#map-canvas { display: block; background: #0a0908; border: var(--hairline); }
#map-stats { color: var(--parchment-dim); font-size: 11px; margin-top: 10px; }
#ov-map .ov-card { max-width: 560px; }

.shop-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  border: var(--hairline);
  background: var(--ink-3);
  padding: 10px 12px;
  margin-bottom: 8px;
}
.shop-name { font-size: 13px; }
.shop-desc { color: var(--parchment-dim); font-size: 11px; margin-top: 2px; }
.shop-item button {
  background: none;
  border: 1px solid var(--brass-dim);
  color: var(--brass);
  font: inherit;
  font-size: 11px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.shop-item button:disabled { opacity: 0.35; cursor: default; }
#shop-marks { color: var(--brass); font-size: 12px; margin-bottom: 12px; }

.travel-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  background: var(--ink-3);
  border: var(--hairline);
  color: var(--parchment);
  font: inherit;
  text-align: left;
  padding: 10px 12px;
  margin-bottom: 7px;
  cursor: pointer;
}
.travel-item:hover { border-color: var(--brass-dim); }
.travel-item.here { opacity: 0.45; cursor: default; }
.travel-sub { color: var(--parchment-dim); font-size: 11px; margin-top: 2px; }

#carve-input, #rename-input {
  width: 100%;
  background: #060505;
  border: 1px solid #3a342a;
  color: var(--parchment);
  font: inherit;
  font-size: 13px;
  padding: 9px 10px;
  margin: 6px 0 14px;
}
#carve-input:focus, #rename-input:focus { outline: none; border-color: var(--brass-dim); }
#ov-rename .ov-card { border-color: #4a4226; }
.ov-actions { display: flex; gap: 10px; justify-content: flex-end; }
.ov-actions button {
  background: none;
  border: 1px solid #3a342a;
  color: var(--parchment-dim);
  font: inherit;
  font-size: 12px;
  padding: 7px 16px;
  cursor: pointer;
}
.ov-actions button.primary { color: var(--brass); border-color: var(--brass-dim); }
.ov-actions button:hover { color: var(--brass); }

#lore-text {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 17px;
  font-style: italic;
  line-height: 1.6;
  color: #cfc4ab;
}

/* ---------------- tavern (chat) ---------------- */
.ov-card-chat { max-width: 520px; }
#chat-auth { display: flex; flex-direction: column; gap: 9px; }
#chat-user, #chat-pass, #chat-input {
  width: 100%;
  background: #060505;
  border: 1px solid #3a342a;
  color: var(--parchment);
  font: inherit;
  font-size: 13px;
  padding: 9px 10px;
}
#chat-user:focus, #chat-pass:focus, #chat-input:focus { outline: none; border-color: var(--brass-dim); }
.chat-msg { font-size: 11px; min-height: 14px; color: var(--parchment-dim); margin-top: 2px; }
.chat-msg.err { color: var(--blood); }
#chat-log {
  height: 320px;
  max-height: 50vh;
  overflow-y: auto;
  border: var(--hairline);
  background: #060505;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
  margin-bottom: 8px;
}
.chat-line { color: var(--parchment); margin-bottom: 2px; word-break: break-word; }
.chat-who-name { color: var(--brass); font-weight: 700; }
.linkname {
  background: none; border: none; padding: 0; font: inherit;
  cursor: pointer;
}
.linkname:hover { text-decoration: underline; }
.chat-flag {
  background: none; border: none; color: #5a5446; font: inherit; font-size: 9px;
  cursor: pointer; margin-left: 6px; opacity: 0; transition: opacity 0.15s;
}
.chat-line:hover .chat-flag { opacity: 1; }
.chat-flag:hover { color: var(--blood); text-decoration: underline; }
.chat-flag.done { color: var(--blood); opacity: 1; cursor: default; text-decoration: none; }
.chat-whisper .chat-wlabel { color: #b79be0; font-weight: 700; font-style: italic; }
.chat-whisper .chat-body { color: #c8badf; font-style: italic; }
.chat-system { color: #6b6457; font-style: italic; }
.chat-inputrow { display: flex; gap: 8px; }
.chat-inputrow #chat-input { flex: 1; }
#chat-send {
  background: none;
  border: 1px solid var(--brass-dim);
  color: var(--brass);
  font: inherit;
  font-size: 12px;
  padding: 7px 16px;
  cursor: pointer;
  white-space: nowrap;
}
.chat-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  font-size: 11px;
  color: var(--parchment-dim);
}
.linkbtn {
  background: none; border: none; color: var(--parchment-dim);
  font: inherit; font-size: 11px; cursor: pointer; text-decoration: underline;
}
.linkbtn:hover { color: var(--brass); }
.hidden { display: none !important; }

#ov-death .ov-card { text-align: center; border-color: #4a2622; }
#death-where { color: var(--parchment-dim); font-size: 12px; margin: 8px 0 20px; }
#btn-respawn {
  background: none;
  border: 1px solid var(--brass-dim);
  color: var(--brass);
  font: inherit;
  font-size: 13px;
  padding: 10px 26px;
  cursor: pointer;
}

/* ---------------- title screen ---------------- */
#title-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #0b0a08;
  transition: opacity 0.7s ease, visibility 0s 0.7s;
  overflow: hidden;
}
#title-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 46%;
  opacity: 0.62;
}
#title-screen::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 50%, rgba(11,10,8,0.20) 0%, rgba(11,10,8,0.72) 52%, rgba(11,10,8,0.96) 100%),
    linear-gradient(180deg, rgba(11,10,8,0.65) 0%, rgba(11,10,8,0.1) 26%, rgba(11,10,8,0.55) 64%, rgba(11,10,8,0.95) 100%);
}
.title-inner {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
}
#title-screen.gone { opacity: 0; visibility: hidden; pointer-events: none; }
.title-rule {
  width: 220px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--brass-dim), transparent);
  margin: 18px 0;
}
#title-screen h1 {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 62px;
  font-weight: 600;
  letter-spacing: 14px;
  text-indent: 14px;
  color: var(--parchment);
  text-shadow: 0 0 40px rgba(201, 162, 39, 0.15);
}
.title-sub {
  color: var(--parchment-dim);
  font-size: 12px;
  letter-spacing: 3px;
  text-transform: uppercase;
}
.title-lore {
  max-width: 430px;
  text-align: center;
  color: #7d7568;
  font-size: 12.5px;
  line-height: 1.7;
  margin-top: 6px;
}
#onboard { display: flex; flex-direction: column; align-items: center; gap: 13px; margin-top: 26px; width: 300px; }
#ob-user, #ob-pass {
  width: 100%;
  background: #060505;
  border: none;
  border-bottom: 1px solid #3a342a;
  color: var(--parchment);
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 18px;
  text-align: center;
  padding: 8px 14px;
}
#ob-user:focus, #ob-pass:focus { outline: none; border-bottom-color: var(--brass); }
#ob-user::placeholder, #ob-pass::placeholder { color: #55503f; font-style: italic; }
#ob-terms {
  display: flex; align-items: flex-start; gap: 7px;
  font-size: 11px; color: var(--parchment-dim); line-height: 1.45;
  text-align: left; max-width: 300px; cursor: pointer;
}
#ob-terms a { color: var(--brass); }
#ob-agree { margin-top: 2px; accent-color: var(--brass); flex-shrink: 0; }
#ob-msg { font-size: 11.5px; color: var(--blood); min-height: 14px; text-align: center; }
.ob-hint { font-size: 10.5px; color: #5a5446; max-width: 300px; line-height: 1.5; text-align: center; }
#resume-block { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-top: 26px; }
.resume-line { color: var(--parchment); font-family: 'Cormorant Garamond', Georgia, serif; font-size: 19px; }
.resume-line b { color: var(--brass); font-weight: 600; }
#btn-switch { margin-top: 2px; }
.title-actions { display: flex; gap: 14px; margin-top: 22px; }
.title-actions button {
  background: none;
  border: 1px solid var(--brass-dim);
  color: var(--brass);
  font: inherit;
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  padding: 11px 28px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.title-actions button:hover { background: var(--brass); color: var(--ink); }
.title-actions button.hidden { display: none; }
.title-foot {
  position: absolute;
  bottom: 24px;
  color: #55503f;
  font-size: 10.5px;
  letter-spacing: 1px;
}

/* ---------------- narrow screens ---------------- */
@media (max-width: 940px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: 46px minmax(300px, 1fr) auto;
    grid-template-areas: 'header' 'stage' 'panel';
  }
  #panel { flex-direction: row; flex-wrap: wrap; align-content: flex-start; max-height: 40vh; }
  #panel > * { flex: 1 1 240px; }
  #spellbar { bottom: 6px; }
  #chronicle { width: min(60%, 380px); }
}
@media (max-width: 560px) {
  #title-screen h1 { font-size: 40px; letter-spacing: 8px; text-indent: 8px; }
  .spell-slot { min-width: 46px; font-size: 9px; }
}
