:root {
  --bg: #0d1117;
  --bg-soft: rgba(13, 17, 23, 0.74);
  --panel: rgba(12, 20, 26, 0.9);
  --border: rgba(126, 231, 135, 0.18);
  --text: #c9d1d9;
  --muted: #8b949e;
  --green: #7ee787;
  --amber: #e3b341;
  --red: #ff7b72;
  --blue: #79c0ff;
  --shadow: 0 0 0 1px rgba(126, 231, 135, 0.06), 0 8px 30px rgba(0, 0, 0, 0.3);
}

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

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at top, rgba(126, 231, 135, 0.07), transparent 28%),
    radial-gradient(circle at bottom right, rgba(121, 192, 255, 0.08), transparent 24%),
    var(--bg);
  color: var(--text);
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
}

.backdrop {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(126, 231, 135, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(126, 231, 135, 0.025) 1px, transparent 1px);
  background-size: 32px 32px;
  pointer-events: none;
}

/* ── Shell ── */
.shell {
  position: relative;
  z-index: 1;
  width: min(1600px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 12px 0 24px;
}

/* ── Hero (compact) ── */
.hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.kicker {
  margin: 0 0 2px;
  color: var(--amber);
  letter-spacing: 0.22em;
  font-size: 0.65rem;
}

h1 {
  margin: 0;
  font-size: 1.4rem;
  line-height: 1;
  text-transform: uppercase;
}

h2 { margin: 0; text-transform: uppercase; }

.lede, .mode-copy p { display: none; } /* hide verbose text to save space */

.hero-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

button, .ghost {
  border: 1px solid rgba(126, 231, 135, 0.3);
  background: rgba(126, 231, 135, 0.08);
  color: var(--green);
  padding: 6px 12px;
  text-decoration: none;
  cursor: pointer;
  font: inherit;
  font-size: 0.75rem;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

button.alt {
  color: var(--blue);
  border-color: rgba(121, 192, 255, 0.35);
  background: rgba(121, 192, 255, 0.08);
}

button:hover, .ghost:hover {
  transform: translateY(-1px);
  border-color: rgba(126, 231, 135, 0.55);
}

/* ── Mode banner (hidden by default, show only if needed) ── */
.mode-banner { display: none; }

/* ── Main Layout: map-dominant ── */
.layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  grid-template-rows: auto;
  gap: 10px;
  align-items: start;
}

.sidebar {
  display: grid;
  gap: 6px;
  max-height: calc(100vh - 70px);
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(126, 231, 135, 0.15) transparent;
  position: sticky;
  top: 10px;
}

/* ── Panels ── */
.panel {
  background: linear-gradient(180deg, rgba(17, 24, 31, 0.9), rgba(11, 18, 24, 0.96));
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 10px;
  overflow: hidden;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(126, 231, 135, 0.08);
  color: var(--green);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ── MAP (big, dominant) ── */
.map-panel {
  display: flex;
  flex-direction: column;
}

.map-area {
  display: flex;
  flex: 1;
}

.inventory-rail {
  width: 140px;
  min-width: 140px;
  background: rgba(8, 14, 18, 0.95);
  border-right: 1px solid rgba(126, 231, 135, 0.1);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(126, 231, 135, 0.15) transparent;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rail-section {
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  padding: 4px 6px;
  background: rgba(255, 255, 255, 0.02);
}

.rail-section.rogue { border-color: rgba(126, 231, 135, 0.18); }
.rail-section.rook { border-color: rgba(121, 192, 255, 0.18); }

.rail-section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding-bottom: 3px;
  margin-bottom: 3px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.rail-section.rogue .rail-section-head { color: var(--green); }
.rail-section.rook .rail-section-head { color: var(--blue); }

.rail-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 2px 3px;
  font-size: 0.7rem;
  border-radius: 3px;
  cursor: default;
  transition: background 120ms;
}

.rail-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.rail-item .ri-key {
  color: var(--muted);
  font-size: 0.6rem;
  min-width: 12px;
}

.rail-item .ri-glyph {
  font-size: 0.8rem;
}

.rail-item .ri-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.rail-empty {
  font-size: 0.65rem;
  color: var(--muted);
  padding: 2px 3px;
  font-style: italic;
}

.map-shell {
  position: relative;
  overflow: auto;
  touch-action: manipulation;
  flex: 1;
}

.map {
  display: grid;
  grid-template-columns: repeat(48, 1.4em);
  grid-auto-rows: 1.4em;
  gap: 0;
  padding: 8px 12px;
  font-size: clamp(0.85rem, 1.6vw, 1.2rem);
  line-height: 1;
  background: linear-gradient(180deg, rgba(4, 11, 14, 0.9), rgba(7, 10, 15, 1));
  transition: filter 180ms ease, opacity 180ms ease;
}

.damage-layer, .floor-flash {
  position: absolute;
  inset: 12px 16px;
  pointer-events: none;
}

.floor-flash.flash { animation: floor-flash 500ms ease; }

/* ── Cells ── */
.cell {
  width: 1.4em;
  height: 1.4em;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #31414f;
  font-size: 1em;
  overflow: hidden;
  transition: opacity 150ms ease, color 150ms ease, text-shadow 150ms ease, background 150ms ease;
}

.cell.fade-in { animation: tile-fade 200ms ease; }

.cell.visible.wall { font-size: 0.85em; opacity: 0.7; filter: saturate(0.3) brightness(0.5); }
.cell.visible.floor { font-size: 0.6em; opacity: 0.15; }
.cell.visible.door { font-size: 0.9em; }
.cell.visible.stairs { font-size: 0.95em; }
.cell.visible.trap { font-size: 0.8em; }
.cell.visible.treasure { font-size: 0.9em; }
.cell.visible.barrier { font-size: 0.85em; }
.cell.explored { opacity: 0.2; filter: saturate(0); }
.cell.fov-rogue.visible { background: rgba(126, 231, 135, 0.04); }
.cell.fov-rook.visible { background: rgba(121, 192, 255, 0.05); }

.cell.player {
  font-size: 1.15em;
  filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.4));
  z-index: 2;
  position: relative;
}
.cell.player.rogue {
  filter: drop-shadow(0 0 8px rgba(126, 231, 135, 0.8));
  animation: pulse-player 1200ms ease-in-out infinite;
}
.cell.player.rook {
  filter: drop-shadow(0 0 8px rgba(121, 192, 255, 0.7));
}
.cell.monster {
  font-size: 1.05em;
  filter: drop-shadow(0 0 5px rgba(255, 123, 114, 0.3));
}
.cell.item {
  font-size: 0.9em;
  filter: drop-shadow(0 0 4px rgba(242, 204, 96, 0.3));
}

/* ── Turn indicator ── */
.turn-indicator {
  padding: 2px 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
}

.turn-indicator.rogue-turn {
  color: var(--green);
  border-color: rgba(126, 231, 135, 0.4);
  background: rgba(126, 231, 135, 0.08);
}

.turn-indicator.rook-turn {
  color: var(--blue);
  border-color: rgba(121, 192, 255, 0.4);
  background: rgba(121, 192, 255, 0.06);
  animation: pulse-rook 1000ms ease-in-out infinite;
}

.turn-indicator.monster-turn {
  color: var(--red);
  border-color: rgba(255, 123, 114, 0.45);
}

/* ── Sidebar panels (compact) ── */
.stats, .inventory, .threats, .controls-help, .threat-detail, .chat-log {
  padding: 8px 12px;
}

.log { padding: 8px 12px; }

/* ── Stats (dual) ── */
.dual-stats, .dual-inventory {
  display: grid;
  gap: 8px;
}

.character-card, .inventory-block {
  padding: 6px 8px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.025);
  border-radius: 6px;
}

.character-card.rogue, .inventory-block.rogue { border-color: rgba(126, 231, 135, 0.16); }
.character-card.rook, .inventory-block.rook { border-color: rgba(121, 192, 255, 0.16); }
.inventory-block.active { box-shadow: inset 0 0 0 1px rgba(227, 179, 65, 0.25); }

.character-head, .inventory-block-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  font-size: 0.75rem;
  gap: 6px;
}

.character-level {
  color: var(--muted);
  font-size: 0.68rem;
}

.stat-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.7rem;
  color: var(--muted);
}

.stat-row strong {
  color: var(--text);
}

.character-glyph { font-size: 1rem; }

.bar-block { margin-bottom: 5px; }

.bar-block label, .stat-grid span, .record span, .history-item span, .death-stats span, .chat-meta {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
}

.bar, .threat-bar {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(126, 231, 135, 0.1);
}

.bar span, .threat-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--green), #2ea043);
}

.bar.xp span { background: linear-gradient(90deg, var(--amber), #bb8009); }
.threat-bar { height: 6px; }
.threat-bar span { background: linear-gradient(90deg, #ff7b72, #ffb36b); }

.stat-grid, .stats-grid, .death-stats { display: grid; gap: 6px; }
.stat-grid, .death-stats { grid-template-columns: repeat(3, 1fr); }
.stat-grid strong, .record strong { font-size: 0.82rem; white-space: pre-wrap; }

/* ── Inventory ── */
.inventory, .run-history { display: grid; gap: 4px; }

.inventory-item, .history-item {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 6px;
  align-items: start;
  padding: 4px 6px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid rgba(126, 231, 135, 0.06);
  border-radius: 4px;
  font-size: 0.78rem;
}

.history-item { grid-template-columns: 1fr; }

.inventory-item p, .empty, .threat-row p, .threat-detail p, .controls-help p, .history-item p, .chat-line span:last-child {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
}

/* ── Threats ── */
.threats { display: grid; gap: 4px; padding-bottom: 0; }

.threat-row {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 123, 114, 0.08);
  padding: 4px 8px;
  font-size: 0.78rem;
}

.threat-row.active {
  border-color: rgba(255, 123, 114, 0.45);
  background: rgba(255, 123, 114, 0.08);
}

.threat-glyph { font-size: 0.9rem; padding-top: 1px; }

.threat-detail {
  border-top: 1px solid rgba(126, 231, 135, 0.08);
  color: #b7c4cf;
  font-size: 0.75rem;
}

/* ── Minimap ── */

#minimap {
  display: block;
  width: 100%;
  max-width: 240px;
  height: auto;
  border: 1px solid rgba(126, 231, 135, 0.12);
  background: rgba(5, 9, 13, 0.95);
  image-rendering: pixelated;
}

/* ── Controls ── */
.controls-help kbd {
  border: 1px solid rgba(126, 231, 135, 0.18);
  padding: 1px 4px;
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.72rem;
}

.controls-help p { font-size: 0.72rem; }

/* ── Chat ── */
.chat-log {
  max-height: 100px;
  overflow-y: auto;
  display: grid;
  gap: 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(126, 231, 135, 0.15) transparent;
}

.chat-line {
  display: grid;
  gap: 2px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 0.78rem;
}

.chat-line.rook { color: #b9d4ff; }
.chat-line.rogue { color: #9ff0ad; }

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  padding: 0 12px 8px;
}

.chat-form input {
  width: 100%;
  border: 1px solid rgba(126, 231, 135, 0.12);
  background: rgba(0, 0, 0, 0.18);
  color: var(--text);
  padding: 6px 8px;
  font: inherit;
  font-size: 0.75rem;
  border-radius: 4px;
}

.chat-form button { font-size: 0.72rem; padding: 6px 10px; }

/* ── Game Log (compact, below map) ── */
.log-panel {
  margin-top: 10px;
}

.log {
  max-height: 150px;
  overflow-y: auto;
  display: grid;
  gap: 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(126, 231, 135, 0.15) transparent;
}

.log-line {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 0.75rem;
  align-items: baseline;
}

.log-meta {
  color: var(--muted);
  font-size: 0.65rem;
  white-space: nowrap;
}

.log-line.combat { color: #ff9e98; }
.log-line.loot { color: #ffd77a; }
.log-line.movement { color: #a2b0bb; }
.log-line.level { color: #8df2a4; }
.log-line.warning, .log-line.error { color: #ff7b72; }
.log-line.chat { color: #8cbaff; }

/* ── Hidden to save space ── */
.ai-suggest { display: none; }
.controls-card { display: none; } /* users know arrow keys */
.minimap-wrap { padding: 4px 10px 6px; }
.threat-detail { padding: 4px 10px; font-size: 0.7rem; }

/* ── Stats page ── */
.stats-grid {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.record {
  padding: 12px;
  border: 1px solid rgba(126, 231, 135, 0.07);
  background: rgba(255, 255, 255, 0.02);
  border-radius: 6px;
}

/* ── Damage floats ── */
.damage-float {
  position: absolute;
  font-size: 0.85rem;
  font-weight: 700;
  animation: float-up 1100ms ease forwards;
  text-shadow: 0 0 12px rgba(0, 0, 0, 0.8);
}

.damage-float.player-hit { color: #ffd166; }
.damage-float.monster-hit { color: #ff7b72; }

/* ── Death screen ── */
.death-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 8, 10, 0.78);
  backdrop-filter: blur(6px);
  z-index: 5;
}

.death-screen.hidden { display: none; }

.death-card {
  width: min(480px, calc(100vw - 32px));
  padding: 24px;
  border: 1px solid rgba(255, 123, 114, 0.28);
  background: linear-gradient(180deg, rgba(26, 14, 17, 0.96), rgba(11, 9, 12, 0.98));
  box-shadow: 0 18px 80px rgba(0, 0, 0, 0.5);
  border-radius: 12px;
}

.death-cause { color: #f3b0aa; margin: 8px 0; }

.death-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

/* ── Animations ── */
@keyframes pulse-player {
  0%, 100% { text-shadow: 0 0 8px rgba(126, 231, 135, 0.65); }
  50% { text-shadow: 0 0 18px rgba(126, 231, 135, 1); }
}

@keyframes pulse-rook {
  0%, 100% { box-shadow: inset 0 0 0 0 rgba(121, 192, 255, 0.15); }
  50% { box-shadow: inset 0 0 0 999px rgba(121, 192, 255, 0.05); }
}

@keyframes tile-fade {
  from { opacity: 0.45; }
  to { opacity: 1; }
}

@keyframes float-up {
  0% { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(-24px); opacity: 0; }
}

@keyframes floor-flash {
  0% { background: rgba(255, 255, 255, 0); }
  50% { background: rgba(121, 192, 255, 0.12); }
  100% { background: rgba(255, 255, 255, 0); }
}

/* ── Mobile ── */
@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    max-height: none;
    overflow: visible;
  }

  .map {
    min-width: 48ch;
    font-size: 0.72rem;
  }

  .map-area { flex-direction: column; }
  .inventory-rail {
    width: 100%;
    min-width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid rgba(126, 231, 135, 0.1);
    max-height: 80px;
    overflow-x: auto;
  }
  .rail-section { flex: 1; min-width: 120px; }

  .chat-form { grid-template-columns: 1fr; }
}

/* ── Wide screens: give map even more room ── */
@media (min-width: 1400px) {
  .layout {
    grid-template-columns: 1fr 320px;
  }
  .map {
    font-size: 1.35rem;
    line-height: 1.22;
  }
}

@media (min-width: 1700px) {
  .map {
    font-size: 1.5rem;
    line-height: 1.25;
  }
}
