/* ── Imports ──────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=Syne:wght@400;600;800&display=swap');

/* ── CSS Variables ────────────────────────────────── */
:root {
  --bg-base:      #0d0f14;
  --bg-panel:     #13161e;
  --bg-card:      #1a1e2a;
  --bg-card2:     #1f2435;
  --border:       #2a2f42;
  --border-bright:#3a4060;
  --text-primary: #e8eaf6;
  --text-secondary:#8892b0;
  --text-muted:   #4a5278;
  --accent-cyan:  #00e5ff;
  --accent-green: #00e676;
  --accent-yellow:#ffd740;
  --accent-red:   #ff5252;
  --accent-purple:#ce93d8;
  --accent-orange:#ffab40;

  /* cell colors */
  --cell-unknown: #1a1e2a;
  --cell-visited: #0d2137;
  --cell-safe:    #0d3320;
  --cell-frontier:#2d2500;
  --cell-agent:   #003366;
  --cell-pit:     #330d0d;
  --cell-wumpus:  #2d1a00;
}

/* ── Reset ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

body {
  font-family: 'Syne', sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
}

/* ── Scrollbar ────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 2px; }

/* ── Header ───────────────────────────────────────── */
header {
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.header-badge {
  background: var(--accent-cyan);
  color: #000;
  font-family: 'Space Mono', monospace;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 2px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
header h1 {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}
header h1 span { color: var(--accent-cyan); }
.header-sub {
  font-family: 'Space Mono', monospace;
  font-size: 0.65rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}
.header-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'Space Mono', monospace;
  font-size: 0.7rem;
  color: var(--text-secondary);
}
.pulse {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.3} }

/* ── Main Layout ──────────────────────────────────── */
.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Left Panel ───────────────────────────────────── */
.control-panel {
  width: 210px;
  min-width: 210px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 16px;
  gap: 14px;
  flex-shrink: 0;
}

.panel-section-title {
  font-family: 'Space Mono', monospace;
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--accent-cyan);
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.panel-section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
}
input[type="number"] {
  padding: 7px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: 'Space Mono', monospace;
  font-size: 0.82rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
}
input[type="number"]:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 2px rgba(0,229,255,0.1);
}

/* Buttons */
.btn {
  padding: 9px 12px;
  border: none;
  border-radius: 7px;
  font-family: 'Space Mono', monospace;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all 0.18s;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  position: relative;
  overflow: hidden;
}
.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: white;
  opacity: 0;
  transition: opacity 0.15s;
}
.btn:hover:not(:disabled)::before { opacity: 0.07; }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }

.btn.primary  { background: var(--accent-cyan);   color: #000; }
.btn.success  { background: var(--accent-green);  color: #000; }
.btn.warning  { background: var(--accent-orange); color: #000; }
.btn.danger   { background: var(--accent-red);    color: #fff; }

/* Legend */
.legend { display: flex; flex-direction: column; gap: 6px; }
.legend-item {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.72rem;
  color: var(--text-secondary);
}
.dot {
  width: 12px; height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.1);
}
.dot.agent       { background: var(--accent-cyan);   box-shadow: 0 0 6px var(--accent-cyan); }
.dot.safe        { background: var(--accent-green);  box-shadow: 0 0 6px var(--accent-green); }
.dot.frontier    { background: var(--accent-yellow); }
.dot.unknown     { background: var(--cell-unknown);  border-color: var(--border-bright); }
.dot.danger-dot  { background: var(--accent-red);    box-shadow: 0 0 6px var(--accent-red); }
.dot.visited     { background: #1e4a6e; }

/* ── Grid Section ─────────────────────────────────── */
.grid-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px 16px;
  gap: 16px;
  overflow: auto;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(0,229,255,0.04) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 80%, rgba(0,230,118,0.03) 0%, transparent 60%),
    var(--bg-base);
}

#grid-container {
  display: inline-grid;
  gap: 8px;
}

/* ── Cell ─────────────────────────────────────────── */
.cell {
  width: 84px;
  height: 84px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  position: relative;
  transition: background 0.3s, transform 0.2s, box-shadow 0.3s;
  border: 1px solid var(--border);
  cursor: default;
  user-select: none;
}
.cell:hover { transform: scale(1.06); z-index: 10; }

.cell .coord {
  position: absolute;
  top: 4px; left: 6px;
  font-family: 'Space Mono', monospace;
  font-size: 0.52rem;
  color: var(--text-muted);
  font-weight: 700;
  letter-spacing: 0.02em;
}
.cell .percept-icons {
  position: absolute;
  bottom: 4px;
  font-size: 0.62rem;
  letter-spacing: 1px;
}

/* Cell States */
.cell.unknown  {
  background: var(--cell-unknown);
  border-color: var(--border);
}
.cell.visited  {
  background: var(--cell-visited);
  border-color: #1e4a6e;
}
.cell.safe     {
  background: var(--cell-safe);
  border-color: rgba(0,230,118,0.3);
  box-shadow: inset 0 0 12px rgba(0,230,118,0.08);
}
.cell.frontier {
  background: var(--cell-frontier);
  border-color: rgba(255,215,64,0.3);
  box-shadow: inset 0 0 12px rgba(255,215,64,0.08);
}
.cell.agent    {
  background: var(--cell-agent);
  border-color: var(--accent-cyan);
  box-shadow: 0 0 16px rgba(0,229,255,0.35), inset 0 0 20px rgba(0,229,255,0.08);
}
.cell.pit      {
  background: var(--cell-pit);
  border-color: rgba(255,82,82,0.4);
  box-shadow: inset 0 0 16px rgba(255,82,82,0.12);
}
.cell.wumpus   {
  background: var(--cell-wumpus);
  border-color: rgba(255,171,64,0.4);
  box-shadow: inset 0 0 16px rgba(255,171,64,0.12);
}

/* ── Status Bar ───────────────────────────────────── */
#status-bar {
  font-family: 'Space Mono', monospace;
  font-size: 0.75rem;
  color: var(--text-secondary);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 18px;
  width: 100%;
  max-width: 640px;
  text-align: center;
  letter-spacing: 0.02em;
}

/* ── Right Panel ──────────────────────────────────── */
.metrics-panel {
  width: 280px;
  min-width: 260px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 16px;
  gap: 14px;
  flex-shrink: 0;
}

/* ── Metrics Grid ─────────────────────────────────── */
.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.metric-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.3s;
}
.metric-box::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
}
.metric-box.cyan::before   { background: var(--accent-cyan); }
.metric-box.green::before  { background: var(--accent-green); }
.metric-box.yellow::before { background: var(--accent-yellow); }
.metric-box.purple::before { background: var(--accent-purple); }

.metric-label {
  font-family: 'Space Mono', monospace;
  font-size: 0.58rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}
.metric-value {
  font-family: 'Space Mono', monospace;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}
.metric-box.cyan   .metric-value { color: var(--accent-cyan); }
.metric-box.green  .metric-value { color: var(--accent-green); }
.metric-box.yellow .metric-value { color: var(--accent-yellow); }
.metric-box.purple .metric-value { color: var(--accent-purple); }

/* Agent Status (full width) */
.metric-box.full {
  grid-column: 1 / -1;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}
.metric-box.full .metric-value { font-size: 0.82rem; }
.metric-box.red::before { background: var(--accent-red); }
.metric-box.red .metric-value { color: var(--accent-red); }

/* ── Percept Box ──────────────────────────────────── */
.percept-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-yellow);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: 'Space Mono', monospace;
  font-size: 0.75rem;
  color: var(--accent-yellow);
  min-height: 42px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}
.percept-tag {
  background: rgba(255,215,64,0.12);
  border: 1px solid rgba(255,215,64,0.3);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.68rem;
  letter-spacing: 0.05em;
}

/* ── KB Box ───────────────────────────────────────── */
.kb-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-green);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: 'Space Mono', monospace;
  font-size: 0.65rem;
  color: var(--accent-green);
  max-height: 180px;
  overflow-y: auto;
  line-height: 1.8;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ── Log Box ──────────────────────────────────────── */
.log-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-purple);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: 'Space Mono', monospace;
  font-size: 0.63rem;
  max-height: 160px;
  overflow-y: auto;
  line-height: 1.8;
  flex: 1;
}
.log-entry       { color: var(--text-secondary); border-bottom: 1px solid var(--border); padding: 1px 0; }
.log-entry:last-child { border-bottom: none; }
.log-warn        { color: var(--accent-yellow) !important; }
.log-error       { color: var(--accent-red) !important; }
.log-info        { color: var(--accent-cyan) !important; }

/* Divider */
.divider {
  height: 1px;
  background: var(--border);
  flex-shrink: 0;
}