:root {
  --bg: #14181f;
  --panel: #1c222c;
  --panel-2: #232a36;
  --border: #2e3746;
  --text: #e7ecf3;
  --muted: #9aa6b8;
  --accent: #c4a35a;
  --accent-dim: #8a7340;
  --user: #2a3544;
  --bot: #243028;
  --danger: #c45a5a;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", "Cascadia Mono", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

.shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
}

.history-header h3 {
  margin: 0;
  font-size: 0.85rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.run-list {
  list-style: none;
  margin: 0;
  padding: 0.15rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  overflow-x: hidden;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  padding: 0.45rem;
}

.run-list > li {
  margin: 0;
  flex-shrink: 0;
}

.run-container {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  overflow: hidden;
}

.run-container-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: 0;
  border-radius: 0;
  padding: 0.5rem 0.7rem;
  font-weight: 500;
  font-size: 0.82rem;
  line-height: 1.3;
  cursor: pointer;
}

.run-container-toggle:hover {
  color: var(--accent);
  background: var(--panel-2);
}

.run-toggle-mark {
  flex: 0 0 1.1rem;
  width: 1.1rem;
  height: 1.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1;
}

.run-container-label {
  flex: 1 1 auto;
  min-width: 0;
}

.run-container-count {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.72rem;
  font-family: var(--mono);
}

.run-children {
  list-style: none;
  margin: 0;
  padding: 0 0.45rem 0.45rem 1.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.run-children button {
  width: 100%;
  text-align: left;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.65rem;
  font-weight: 500;
  font-size: 0.78rem;
  line-height: 1.3;
  cursor: pointer;
  white-space: normal;
}

.run-children button:hover,
.run-children button.active {
  border-color: var(--accent-dim);
  color: var(--accent);
}

.run-list .run-meta {
  display: block;
  color: var(--muted);
  font-size: 0.7rem;
  margin-top: 0.2rem;
}

.run-list .empty {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0.5rem;
}

.history-panel {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.history-log {
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  font-size: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.65rem 0.75rem;
  flex: 1 1 auto;
  min-height: 0;
}

.tabs {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0;
}

.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0.4rem 0.85rem;
  font-weight: 600;
  cursor: pointer;
  align-self: center;
}

.tab.active {
  color: var(--accent);
  border-color: var(--accent-dim);
  background: var(--panel-2);
}

.tab-meta {
  margin-left: auto;
}

.tab-settings {
  color: var(--muted);
}

.modal[hidden] {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 10, 14, 0.72);
}

.modal-panel {
  position: relative;
  z-index: 1;
  width: min(28rem, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.1rem 0.85rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.modal-header h2 {
  margin: 0;
}

.modal-close {
  min-width: 2rem;
  padding: 0.25rem 0.45rem;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.settings-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  cursor: pointer;
}

.settings-label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.95rem;
  color: var(--text);
}

.settings-hint {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.settings-row input[type="checkbox"] {
  margin-top: 0.2rem;
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.settings-fieldset {
  cursor: default;
  flex-direction: column;
  align-items: stretch;
  gap: 0.65rem;
}

.settings-fieldset legend {
  padding: 0;
  float: none;
  width: 100%;
}

.mode-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  background: var(--panel-2);
}

.mode-btn,
.mode-opt {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.28rem 0.7rem;
  cursor: pointer;
}

.mode-opt {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  text-transform: none;
  letter-spacing: 0;
}

.mode-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.mode-toggle .mode-btn + .mode-btn {
  border-left: 1px solid var(--border);
}

.modal-footer {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

#settingsMsg {
  min-height: 1.1rem;
  margin: 0.35rem 0 0;
}

.app {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

.main-views {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.view {
  display: none;
  height: 100%;
  overflow: auto;
  padding: 1rem 1.25rem;
}

.main-views > .view.active {
  display: block;
}

.main-views > .view.combat.active,
.main-views > .view.loop.active {
  display: flex;
  flex-direction: column;
}

.chat-dock {
  display: flex;
  flex-direction: column;
  flex: 0 0 360px;
  width: 360px;
  max-width: 40vw;
  min-height: 0;
  border-left: 1px solid var(--border);
  background: var(--panel);
  overflow: hidden;
  padding: 0.75rem 0.85rem 0.85rem;
}

.chat-expand-tab {
  display: none;
  flex: 0 0 auto;
  align-self: stretch;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  transform: rotate(180deg);
  padding: 0.75rem 0.35rem;
  border: none;
  border-left: 1px solid var(--border);
  background: var(--panel);
  color: var(--accent);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}

.chat-expand-tab:hover {
  background: var(--panel-2);
  color: var(--text);
}

@media (min-width: 901px) {
  .shell.chat-collapsed .chat-dock {
    display: none;
  }

  .shell.chat-collapsed .chat-expand-tab {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

@media (max-width: 900px) {
  .app {
    flex-direction: column;
  }
  .chat-dock {
    flex: 0 0 auto;
    width: 100%;
    max-width: none;
    max-height: 40vh;
    border-left: none;
    border-top: 1px solid var(--border);
    transition: max-height 0.2s ease;
  }

  .shell.chat-collapsed .chat-dock {
    max-height: none;
  }

  .shell.chat-collapsed .chat-dock .messages,
  .shell.chat-collapsed .chat-dock .composer,
  .shell.chat-collapsed .chat-dock #chatMeta {
    display: none;
  }

  .shell.chat-collapsed .chat-dock .header-actions #clearChat,
  .shell.chat-collapsed .chat-dock .header-actions #chatCombatPill {
    display: none;
  }
}

.setup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.map-panel {
  grid-column: 1 / -1;
}

.hint {
  margin: 0.35rem 0 0.75rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.file-btn,
.map-controls .file-btn,
.accent-btn {
  display: inline-block;
  background: var(--accent) !important;
  color: #1a1408 !important;
  border: 1px solid var(--accent-dim);
  border-radius: 8px;
  padding: 0.45rem 0.85rem;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
  align-self: center;
}

/* Author display on .accent-btn beats the UA [hidden] rule otherwise. */
.file-btn[hidden],
.map-controls .file-btn[hidden],
.accent-btn[hidden] {
  display: none !important;
}

.accent-btn:hover,
.file-btn:hover {
  filter: brightness(1.08);
}

.import-list {
  margin: 0.75rem 0 0;
  padding-left: 0;
  list-style: none;
  font-size: 0.85rem;
  color: #d5dde8;
}

.import-list .unit-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.45rem 0.55rem;
  margin-bottom: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-2);
}

.import-list .unit-meta {
  font-size: 0.82rem;
  color: var(--text);
}

.import-list .tactics-stack {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.import-list .tactics-label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.import-list .tactics-label.secondary {
  padding-left: 0.65rem;
  border-left: 2px solid var(--border);
  color: #9aa7b8;
}

.import-list .tactics-select {
  flex: 1;
  min-width: 0;
  font-size: 0.8rem;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.25rem 0.4rem;
}

.import-list .muted {
  color: var(--muted);
  list-style: none;
  margin-left: -1.1rem;
}

.unit-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.loadout-btn {
  font-size: 0.75rem;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--accent);
  cursor: pointer;
}

.loadout-btn:hover {
  border-color: var(--accent);
}

.loadout-editor {
  margin-top: 0.35rem;
  padding: 0.55rem;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: var(--panel);
}

.loadout-editor[hidden] {
  display: none;
}

.loadout-section {
  margin-bottom: 0.65rem;
}

.loadout-section h3 {
  margin: 0 0 0.35rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.loadout-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(4.5rem, 1fr));
  gap: 0.3rem;
  align-items: end;
  margin-bottom: 0.35rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}

.loadout-row label {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.68rem;
  color: var(--muted);
}

.loadout-row input,
.loadout-row select {
  font-size: 0.78rem;
  padding: 0.2rem 0.3rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel-2);
  color: var(--text);
}

.loadout-row .row-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 0.35rem;
}

.loadout-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}

.loadout-toolbar button {
  font-size: 0.72rem;
  padding: 0.2rem 0.45rem;
}

.loadout-save {
  margin-top: 0.35rem;
}

  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.map-controls label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.map-controls input[type="number"] {
  width: 3.5rem;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.4rem;
}

.map-controls .check {
  color: var(--text);
}

.map-preview-row {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  min-width: 0;
}

#mapImg {
  width: min(100%, 480px);
  max-height: 220px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #0d1015;
}

.map-ascii {
  width: 100%;
  max-width: none;
  max-height: none;
  overflow-x: auto;
  overflow-y: visible;
  white-space: pre;
  font-size: 0.9rem;
  line-height: 1.4;
  letter-spacing: 0;
}

.setup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.setup-msg {
  flex: 1 1 100%;
  min-height: 1.2rem;
}

button.secondary {
  background: var(--panel-2);
  color: var(--accent);
  border: 1px solid var(--accent-dim);
}

.view.logs.active {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

/* Walkthrough open: cap list height so the log panel keeps room. */
.view.logs.active:has(.history-panel:not([hidden])) .run-list {
  flex: 0 0 auto;
  max-height: min(36vh, 16rem);
  min-height: 10rem;
}

.view.combat.active {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-width: none;
  margin: 0;
  padding: 0;
  height: 100%;
  min-height: 0;
}

.combat-theater-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-shrink: 0;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.theater-body {
  display: flex;
  align-items: stretch;
  gap: 0;
  flex-shrink: 0;
  min-height: 0;
  max-height: min(58vh, 640px);
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}

.init-roster {
  flex: 0 0 220px;
  width: 220px;
  min-width: 180px;
  max-width: 260px;
  overflow: auto;
  padding: 0.55rem 0.65rem 0.75rem;
  border-right: 1px solid var(--border);
  background: var(--panel);
}

.action-panel {
  flex: 0 0 240px;
  width: 240px;
  min-width: 200px;
  max-width: 280px;
  overflow: auto;
  padding: 0.55rem 0.65rem 0.75rem;
  border-left: 1px solid var(--border);
  background: var(--panel);
}

.theater-side-title {
  margin: 0.35rem 0 0.4rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}

.init-list,
.roster-list {
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0;
}

.init-item {
  display: grid;
  grid-template-columns: 0.9rem 1.1rem 1fr auto;
  gap: 0.25rem;
  align-items: center;
  padding: 0.2rem 0.25rem;
  font-size: 0.78rem;
  font-family: var(--mono);
  border-radius: 3px;
}

.init-item.active {
  background: rgba(90, 140, 200, 0.28);
  outline: 1px solid rgba(120, 170, 230, 0.55);
}

.init-item.next {
  background: rgba(200, 180, 80, 0.12);
}

.init-item.acted {
  opacity: 0.55;
}

.init-item.acted .init-mark {
  color: #8bc48b;
}

.init-item.just-acted:not(.active) {
  outline: 1px dashed rgba(200, 160, 120, 0.45);
}

.init-round-item {
  list-style: none;
  margin: 0 0 0.35rem;
  padding: 0.15rem 0.25rem;
  font-size: 0.72rem;
  font-family: var(--mono);
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.enemy-action-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.78rem;
  font-family: var(--mono);
}

.enemy-action-list li {
  display: grid;
  grid-template-columns: 1.4rem 1fr;
  gap: 0.35rem;
  padding: 0.35rem 0.25rem;
  border-bottom: 1px solid var(--border);
}

.enemy-action-slot {
  color: var(--accent);
  font-weight: 700;
  text-align: right;
}

.enemy-action-text {
  line-height: 1.35;
  word-break: break-word;
}

.enemy-action-empty {
  margin: 0.25rem 0;
}

.init-item.downed {
  opacity: 0.45;
}

.init-mark {
  color: var(--accent);
  font-weight: 700;
}

.init-char.party,
.roster-card.party .roster-char {
  color: #9ec0ef;
}

.init-char.enemy,
.roster-card.enemy .roster-char {
  color: #efb0a8;
}

.roster-card {
  margin-bottom: 0.45rem;
  padding: 0.4rem 0.45rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  font-size: 0.75rem;
}

.roster-card.roster-active {
  border-color: rgba(120, 170, 230, 0.65);
  box-shadow: inset 0 0 0 1px rgba(120, 170, 230, 0.25);
}

.roster-card.roster-downed {
  opacity: 0.5;
}

.roster-head {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--mono);
}

.roster-id {
  font-weight: 600;
  flex: 1;
}

.roster-ac {
  color: var(--muted);
  font-size: 0.7rem;
}

.roster-name {
  margin: 0.15rem 0 0.25rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hp-bar {
  height: 4px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.hp-fill {
  height: 100%;
  background: #5a9e6e;
}

.roster-card.enemy .hp-fill {
  background: #b85a4a;
}

.roster-hp {
  margin-top: 0.2rem;
  font-family: var(--mono);
  font-size: 0.7rem;
}

.roster-cond {
  margin-top: 0.15rem;
  color: #d4c48a;
  font-size: 0.68rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.action-panel-hint {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
}

.action-panel-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.action-choice {
  display: grid;
  grid-template-columns: 1.4rem 1fr;
  grid-template-rows: auto auto;
  column-gap: 0.4rem;
  row-gap: 0.1rem;
  text-align: left;
  padding: 0.4rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel-2);
  color: inherit;
  cursor: pointer;
  font: inherit;
}

.action-choice:hover {
  border-color: var(--accent);
  background: rgba(90, 140, 200, 0.12);
}

.action-key {
  grid-row: 1 / span 2;
  align-self: center;
  font-family: var(--mono);
  font-weight: 700;
  color: var(--accent);
}

.action-label {
  font-size: 0.78rem;
  line-height: 1.25;
}

.action-tactic {
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.battle-map-wrap {
  flex: 1 1 auto;
  min-width: 0;
  overflow: auto;
  padding: 0.65rem 1rem 0.85rem;
  background: var(--panel-2);
}

@media (max-width: 1100px) {
  .theater-body {
    flex-wrap: wrap;
    max-height: none;
  }
  .init-roster,
  .action-panel {
    flex: 1 1 200px;
    width: auto;
    max-width: none;
    border: none;
    border-bottom: 1px solid var(--border);
  }
  .battle-map-wrap {
    flex: 1 1 100%;
    order: -1;
  }
}

.battle-map-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}

.battle-map-header h2 {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}

.battle-map-body {
  display: flex;
  align-items: flex-start;
  gap: 1rem 1.25rem;
  min-width: 0;
}

@media (max-width: 640px) {
  .battle-map-body {
    flex-direction: column;
  }

  .battle-map-legend {
    flex: none;
    max-height: none;
    flex-direction: row;
    flex-wrap: wrap;
  }
}

.battle-map-legend {
  display: flex;
  flex-direction: column;
  flex: 0 1 14rem;
  gap: 0.35rem;
  list-style: none;
  margin: 0;
  padding: 0.15rem 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  max-height: min(70vh, 28rem);
  overflow: auto;
}

.battle-map-legend li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}

.lg-swatch {
  display: inline-block;
  width: 0.85rem;
  height: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 2px;
  vertical-align: middle;
}

.lg-swatch.cell-barricade {
  background: #3a3428;
  box-shadow: inset 0 0 0 1px rgba(180, 140, 70, 0.55);
}

.lg-swatch.cell-wall-h {
  background: #12151a;
  background-image: linear-gradient(
    transparent 40%,
    #4a5568 40%,
    #4a5568 60%,
    transparent 60%
  );
}

.lg-swatch.cell-wall-v {
  background: #12151a;
  background-image: linear-gradient(
    90deg,
    transparent 40%,
    #4a5568 40%,
    #4a5568 60%,
    transparent 60%
  );
}

.lg-swatch.cell-cover {
  background: #334038;
}

.lg-swatch.cell-blocking {
  background: #12151a;
}

.lg-swatch.token {
  border-radius: 50%;
  font-size: 0;
}

.lg-swatch.token.party {
  background: #3d5a80;
}

.lg-swatch.token.enemy {
  background: #8a3a3a;
}

.lg-token-char {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.2rem;
  border-radius: 50%;
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
}

.lg-token-char.party {
  background: #3d5a80;
  color: #e8f0ff;
}

.lg-token-char.enemy {
  background: #8a3a3a;
  color: #ffe8e8;
}

.deploy-hint,
.setup-map-hint {
  margin: 0 0 0.5rem;
  color: var(--accent);
  font-size: 0.8rem;
}

.setup-map-block {
  width: 100%;
  min-width: 0;
}

.setup-map.editable .battle-token,
.battle-map.editable .battle-token {
  cursor: grab;
  -webkit-user-drag: element;
}

.setup-map.editable .battle-token:active,
.battle-map.editable .battle-token:active {
  cursor: grabbing;
}

/* Let dragover hit cells under other tokens — never the active drag source
   (pointer-events:none on the dragged node aborts HTML5 drag in Chromium). */
.battle-map.dragging-token .battle-token:not(.dragging),
.setup-map.dragging-token .battle-token:not(.dragging) {
  pointer-events: none;
}

.battle-map.editable .battle-cell.cell-floor,
.battle-map.editable .battle-cell.cell-difficult,
.battle-map.editable .battle-cell.cell-hazardous,
.battle-map.editable .battle-cell.cell-cover,
.battle-map.editable .battle-cell.cell-barricade,
.setup-map.editable .battle-cell.cell-floor,
.setup-map.editable .battle-cell.cell-difficult,
.setup-map.editable .battle-cell.cell-hazardous,
.setup-map.editable .battle-cell.cell-cover,
.setup-map.editable .battle-cell.cell-barricade {
  cursor: cell;
}

.map-toolbox {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin: 0.35rem 0 0.5rem;
}

.map-toolbox.disabled {
  opacity: 0.55;
}

.map-toolbox-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted, #8a93a3);
  margin-right: 0.15rem;
}

.brush-btn {
  font: inherit;
  font-size: 0.8rem;
  padding: 0.28rem 0.65rem;
  border-radius: 4px;
  border: 1px solid var(--border, #3a4454);
  background: #1c222c;
  color: var(--text, #e6eaf0);
  cursor: pointer;
}

.brush-btn:hover:not(:disabled) {
  border-color: var(--accent, #6ea8fe);
}

.brush-btn.active {
  background: #2a3a52;
  border-color: var(--accent, #6ea8fe);
  color: #e8f0ff;
}

.brush-btn:disabled {
  cursor: not-allowed;
}

.setup-map.paint-mode {
  cursor: crosshair;
}

.setup-map.paint-mode .battle-cell {
  cursor: crosshair;
}

.battle-cell.drop-target {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.battle-token.dragging {
  opacity: 0.55;
}

.battle-map {
  --cell: clamp(1.35rem, 3.2vw, 2.1rem);
  display: grid;
  flex: 0 1 auto;
  width: max-content;
  max-width: 100%;
  margin: 0;
  gap: 1px;
  padding: 2px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: auto;
}

.battle-cell {
  position: relative;
  width: var(--cell);
  height: var(--cell);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: calc(var(--cell) * 0.48);
  font-weight: 600;
  line-height: 1;
  user-select: none;
}

.battle-cell.cell-floor {
  background: #2a3340;
}

.battle-cell.cell-difficult {
  background: #3a3428;
  background-image: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 3px,
    rgba(0, 0, 0, 0.18) 3px,
    rgba(0, 0, 0, 0.18) 6px
  );
}

.battle-cell.cell-grease {
  background-color: #2e3a28;
  background-image: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 4px,
    rgba(140, 200, 80, 0.32) 4px,
    rgba(140, 200, 80, 0.32) 8px
  );
  background-size: 100% 12px;
  box-shadow: inset 0 0 0 1px rgba(160, 210, 90, 0.55);
  animation: grease-shift 4.5s linear infinite;
}

.battle-cell .cell-marker.grease {
  color: #b8e070;
  font-weight: 700;
  font-size: calc(var(--cell) * 0.55);
}

.battle-cell.cell-fog {
  background-color: #2a3038;
  background-image: radial-gradient(
    ellipse at 40% 40%,
    rgba(200, 220, 240, 0.38) 0%,
    transparent 55%
  ),
    radial-gradient(
      ellipse at 70% 60%,
      rgba(170, 195, 220, 0.3) 0%,
      transparent 50%
    );
  box-shadow: inset 0 0 0 1px rgba(190, 210, 230, 0.5);
  animation: fog-pulse 3.2s ease-in-out infinite;
}

.battle-cell .cell-marker.fog {
  color: #c8d8e8;
  font-weight: 700;
  font-size: calc(var(--cell) * 0.55);
  opacity: 0.85;
}

.battle-cell.cell-hazardous {
  background: #3a2828;
  background-image: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 3px,
    rgba(200, 70, 45, 0.36) 3px,
    rgba(200, 70, 45, 0.36) 6px
  );
  box-shadow: inset 0 0 0 1px rgba(220, 90, 55, 0.55);
}

.battle-cell .cell-marker.hazardous {
  color: #e08060;
  font-weight: 700;
  font-size: calc(var(--cell) * 0.55);
}

@keyframes fog-pulse {
  0%,
  100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.12);
  }
}

@keyframes grease-shift {
  0% {
    background-position: 0 0;
  }
  100% {
    background-position: 0 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .battle-cell.cell-fog,
  .battle-cell.cell-grease {
    animation: none;
  }
}

/* Corner chips when a token occupies effect terrain */
.battle-cell .cell-corner {
  position: absolute;
  top: 1px;
  right: 2px;
  z-index: 2;
  font-size: calc(var(--cell) * 0.32);
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
  text-shadow: 0 0 2px rgba(0, 0, 0, 0.85);
}

.battle-cell .cell-corner.grease {
  color: #b8e070;
}

.battle-cell .cell-corner.fog {
  color: #c8d8e8;
}

.battle-cell .cell-corner.hazardous {
  color: #e08060;
}

.battle-cell .cell-corner.barricade {
  color: #e0c070;
}

.battle-cell.cell-cover {
  background: #334038;
  box-shadow: inset 0 0 0 2px rgba(120, 160, 120, 0.45);
}

.battle-cell.cell-barricade {
  background: #3a3428;
  box-shadow: inset 0 0 0 2px rgba(180, 140, 70, 0.55);
}

.battle-cell .cell-marker.barricade {
  color: #e0c070;
  font-weight: 700;
  font-size: calc(var(--cell) * 0.55);
  pointer-events: none;
  z-index: 0;
}

.battle-cell .cell-marker.wall-h,
.battle-cell .cell-marker.wall-v {
  color: #8a96a8;
  font-weight: 700;
  font-size: calc(var(--cell) * 0.55);
  pointer-events: none;
  z-index: 0;
  opacity: 0.85;
}

.battle-cell.cell-blocking {
  background: #12151a;
  color: #3a4454;
}

.battle-cell.cell-wall-h,
.battle-cell.cell-wall-v {
  background: #12151a;
  color: #5a6578;
}

.battle-cell.cell-wall-h::after {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  top: 50%;
  height: 22%;
  transform: translateY(-50%);
  background: #4a5568;
  border-radius: 1px;
}

.battle-cell.cell-wall-v::after {
  content: "";
  position: absolute;
  top: 8%;
  bottom: 8%;
  left: 50%;
  width: 22%;
  transform: translateX(-50%);
  background: #4a5568;
  border-radius: 1px;
}

.battle-token {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 82%;
  height: 82%;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.35);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  z-index: 1;
}

/* Short status strip above token; visible on token or cell hover */
.battle-token .token-status {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 2px);
  transform: translateX(-50%);
  z-index: 3;
  max-width: calc(var(--cell) * 2.4);
  padding: 1px 4px;
  border-radius: 3px;
  background: rgba(12, 16, 22, 0.92);
  color: #f0e6c8;
  font-family: var(--mono);
  font-size: max(9px, calc(var(--cell) * 0.28));
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease;
}

.battle-token:hover .token-status,
.battle-cell:hover .battle-token .token-status {
  opacity: 1;
  visibility: visible;
}

.battle-token.party {
  background: #3d5a80;
  color: #e8f0ff;
}

.battle-token.enemy {
  background: #8a3a3a;
  color: #ffe8e8;
}

.battle-token.downed {
  opacity: 0.45;
  filter: grayscale(0.7);
}

.battle-token.dead {
  opacity: 0.35;
  filter: grayscale(1);
  outline: 1px solid #6a3030;
}

.battle-token.stack {
  font-size: 0.7em;
  border-radius: 4px;
  width: 90%;
  height: 90%;
}

.battle-token.token-active {
  outline: 2px solid #e8d080;
  outline-offset: 1px;
  box-shadow: 0 0 0 2px rgba(232, 208, 128, 0.35);
  z-index: 2;
}

/* Theater highlights (active actor) */
.battle-cell.cell-reach {
  box-shadow: inset 0 0 0 2px rgba(90, 180, 120, 0.55);
}

.battle-cell.cell-melee {
  box-shadow: inset 0 0 0 2px rgba(220, 100, 90, 0.65);
}

/** Your threatened squares (polearm / Reactive Strike control). */
.battle-cell.cell-control {
  background-image: radial-gradient(
    circle at center,
    rgba(200, 80, 80, 0.12) 0%,
    transparent 72%
  );
}

/** Enemy Reactive Strike zones — Stride out of these may provoke. */
.battle-cell.cell-aoo {
  box-shadow: inset 0 0 0 1px rgba(240, 120, 60, 0.45);
}

.battle-cell.cell-range {
  background-image: radial-gradient(
    circle at center,
    rgba(220, 160, 70, 0.18) 0%,
    transparent 70%
  );
}

.battle-cell.cell-no-los {
  opacity: 0.55;
  filter: saturate(0.55);
}

.battle-cell.cell-cover-cue {
  box-shadow: inset 0 0 0 2px rgba(180, 150, 70, 0.5);
}

.battle-cell.cell-lesser-cover {
  box-shadow: inset 0 0 0 2px rgba(140, 170, 200, 0.45);
}

.battle-cell.cell-choice-hl {
  outline: 2px solid #f0c040;
  outline-offset: -2px;
  z-index: 2;
}

.round-card .battle-map {
  --cell: clamp(1.1rem, 2.4vw, 1.65rem);
  margin: 0;
}

.round-stage {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 1.25rem 1.5rem 1.5rem;
  outline: none;
}

.round-empty {
  text-align: center;
  padding: 3rem 1rem;
}

.round-card {
  width: min(1100px, 100%);
  margin: 0 auto 1.5rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem 1.25rem;
}

.round-card.current {
  border-color: var(--accent-dim);
  box-shadow: inset 0 0 0 1px var(--accent-dim);
}

.round-card.past {
  opacity: 0.82;
}

.round-card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.35rem;
  color: var(--accent);
  text-align: center;
  letter-spacing: 0.04em;
}

.round-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.round-grid .full {
  grid-column: 1 / -1;
}

.round-card .panel {
  margin: 0;
}

.round-card .mono {
  font-size: 0.82rem;
  line-height: 1.4;
  white-space: pre;
  overflow-x: auto;
}

.advance-banner,
.advance-hint {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.75rem;
  margin: 0 0 0.85rem;
  padding: 0.55rem 0.85rem;
  background: var(--panel-2);
  border: 1px solid var(--accent-dim);
  border-radius: 6px;
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.03em;
  text-align: center;
}

.advance-banner kbd {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.15rem 0.45rem;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.85rem;
}

@media (max-width: 900px) {
  .round-grid {
    grid-template-columns: 1fr;
  }
}

.main-views > .view.loop.active,
.view.loop.active {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  height: 100%;
  min-height: 0;
}

.loop-briefing {
  flex: 0 0 auto;
  margin: 0;
}

.loop-briefing[hidden] {
  display: none !important;
}

.loop-briefing-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.loop-briefing-stats .stat .v {
  font-size: 1.45rem;
  font-weight: 700;
  line-height: 1.15;
}

.loop-briefing-stats .stat .v.ok {
  color: var(--ok, #4ade80);
}

.loop-briefing-stats .stat .v.warn {
  color: var(--warn, #f59e0b);
}

.loop-briefing-stats .stat .l {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 0.25rem;
}

.loop-briefing-callout {
  border-left: 3px solid var(--ok, #4ade80);
  padding: 0.35rem 0 0.35rem 0.85rem;
  margin: 0 0 0.85rem;
}

.loop-briefing-callout.warn {
  border-left-color: var(--warn, #f59e0b);
}

.loop-briefing-headline {
  margin: 0 0 0.25rem;
  color: var(--ok, #4ade80);
  font-weight: 700;
  font-size: 0.95rem;
}

.loop-briefing-callout.warn .loop-briefing-headline {
  color: var(--warn, #f59e0b);
}

.loop-briefing-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.loop-briefing h3 {
  margin: 0 0 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.loop-briefing-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1.25rem;
}

.loop-briefing-grid ul {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.88rem;
  line-height: 1.4;
  color: var(--text);
}

.loop-briefing-grid li + li {
  margin-top: 0.3rem;
}

@media (max-width: 900px) {
  .loop-briefing-grid,
  .loop-briefing-stats {
    grid-template-columns: 1fr;
  }
}

.loop-params {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: flex-end;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.loop-params > label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.loop-params input[type="number"] {
  width: 5.5rem;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.45rem;
}

.loop-checks {
  border: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.75rem;
  align-items: center;
}

.loop-checks legend {
  font-size: 0.8rem;
  color: var(--muted);
  padding: 0;
  margin-bottom: 0.25rem;
  width: 100%;
}

.loop-checks .check {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--text);
}

#loopFightCount {
  flex: 1 1 100%;
  margin: 0;
  color: var(--accent);
}

.loop-frame {
  flex: 1;
  min-height: 28rem;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0d1015;
}

.combat-header,
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-shrink: 0;
}

h1,
h2 {
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.01em;
}

h1 {
  font-size: 1.25rem;
}

h2 {
  font-size: 0.95rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.meta {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.pills {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  align-items: center;
}

.header-actions .accent-btn {
  margin: 0;
}

.pill {
  border: 1px solid var(--accent-dim);
  color: var(--accent);
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.pill.muted {
  border-color: var(--border);
  color: var(--muted);
}

.pill.ended {
  border-color: var(--danger);
  color: var(--danger);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 0.9rem;
}

.panel.grow {
  flex: 1;
  min-height: 12rem;
  display: flex;
  flex-direction: column;
}

.mono {
  margin: 0.5rem 0 0;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.35;
  white-space: pre-wrap;
  color: #d5dde8;
}

.log {
  overflow: auto;
  flex: 1;
  max-height: none;
}

.messages {
  flex: 1 1 auto;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.75rem 0;
  min-height: 8rem;
}

.bubble {
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
  max-width: 95%;
  white-space: pre-wrap;
  font-size: 0.92rem;
  line-height: 1.4;
  border: 1px solid var(--border);
}

.bubble.user {
  align-self: flex-end;
  background: var(--user);
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--bot);
}

.bubble .who {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  padding: 0.5rem 0 0.25rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--panel);
}

textarea {
  resize: vertical;
  min-height: 4.5rem;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  font-family: var(--font);
  font-size: 0.92rem;
}

textarea:focus,
button:focus {
  outline: 1px solid var(--accent-dim);
}

button {
  background: var(--accent);
  color: #1a1408;
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1rem;
  font-weight: 600;
  cursor: pointer;
  align-self: end;
}

button:disabled {
  opacity: 0.55;
  cursor: wait;
}

button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  align-self: flex-start;
  font-weight: 500;
}

.empty-hint {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 1rem 0.25rem;
}

@media (max-width: 900px) {
  .setup-grid {
    grid-template-columns: 1fr;
  }
}
