:root {
  --bg: #0f1218;
  --panel: #171c26;
  --text: #e8ecf2;
  --muted: #9aa6b8;
  --accent: #d4a84b;
  --line: #2a3344;
  --here: #6ec6ff;
  --ok: #7dcea0;
  --header-h: 2.75rem;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
}

.top {
  flex: 0 0 var(--header-h);
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0 0.75rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  min-height: 0;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
  font-size: 0.95rem;
}

/* Sprint 5 — world calendar clock */
.game-clock {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--accent);
  padding: 0.2rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(212, 168, 75, 0.08);
  white-space: nowrap;
}

.status {
  flex: 1;
  min-width: 0;
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.actions {
  display: flex;
  gap: 0.3rem;
  flex-shrink: 0;
}

button {
  background: #243044;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.3rem 0.55rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
}

button:hover {
  border-color: var(--accent);
}

button.active {
  background: #3a4a28;
  border-color: var(--accent);
}

/* Main fills remaining viewport; never grows past it */
.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr minmax(240px, 300px);
  overflow: hidden;
}

.layout.map-hidden {
  grid-template-columns: 1fr;
}

.viewport-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #000;
}

#viewport {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Top info overlay — compact, no page scroll */
.hud-top {
  position: absolute;
  left: 0.75rem;
  top: 0.65rem;
  right: 0.75rem;
  max-width: 26rem;
  pointer-events: none;
  text-shadow: 0 1px 3px #000;
  z-index: 2;
}

.hud-top h1 {
  margin: 0 0 0.15rem;
  font-size: 1.15rem;
  line-height: 1.2;
}

.hud-top p {
  margin: 0.12rem 0;
  color: #dce4f0;
  font-size: 0.85rem;
  line-height: 1.3;
}

.summary-clamp {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  max-height: 2.6em;
  color: #c5cdd8 !important;
  font-size: 0.8rem !important;
}

.message {
  color: var(--ok) !important;
  min-height: 0;
  max-height: 2.6em;
  overflow: hidden;
}

.vitals {
  color: var(--accent) !important;
  font-weight: 600;
  font-size: 0.82rem !important;
}

/* Bottom dock — combat / exits always visible without scrolling the page */
.hud-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  padding: 0.55rem 0.75rem calc(0.55rem + env(safe-area-inset-bottom, 0));
  background: linear-gradient(
    to top,
    rgba(8, 10, 14, 0.92) 0%,
    rgba(8, 10, 14, 0.75) 55%,
    transparent 100%
  );
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.4rem;
}

.hud-bottom > * {
  pointer-events: auto;
}

.party-line {
  font-size: 0.8rem;
  color: #b8c4d8;
  text-shadow: 0 1px 3px #000;
  max-width: 100%;
}

.dock-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  max-width: 100%;
}

.btn-talk {
  background: rgba(30, 45, 60, 0.95);
  border-color: #6a8aaa;
  flex-shrink: 0;
}

.exit-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  max-width: 100%;
  flex: 1 1 auto;
}

.exit-list button {
  font-size: 0.8rem;
  background: rgba(20, 28, 40, 0.92);
}

.combat-panel {
  padding: 0.45rem 0.55rem;
  background: rgba(40, 18, 18, 0.94);
  border: 1px solid #a05050;
  border-radius: 8px;
  max-width: min(22rem, 100%);
}

.combat-panel.hidden,
.dead-panel.hidden {
  display: none;
}

.combat-foe {
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: #ffb4b4;
  font-size: 0.9rem;
}

.combat-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.combat-actions button {
  background: #5a2828;
  border-color: #c07070;
  font-size: 0.9rem;
  padding: 0.4rem 0.85rem;
  min-width: 4.5rem;
}

.dead-panel {
  padding: 0.45rem 0.55rem;
  background: rgba(20, 20, 30, 0.94);
  border: 1px solid #666;
  border-radius: 8px;
}

.dead-panel p {
  margin: 0 0 0.35rem;
  font-size: 0.9rem;
}

.dead-panel button {
  background: #2a3a4a;
}

/* Side map: own column, internal scroll only */
.map-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 0.65rem 0.75rem;
  overflow: hidden;
}

.map-panel.hidden {
  display: none;
}

.map-panel h2 {
  margin: 0;
  font-size: 0.95rem;
  color: var(--accent);
  flex-shrink: 0;
}

.map-sub {
  margin: 0.15rem 0 0.5rem;
  color: var(--muted);
  font-size: 0.75rem;
  flex-shrink: 0;
}

#world-map {
  width: 100%;
  flex: 0 0 auto;
  height: min(200px, 28vh);
  background: #0c1018;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.map-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  margin-top: 0.35rem;
}

.inv-title {
  margin: 0.55rem 0 0.25rem;
  font-size: 0.8rem;
  color: var(--accent);
}

.inv-list {
  list-style: none;
  padding: 0;
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.inv-list li {
  padding: 0.08rem 0;
}

#world-map .edge {
  stroke: #3d4d66;
  stroke-width: 2;
}

#world-map .edge.reachable {
  stroke: var(--accent);
  stroke-width: 2.5;
}

#world-map .node {
  cursor: pointer;
}

#world-map .node circle {
  fill: #243044;
  stroke: #6a7a94;
  stroke-width: 2;
}

#world-map .node.here circle {
  fill: #1a3a4a;
  stroke: var(--here);
  stroke-width: 3;
}

#world-map .node.reachable circle {
  fill: #3a3420;
  stroke: var(--accent);
}

#world-map .node text {
  fill: var(--text);
  font-size: 11px;
  text-anchor: middle;
  pointer-events: none;
  user-select: none;
}

.trail {
  list-style: none;
  padding: 0;
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.75rem;
}

.trail li {
  padding: 0.1rem 0;
}

.trail li::before {
  content: "→ ";
  color: var(--line);
}

.trail li:first-child::before {
  content: "";
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr minmax(0, 34%);
  }

  .map-panel {
    border-left: none;
    border-top: 1px solid var(--line);
  }

  #world-map {
    height: min(140px, 18vh);
  }
}
