:root {
  --paper: #1a1410;
  --ink: #e8d8b0;
  --ink-dim: #a89878;
  --ink-bright: #f5e6c0;
  --accent: #d49a4a;
  --rule: #3a2a1c;
  --shadow: rgba(0, 0, 0, 0.6);
  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --mono: "SFMono-Regular", "Menlo", "Consolas", "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.55;
}

body {
  background-image:
    radial-gradient(ellipse at top, rgba(212, 154, 74, 0.06), transparent 60%),
    radial-gradient(ellipse at bottom, rgba(0, 0, 0, 0.4), transparent 70%);
}

#frame {
  max-width: 820px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 16px 20px 0;
}

#banner {
  border-bottom: 1px solid var(--rule);
  padding-bottom: 8px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

#banner h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink-bright);
  text-shadow: 0 0 12px rgba(212, 154, 74, 0.25);
}

#status {
  margin-top: 4px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-dim);
}
#status .sep { margin: 0 6px; opacity: 0.5; }

#transcript {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 4px 4px 16px;
  scroll-behavior: smooth;
}

#transcript .line {
  margin: 0 0 0.4em;
  white-space: pre-wrap;
  word-wrap: break-word;
}

#transcript .room-name {
  color: var(--accent);
  font-weight: 600;
  font-variant: small-caps;
  letter-spacing: 0.05em;
  margin-top: 0.6em;
}

#transcript .echo {
  color: var(--ink-dim);
  font-family: var(--mono);
  font-size: 14px;
}

#transcript .echo::before { content: "> "; opacity: 0.7; }

#transcript .system {
  color: var(--accent);
  font-style: italic;
}

#transcript .death {
  color: #c44;
  font-weight: 600;
}

#transcript .noun {
  color: var(--ink-bright);
  border-bottom: 1px dotted var(--ink-dim);
  cursor: pointer;
  transition: color 80ms ease, border-color 80ms ease;
}
#transcript .noun:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

#transcript .win {
  color: #6c6;
  font-weight: 600;
}

#input-form {
  display: flex;
  align-items: center;
  border-top: 1px solid var(--rule);
  padding: 10px 0 14px;
  flex-shrink: 0;
  background: var(--paper);
  position: sticky;
  bottom: 0;
}

#input-form .prompt {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 16px;
  margin-right: 8px;
}

#input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--ink-bright);
  font-family: var(--mono);
  font-size: 16px;
  padding: 4px 0;
  caret-color: var(--accent);
}

#input:focus { outline: none; }

@media (max-width: 600px) {
  html, body { font-size: 16px; }
  #frame { padding: 10px 12px 0; }
  #banner h1 { font-size: 18px; }
  #status { font-size: 11px; }
}

::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--rule);
  border-radius: 5px;
}
::-webkit-scrollbar-thumb:hover { background: var(--ink-dim); }

/* ---------- Map overlay ---------- */

#map-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  display: none;
  align-items: flex-start;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  overflow: auto;
}

.map-panel {
  background: #1f1812;
  border: 1px solid var(--rule);
  border-radius: 6px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.7);
  padding: 14px 18px 18px;
  max-width: 980px;
  width: 100%;
  color: var(--ink);
}

.map-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 8px;
}
.map-title {
  font-family: var(--serif);
  font-size: 18px;
  color: var(--ink-bright);
  font-variant: small-caps;
  letter-spacing: 0.06em;
  flex-shrink: 0;
}
.map-stats {
  flex: 1;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-dim);
  text-align: center;
}
#map-close {
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
}
#map-close:hover { border-color: var(--accent); color: var(--accent); }

/* Graph container (hosts the Cytoscape canvas, or the SVG fallback) */
.map-graph-wrap {
  position: relative;
  background: #14100c;
  border-radius: 4px;
}
.cy-graph {
  width: 100%;
  height: 70vh;
  min-height: 480px;
  max-height: 760px;
  position: relative;
}
.cy-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink-dim);
  font-style: italic;
}

/* HTML compass overlay (top-right of the graph) */
.map-compass {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 70px;
  height: 70px;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: rgba(20, 16, 12, 0.7);
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  font-family: var(--serif);
  font-size: 13px;
  color: var(--accent);
  pointer-events: none;
  z-index: 2;
}
.map-compass .cn { grid-column: 2; grid-row: 1; justify-self: center; align-self: end; }
.map-compass .cw { grid-column: 1; grid-row: 2; justify-self: start; align-self: center; padding-left: 6px; }
.map-compass .ce { grid-column: 3; grid-row: 2; justify-self: end;   align-self: center; padding-right: 6px; }
.map-compass .cs { grid-column: 2; grid-row: 3; justify-self: center; align-self: start; }
.map-compass .cdot { grid-column: 2; grid-row: 2; justify-self: center; align-self: center; opacity: 0.6; }

/* SVG fallback only */
.map-panel svg {
  width: 100%;
  height: auto;
  display: block;
  background: #14100c;
  border-radius: 4px;
}
.map-panel svg .section-label {
  font-family: var(--serif);
  font-size: 14px;
  fill: var(--accent);
  font-variant: small-caps;
  letter-spacing: 0.08em;
}

/* Edges */
.map-panel svg .edge {
  stroke: var(--ink-dim);
  stroke-width: 1.4;
  fill: none;
}
.map-panel svg .edge.dim {
  stroke: var(--rule);
  stroke-dasharray: 2 4;
}
.map-panel svg .edge.stair {
  stroke: var(--accent);
  stroke-width: 1.2;
  stroke-dasharray: 4 4;
  opacity: 0.7;
}

/* Rooms */
.map-panel svg .room rect {
  stroke: var(--rule);
  stroke-width: 1.2;
}
.map-panel svg .room text {
  font-family: var(--serif);
  font-size: 12px;
  fill: var(--ink);
  pointer-events: none;
}

.map-panel svg .room.unknown rect {
  fill: #1a140e;
  stroke: var(--rule);
  stroke-dasharray: 3 3;
}
.map-panel svg .room.unknown text {
  fill: var(--ink-dim);
  font-style: italic;
}

.map-panel svg .room.visited rect {
  fill: #2a1f15;
  stroke: var(--ink-dim);
}
.map-panel svg .room.visited text {
  fill: var(--ink);
}

.map-panel svg .room.here rect {
  fill: var(--accent);
  stroke: var(--ink-bright);
  stroke-width: 2;
}
.map-panel svg .room.here text {
  fill: #14100c;
  font-weight: 700;
}

/* Legend */
.map-legend {
  margin-top: 10px;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-dim);
  padding-top: 8px;
  border-top: 1px solid var(--rule);
}
.map-legend .legend.here { color: var(--accent); font-weight: 600; }
.map-legend .legend.visited { color: var(--ink); }
.map-legend .legend.unknown { color: var(--ink-dim); font-style: italic; }
.map-legend .legend.stair { color: var(--accent); }
.map-legend .legend.hint { color: var(--ink-dim); margin-left: auto; font-style: italic; }

@media (max-width: 720px) {
  #map-overlay { padding: 8px; }
  .map-panel { padding: 10px; }
  .map-toolbar { flex-wrap: wrap; }
  .map-stats { width: 100%; text-align: left; }
}
