/* WBR2 MUD Web Client */

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-panel: #0f3460;
  --text-primary: #e0e0e0;
  --text-secondary: #a0a0a0;
  --accent: #e94560;
  --bar-hp: #e94560;
  --bar-mana: #4ea8de;
  --bar-move: #4ade80;
  --border: #2a2a4a;
  --exit-bg: #1a3a5c;
  --exit-hover: #2a5a8c;

  /* Auto-map (read by client.js via getComputedStyle) */
  --map-bg: #0d1526;
  --map-link: #35507a;
  --map-link-dim: #24344f;
  --map-room-seen: #4ea8de;
  --map-room-unseen: #33415c;
  --map-room-here: #e94560;
  --map-room-edge: #0d1526;
  --map-vert: #fbbf24;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.05em;
}

.status {
  font-size: 0.8rem;
  padding: 0.2rem 0.6rem;
  border-radius: 3px;
}

.status.connected {
  color: #4ade80;
  background: rgba(74, 222, 128, 0.1);
}

.status.disconnected {
  color: var(--accent);
  background: rgba(233, 69, 96, 0.1);
}

.status.connecting {
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.1);
}

/* Main layout */
#main {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* Terminal */
#terminal-container {
  flex: 1;
  min-width: 0;
  max-width: 100%;
  padding: 4px;
  background: #000;
  overflow: hidden;          /* xterm's canvas must never widen the body */
}

#terminal {
  height: 100%;
  width: 100%;
  overflow: hidden;
}

/* Make xterm fill its container */
.xterm {
  height: 100%;
}

/* Sidebar */
#sidebar {
  width: 220px;
  flex-shrink: 0;
  overflow-y: auto;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0;
}

.panel {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.panel.hidden {
  display: none;
}

.panel h3 {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Stat bars */
.stat-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.stat-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.stat-bar label {
  width: 36px;
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.bar-container {
  flex: 1;
  height: 14px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 2px;
  overflow: hidden;
}

.bar {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s ease;
}

.bar-hp { background: var(--bar-hp); }
.bar-mana { background: var(--bar-mana); }
.bar-move { background: var(--bar-move); }

.bar-text {
  font-size: 0.7rem;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  color: var(--text-secondary);
  min-width: 50px;
  text-align: right;
}

/* Room info */
.room-zone {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

/* Exit grid - compass layout */
.exit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: auto auto auto;
  gap: 3px;
  max-width: 180px;
  margin: 0 auto;
}

.exit-btn {
  padding: 0.3rem;
  font-size: 0.7rem;
  font-family: inherit;
  background: var(--exit-bg);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  text-align: center;
  text-transform: capitalize;
  transition: background 0.15s;
}

.exit-btn:hover {
  background: var(--exit-hover);
}

.exit-btn:active {
  background: var(--accent);
}

.exit-placeholder {
  /* empty cell */
}

/* Auto-map panel */
.panel-head {
  margin-bottom: 0.5rem;
}

.panel-toggle {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  width: 100%;
  padding: 0;
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  text-align: left;
}

.panel-toggle:hover {
  color: var(--accent);
}

.panel-toggle:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 2px;
}

.panel-caret {
  font-size: 0.7rem;
  color: var(--text-secondary);
  transition: transform 0.15s ease;
}

.panel-toggle[aria-expanded="false"] .panel-caret {
  transform: rotate(-90deg);
}

#map-body.collapsed {
  display: none;
}

#map-canvas {
  display: block;
  width: 100%;
  height: 180px;
  background: var(--map-bg);
  border: 1px solid var(--border);
  border-radius: 3px;
}

.map-caption {
  margin-top: 0.35rem;
  font-size: 0.7rem;
  line-height: 1.3;
  color: var(--text-secondary);
  word-break: break-word;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.3rem;
  font-size: 0.62rem;
  color: var(--text-secondary);
}

.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}

.swatch {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 1px;
}

.swatch-here { background: var(--map-room-here); }
.swatch-seen { background: var(--map-room-seen); }
.swatch-unseen { background: var(--map-room-unseen); }

/* Character status */
.status-grid {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
}

.status-grid .label {
  color: var(--text-secondary);
}

/* Responsive: hide sidebar on narrow screens */
@media (max-width: 700px) {
  #sidebar {
    display: none;
  }
}

/* Short viewports (laptops, landscape phones): don't let the map crowd out
   the vitals/status panels.  The map panel is collapsible either way. */
@media (max-height: 720px) {
  #map-canvas {
    height: 132px;
  }
}

/* Scrollbar styling */
#sidebar::-webkit-scrollbar {
  width: 4px;
}

#sidebar::-webkit-scrollbar-track {
  background: transparent;
}

#sidebar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}
