:root {
  color-scheme: dark;
  --bg: #0d0f12;
  --panel: #161a20;
  --border: #2a2f38;
  --text: #d8dee6;
  --dim: #7d8794;
  --accent: #57c785;
  --warn: #e0a458;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 1.1rem;
  margin: 0;
}

.status {
  color: var(--dim);
  font-size: 0.85rem;
}

.status.connected {
  color: var(--accent);
}

.controls {
  margin-left: auto;
  display: flex;
  gap: 0.5rem;
}

.learning-link {
  color: var(--dim);
  font-size: 0.85rem;
  text-decoration: none;
}

.learning-link:hover {
  color: var(--accent);
}

.controls button {
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.35rem 0.9rem;
  cursor: pointer;
}

.controls button:hover:not(:disabled) {
  border-color: var(--accent);
}

.batch-bar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.5rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.batch-toggle,
.batch-count {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--dim);
}

.batch-toggle:has(input:checked) {
  color: var(--text);
}

.batch-count input {
  width: 4.5rem;
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.2rem 0.4rem;
}

.batch-count input:disabled,
.batch-toggle input:disabled {
  opacity: 0.5;
}

.batch-bar button {
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.35rem 0.9rem;
  cursor: pointer;
}

.batch-bar button:hover:not(:disabled) {
  border-color: var(--accent);
}

.batch-bar button:disabled {
  color: var(--dim);
  cursor: default;
  opacity: 0.6;
}

#pass-progress {
  margin-left: auto;
}

.controls button:disabled {
  color: var(--dim);
  cursor: default;
  opacity: 0.6;
}

main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1rem;
  padding: 1rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  min-height: 0;
}

.map-panel {
  /* Brogue's own rendering already supplies a real background per cell
     (mostly near-black ambient lighting) -- match its true backdrop
     instead of the UI's panel navy, so cell colors read correctly. */
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.map-panel pre {
  margin: 0;
  line-height: 1.15;
  white-space: pre;
}

.start-overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
}

.start-overlay[hidden] {
  display: none;
}

.start-overlay button {
  font-family: inherit;
  font-size: 1.25rem;
  font-weight: 700;
  color: #0d0f12;
  background: var(--accent);
  border: 1px solid #8fd694;
  border-radius: 4px;
  padding: 0.8rem 1.4rem;
  cursor: pointer;
}

.start-overlay button:hover:not(:disabled) {
  background: #8fd694;
}

.start-overlay button:focus-visible {
  outline: 3px solid var(--text);
  outline-offset: 4px;
}

.start-overlay button:disabled {
  cursor: default;
  opacity: 0.7;
}

.stats-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow: hidden;
}

.stats-panel h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--dim);
  margin: 1rem 0 0.4rem;
}

.stats-panel h2:first-child {
  margin-top: 0;
}

.panel-upper {
  /* flex-shrink: 0 -- this box's own size is never negotiable. Left at the
     default shrink:1, a long enough Decisions/History log pushed .panel-lower
     past its hypothetical size and the flex algorithm compressed this box
     to make room, clipping player stats out of view -- worse the longer a
     run went, since the log only ever grows. max-height still caps it and
     hands overflow to its own scrollbar if stats ever genuinely exceed 45%. */
  flex: 0 0 auto;
  overflow-y: auto;
  max-height: 45%;
}

.panel-lower {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
  padding-top: 0.65rem;
}

#lower-panel-select {
  font-family: inherit;
  font-size: 0.8rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem 0.5rem;
  margin-bottom: 0.6rem;
  align-self: flex-start;
}

.lower-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.lower-content[hidden] {
  display: none;
}

dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.15rem 0.6rem;
  font-size: 0.85rem;
}

dt {
  color: var(--dim);
}

dd {
  margin: 0;
  text-align: right;
}

#decision-log,
#history-log,
#learnings-log,
#inventory-list,
#run-history,
#lessons {
  margin: 0;
  padding-left: 0;
  list-style: none;
  font-size: 0.8rem;
}

#decision-log li {
  margin-bottom: 0.5rem;
  color: var(--dim);
}

#decision-log li .action {
  color: var(--text);
  font-weight: 600;
}

#decision-log li .confidence {
  color: var(--accent);
}

#decision-log li .source {
  color: var(--warn);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.7rem;
}

/* Newly learned knowledge, inline among the decisions -- set off with a
   rule so it reads as a different kind of event at a glance. */
#decision-log li.discovery {
  border-left: 2px solid var(--accent);
  padding-left: 0.5rem;
}

#decision-log li.discovery .discovery-label {
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.7rem;
}

#decision-log li.discovery .discovery-detail {
  color: var(--dim);
  font-size: 0.75rem;
  margin-top: 0.15rem;
}

#run-history li,
#lessons li,
#history-log li,
#learnings-log li {
  margin-bottom: 0.5rem;
  color: var(--dim);
}

#history-log li .turn,
#learnings-log li .turn {
  color: var(--dim);
}

#learnings-log li .knowledge-block {
  color: var(--text);
}

#learnings-log li .advice-text {
  color: var(--dim);
  font-size: 0.75rem;
  display: block;
  margin-top: 0.1rem;
}

#inventory-list li {
  margin-bottom: 0.35rem;
  color: var(--dim);
}

#inventory-list li .item-name {
  color: var(--text);
}

#inventory-list li .equipped-tag {
  color: var(--accent);
  font-size: 0.7rem;
  text-transform: uppercase;
  margin-left: 0.3rem;
}

#run-history .outcome {
  color: var(--text);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.7rem;
}

#run-history .outcome.died {
  color: var(--warn);
}

#run-history .outcome.amulet_escaped {
  color: var(--accent);
}


/* Two-stage decisions: the verb Jev chose, then what it applied it to. */
.operand {
  color: #8fd694;
}

.target {
  color: #d69a8f;
}


/* A supervisor intervention: what Jev asked for, and what was sent instead. */
.supervision {
  border-left: 3px solid #d6a44f;
  padding-left: 8px;
}
