/* ═══════════════════════════════════════════════════════════
   CoC 7e Chase Tracker — Stylesheet
   ═══════════════════════════════════════════════════════════ */

/* ── CSS VARIABLES ────────────────────────────────────────── */
:root {
  --bg: #1a1510;
  --panel-bg: #2a2218;
  --text: #d4c5a0;
  --text-secondary: #8a7b5a;
  --text-flavor: #c4b48a;
  --accent: #b8945f;
  --hazard: #7a4028;
  --barrier: #3e4448;
  --exit: #3d4a30;
  --location: #4a3d30;
  --chaser-token: #6b2c2c;
  --investigator-token: #4a4d5a;
  --card-border: #3d3425;
  --card-border-hover: #6b5b3a;
  --panel-border: #3d3425;
  --font-body: 'Crimson Text', 'Georgia', serif;
  --font-heading: 'Cinzel', 'Georgia', serif;
  --font-flavor: 'IM Fell English', 'Georgia', serif;
  --font-mono: 'Roboto Mono', 'Courier New', monospace;
}

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

body {
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* body::before removed — atmospheric lighting lives on #diagram-container only */

/* ── HEADER ───────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: linear-gradient(180deg, #2a2218 0%, #1a1510 100%);
  border-bottom: 2px solid #5a4a30;
  z-index: 100;
  flex-shrink: 0;
  position: relative;
}

.header::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}

.header-title-area {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

#chase-selector {
  font-family: var(--font-heading);
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 1px;
  text-transform: uppercase;
  background: #2a2218;
  border: 1px solid #5a4a30;
  border-radius: 2px;
  padding: 4px 24px 4px 8px;
  cursor: pointer;
  width: auto;
  max-width: 400px;
  transition: border-color 0.2s;
}
#chase-selector:hover { border-color: var(--accent); }
#chase-selector:focus { border-color: var(--accent); outline: none; }

.chase-mgmt-btn {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
  border-radius: 2px;
  font-size: 16px;
  line-height: 1;
  padding: 2px 6px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}
.chase-mgmt-btn:hover { color: var(--accent); border-color: #5a4a30; }
.chase-mgmt-del:hover { color: #a05030; border-color: #6b3020; }

.header-controls { display: flex; gap: 8px; flex-shrink: 0; align-items: center; }

#kofi-btn {
  display: inline-flex;
  align-items: center;
  padding: 4px;
  opacity: 0.7;
  transition: opacity 0.2s;
}
#kofi-btn:hover { opacity: 1; }
.kofi-icon {
  height: 20px;
  width: auto;
  display: block;
  animation: kofi-wiggle 3s infinite;
}
@keyframes kofi-wiggle {
  0%, 60% { transform: rotate(0) scale(1); }
  75% { transform: rotate(0) scale(1.12); }
  80% { transform: rotate(0) scale(1.1); }
  84% { transform: rotate(-10deg) scale(1.1); }
  88% { transform: rotate(10deg) scale(1.1); }
  92% { transform: rotate(-10deg) scale(1.1); }
  96% { transform: rotate(10deg) scale(1.1); }
  100% { transform: rotate(0) scale(1); }
}

.header-controls button, .ctrl-btn {
  background: linear-gradient(180deg, #3d3425 0%, #2a2218 100%);
  color: var(--accent);
  border: 1px solid #5a4a30;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  border-radius: 2px;
  font-family: var(--font-body);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  transition: all 0.2s;
  box-shadow: inset 0 1px 0 rgba(184,148,95,0.15), 0 1px 2px rgba(0,0,0,0.3);
}

.header-controls button:hover, .ctrl-btn:hover {
  background: linear-gradient(180deg, #4d4235 0%, #3a3228 100%);
  color: #d4b87a;
  border-color: var(--accent);
  box-shadow: inset 0 1px 0 rgba(184,148,95,0.25), 0 1px 4px rgba(0,0,0,0.4);
}

.ctrl-btn.active-mode {
  border-color: #7cb87c;
  color: #7cb87c;
  box-shadow: 0 0 6px rgba(124,184,124,0.2);
}

#import-input { display: none; }

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

/* ── RESIZE HANDLES ──────────────────────────────────────── */
.resize-handle {
  width: 5px;
  cursor: col-resize;
  background: transparent;
  flex-shrink: 0;
  position: relative;
  z-index: 20;
  transition: background 0.15s;
}
.resize-handle:hover,
.resize-handle.dragging {
  background: rgba(184,148,95,0.25);
}
.resize-handle-left { margin-left: -3px; margin-right: -2px; }
.resize-handle-right { margin-left: -2px; margin-right: -3px; }

/* ── LEFT PANEL: FLAVOR TEXT ──────────────────────────────── */
#flavor-panel {
  width: 280px;
  min-width: 160px;
  max-width: 500px;
  background: linear-gradient(180deg, #2a2218 0%, #221c14 100%);
  border-right: 1px solid #5a4a30;
  overflow-y: auto;
  padding: 12px;
  flex-shrink: 0;
}

#flavor-panel h2 {
  font-family: var(--font-heading);
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--card-border);
}

.flavor-section {
  font-family: var(--font-heading);
  font-size: 13px;
  letter-spacing: 2px;
  text-transform: uppercase;
  text-align: center;
  color: var(--accent);
  margin: 14px 0 8px;
  padding: 4px 0;
  opacity: 0.9;
}

.flavor-section::before,
.flavor-section::after {
  content: '\25C6';
  font-size: 10px;
  color: var(--accent);
  vertical-align: middle;
  margin: 0 6px;
  opacity: 0.6;
}

.flavor-card {
  background: linear-gradient(180deg, rgba(42,34,24,0.8) 0%, rgba(26,21,16,0.8) 100%);
  border: 1px solid var(--card-border);
  border-radius: 2px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: all 0.2s;
  overflow: hidden;
}

.flavor-card:hover { border-color: var(--card-border-hover); }

.flavor-card .node-label {
  display: block;
  padding: 8px 12px;
  font-family: var(--font-heading);
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.5px;
}

.flavor-card .flavor-text {
  display: none;
  padding: 0 12px 10px;
  font-family: var(--font-flavor);
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-flavor);
  border-top: 1px solid var(--card-border);
  margin-top: 0;
  padding-top: 8px;
}

.flavor-card.active .flavor-text { display: block; }

/* ── TOKEN TRAY ───────────────────────────────────────────── */
#token-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 12px;
  background: linear-gradient(180deg, #221c14 0%, #1a1510 100%);
  border-bottom: 1px solid #3d3425;
  align-items: center;
  min-height: 48px;
}

#token-tray .tray-label {
  font-family: var(--font-heading);
  font-size: 13px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-right: 4px;
}

/* ── CONNECTION TOOLBAR ───────────────────────────────────── */
#connection-toolbar {
  display: none;
  gap: 8px;
  align-items: center;
  padding: 6px 12px;
  background: linear-gradient(180deg, #2a2218 0%, #241e16 100%);
  border-bottom: 1px solid #5a4a30;
  flex-shrink: 0;
}

#connection-toolbar.visible { display: flex; }

#conn-status {
  font-size: 13px;
  color: var(--text-secondary);
  flex: 1;
}

/* ── TOKENS ───────────────────────────────────────────────── */
.token {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  color: #fff;
  font-family: var(--font-heading);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  cursor: grab;
  user-select: none;
  border: 2px solid rgba(255,255,255,0.2);
  box-shadow: 0 2px 4px rgba(0,0,0,0.4);
  transition: box-shadow 0.2s;
  z-index: 10;
  line-height: 1.1;
  padding: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.token:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.6); }

/* Tokens placed on the diagram map — inside #diagram-container */
.token.placed-on-map {
  position: absolute;
  z-index: 10;
}

/* ── DIAGRAM ──────────────────────────────────────────────── */
.center-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  position: relative; /* anchor for zoom indicator */
}

#diagram-container {
  flex: 1;
  overflow: auto;
  position: relative;
  /* 1920s desk surface: lamp glow + soft wood grain + vignette */
  background:
    /* Warm desk-lamp spotlight */
    radial-gradient(ellipse 80% 70% at 50% 40%,
      rgba(184,148,95,0.11) 0%,
      rgba(170,135,80,0.08) 20%,
      rgba(155,120,65,0.05) 40%,
      rgba(140,105,50,0.025) 60%,
      transparent 85%
    ),
    /* Subtle warm bounce near bottom edge */
    radial-gradient(ellipse 100% 60% at 50% 95%,
      rgba(139,100,50,0.04) 0%,
      rgba(139,100,50,0.02) 30%,
      transparent 70%
    ),
    /* Wood grain grid — three layers per axis: fine + medium + wide for natural variation */
    repeating-linear-gradient(
      0deg,
      transparent 0px, transparent 8px,
      rgba(85,58,22,0.022) 10px, rgba(85,58,22,0.010) 12px,
      transparent 13px
    ),
    repeating-linear-gradient(
      0deg,
      transparent 0px, transparent 22px,
      rgba(70,45,15,0.018) 24px, rgba(70,45,15,0.008) 27px,
      transparent 29px
    ),
    repeating-linear-gradient(
      0deg,
      transparent 0px, transparent 55px,
      rgba(60,38,12,0.012) 58px, rgba(60,38,12,0.006) 62px,
      transparent 65px
    ),
    repeating-linear-gradient(
      90deg,
      transparent 0px, transparent 8px,
      rgba(85,58,22,0.022) 10px, rgba(85,58,22,0.010) 12px,
      transparent 13px
    ),
    repeating-linear-gradient(
      90deg,
      transparent 0px, transparent 22px,
      rgba(70,45,15,0.018) 24px, rgba(70,45,15,0.008) 27px,
      transparent 29px
    ),
    repeating-linear-gradient(
      90deg,
      transparent 0px, transparent 55px,
      rgba(60,38,12,0.012) 58px, rgba(60,38,12,0.006) 62px,
      transparent 65px
    ),
    var(--bg);
  box-shadow: inset 0 0 140px 50px rgba(10,8,4,0.4);
}

#diagram-inner {
  position: relative; /* anchor for absolutely-positioned map tokens */
  transform-origin: top left; /* must be top-left so zoom + token coords align */
  min-width: 100%;
  min-height: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.mermaid svg { min-width: 800px; min-height: 600px; background: transparent !important; }
.mermaid svg .node { cursor: default; }
body.nodes-tab-active .mermaid svg .node { cursor: pointer; }
.mermaid svg .node:hover rect,
.mermaid svg .node:hover polygon { filter: brightness(1.3); }
body.nodes-tab-active .mermaid svg .edgePath { cursor: pointer; }

/* Subgraph labels and boxes */
.mermaid svg .cluster rect { fill: rgba(42,34,24,0.4) !important; stroke: #7a6a4a !important; }
.mermaid svg .cluster span { color: #b8945f !important; font-family: var(--font-heading) !important; }

/* Prevent Mermaid from clipping node and subgraph label text */
.mermaid svg foreignObject { overflow: visible !important; }
.mermaid svg .nodeLabel { overflow: visible !important; }
.mermaid svg .label { overflow: visible !important; }

/* Edge labels */
.mermaid svg .edgeLabel { background: transparent !important; }

/* Arrow markers */
.mermaid svg .marker { fill: #7a6a4a !important; }

.zoom-indicator {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(42,34,24,0.85);
  color: var(--text-secondary);
  font-size: 13px;
  padding: 3px 8px;
  border-radius: 2px;
  border: 1px solid var(--card-border);
  pointer-events: none;
  z-index: 5;
}

/* ── RIGHT PANEL ──────────────────────────────────────────── */
.right-panel {
  width: 360px;
  min-width: 260px;
  max-width: 600px;
  background: linear-gradient(180deg, #2a2218 0%, #221c14 100%);
  border-left: 1px solid #5a4a30;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.panel-tabs {
  display: flex;
  border-bottom: 1px solid #5a4a30;
  flex-shrink: 0;
}

.panel-tab {
  flex: 1;
  padding: 8px;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  font-family: var(--font-heading);
  font-size: 13px;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.2s;
  border-bottom: 2px solid transparent;
}

.panel-tab:hover { color: var(--accent); }
.panel-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: rgba(184,148,95,0.05);
}

.tab-content { display: none; flex: 1; overflow-y: auto; padding: 10px; }
.tab-content.active { display: block; }

/* ── CHARACTER EDITOR ─────────────────────────────────────── */
.char-item {
  background: rgba(26,21,16,0.5);
  border: 1px solid var(--card-border);
  border-radius: 2px;
  margin-bottom: 6px;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.char-item.expanded {
  border-color: var(--accent);
  box-shadow: 0 0 6px rgba(184,148,95,0.15);
}

.char-item-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  transition: background 0.2s;
}

.char-item-header:hover { background: rgba(184,148,95,0.05); }

.char-item-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.char-item-name {
  flex: 1;
  font-family: var(--font-heading);
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.5px;
}

.char-item-stats {
  font-size: 13px;
  color: var(--text-secondary);
}

.char-item-body {
  display: none;
  padding: 0 12px 12px;
  border-top: 1px solid var(--card-border);
}

.char-item.expanded .char-item-body { display: block; }

.char-field { margin-top: 8px; }

.char-field label {
  display: block;
  font-family: var(--font-heading);
  font-size: 13px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--accent);
  opacity: 0.8;
  margin-bottom: 3px;
}

.char-field input, .char-field select {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--card-border);
  padding: 6px 10px;
  font-family: var(--font-body);
  font-size: 14px;
  border-radius: 2px;
}

.char-field input:focus, .char-field select:focus {
  outline: none;
  border-color: var(--accent);
}

.char-field-row { display: flex; gap: 8px; }
.char-field-row .char-field { flex: 1; }

.char-delete-btn {
  margin-top: 8px;
  width: 100%;
  background: rgba(107,44,44,0.3);
  color: #c47a7a;
  border: 1px solid #6b2c2c;
  padding: 6px;
  font-family: var(--font-body);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.2s;
}

.char-delete-btn:hover { background: rgba(107,44,44,0.6); }

.char-add-area {
  padding: 8px 0;
  display: flex;
  gap: 8px;
}

/* ── CON ROLL RESULTS ─────────────────────────────────────── */
.con-roll-area {
  margin-top: 10px;
  border-top: 1px solid var(--card-border);
  padding-top: 10px;
  font-size: 13px;
}

.con-result {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid rgba(61,52,37,0.3);
  flex-wrap: wrap;
}

.con-result-name {
  font-family: var(--font-heading);
  font-size: 13px;
  color: var(--accent);
  min-width: 50px;
}

.con-result-roll {
  font-size: 13px;
  color: var(--text-secondary);
}

.con-result-extreme { color: #7cb87c; font-weight: bold; font-size: 13px; }
.con-result-pass { color: var(--accent); font-size: 13px; }
.con-result-fail { color: #c47a7a; font-weight: bold; font-size: 13px; }

.con-result-mov {
  font-size: 13px;
  color: var(--text);
  margin-left: auto;
}

.reroll-btn {
  background: linear-gradient(180deg, #3d3425 0%, #2a2218 100%);
  color: var(--accent);
  border: 1px solid #5a4a30;
  padding: 3px 10px;
  font-size: 13px;
  cursor: pointer;
  border-radius: 2px;
  font-family: var(--font-body);
}

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

.manual-roll-input {
  width: 72px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--card-border);
  padding: 4px 6px;
  font-family: var(--font-body);
  font-size: 13px;
  border-radius: 2px;
  text-align: center;
}

.manual-roll-input:focus { outline: none; border-color: var(--accent); }

/* ── NODE EDITOR ──────────────────────────────────────────── */
.node-item {
  background: rgba(26,21,16,0.5);
  border: 1px solid var(--card-border);
  border-radius: 2px;
  margin-bottom: 6px;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.node-item.expanded {
  border-color: var(--accent);
  box-shadow: 0 0 6px rgba(184,148,95,0.15);
}

.node-item.highlighted {
  border-color: #7cb87c;
  box-shadow: 0 0 8px rgba(124,184,124,0.2);
}

.node-item-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  transition: background 0.2s;
  font-size: 13px;
}

.node-item-header:hover { background: rgba(184,148,95,0.05); }

.node-item-type {
  font-size: 13px;
  padding: 2px 8px;
  border-radius: 2px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: bold;
  flex-shrink: 0;
}

.node-item-label {
  flex: 1;
  font-family: var(--font-heading);
  font-size: 13px;
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-item-body {
  display: none;
  padding: 0 12px 12px;
  border-top: 1px solid var(--card-border);
}

.node-item.expanded .node-item-body { display: block; }

.node-field { margin-top: 6px; }

.node-field label {
  display: block;
  font-family: var(--font-heading);
  font-size: 13px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--accent);
  opacity: 0.8;
  margin-bottom: 3px;
}

.node-field input, .node-field select, .node-field textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--card-border);
  padding: 6px 10px;
  font-family: var(--font-body);
  font-size: 14px;
  border-radius: 2px;
}

.node-field textarea {
  font-family: var(--font-flavor);
  font-size: 14px;
  line-height: 1.6;
  min-height: 70px;
  resize: vertical;
}

.node-field input:focus, .node-field select:focus, .node-field textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.node-field-row { display: flex; gap: 8px; }
.node-field-row .node-field { flex: 1; }

.node-delete-btn {
  margin-top: 8px;
  width: 100%;
  background: rgba(107,44,44,0.3);
  color: #c47a7a;
  border: 1px solid #6b2c2c;
  padding: 6px;
  font-family: var(--font-body);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.2s;
}

.node-delete-btn:hover { background: rgba(107,44,44,0.6); }

.node-add-area {
  padding: 8px 0;
  display: flex;
  gap: 8px;
}

/* ── OBSTACLE FIELDS (conditional) ────────────────────────── */
.obstacle-fields {
  display: none;
}

.node-item.show-obstacle .obstacle-fields {
  display: block;
}

/* ── CONNECTIONS SECTION ──────────────────────────────────── */
.conn-section {
  margin-top: 10px;
  border-top: 1px solid var(--card-border);
  padding-top: 10px;
}

.conn-section-title {
  font-family: var(--font-heading);
  font-size: 13px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--accent);
  opacity: 0.8;
  margin-bottom: 6px;
}

.conn-hint {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-style: italic;
}

.conn-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 13px;
  color: var(--text-secondary);
  border-bottom: 1px solid rgba(61,52,37,0.3);
}

.conn-item-label {
  font-size: 13px;
  color: var(--accent);
}

.conn-item-arrow {
  color: var(--text-secondary);
  font-size: 14px;
}

.conn-remove-btn {
  background: none;
  border: 1px solid #6b2c2c;
  color: #c47a7a;
  font-size: 13px;
  padding: 2px 8px;
  cursor: pointer;
  border-radius: 2px;
  margin-left: auto;
}

.conn-remove-btn:hover { background: rgba(107,44,44,0.4); }

/* ── GRID ─────────────────────────────────────────────────── */
#grid-token-holder {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  background: rgba(26,21,16,0.5);
  border: 1px solid var(--card-border);
  border-radius: 2px;
  min-height: 52px;
  margin-bottom: 10px;
  align-items: center;
}

#grid-token-holder .holder-label {
  font-family: var(--font-heading);
  font-size: 13px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-right: 4px;
}

.grid-token {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: #fff;
  font-family: var(--font-heading);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  cursor: grab;
  user-select: none;
  border: 2px solid rgba(255,255,255,0.2);
  box-shadow: 0 2px 4px rgba(0,0,0,0.4);
  z-index: 10;
  line-height: 1.1;
  padding: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
}

#speed-grid {
  display: grid;
  border: 1px solid var(--card-border);
  border-radius: 2px;
  overflow: auto;
  background: rgba(26,21,16,0.3);
  margin-bottom: 10px;
}

.grid-header {
  background: linear-gradient(180deg, #3d3425 0%, #2a2218 100%);
  font-family: var(--font-heading);
  font-size: 11px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--accent);
  text-align: center;
  padding: 4px 2px;
  border-bottom: 1px solid var(--card-border);
  border-right: 1px solid var(--card-border);
  white-space: nowrap;
  line-height: 1.3;
}

.grid-mov-ref {
  font-size: 9px;
  color: var(--text-secondary);
  letter-spacing: 0;
  text-transform: none;
}

.grid-row-label {
  background: linear-gradient(90deg, #3d3425 0%, #2a2218 100%);
  font-family: var(--font-heading);
  font-size: 13px;
  letter-spacing: 1px;
  color: var(--text-secondary);
  text-align: center;
  padding: 6px 4px;
  border-bottom: 1px solid var(--card-border);
  border-right: 1px solid var(--card-border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.grid-cell {
  min-height: 52px;
  min-width: 60px;
  border-bottom: 1px solid var(--card-border);
  border-right: 1px solid var(--card-border);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  transition: background 0.2s;
}

.grid-cell:hover { background: rgba(184,148,95,0.05); }
.grid-cell-drop-target {
  background: rgba(184,148,95,0.15) !important;
  box-shadow: inset 0 0 6px rgba(184,148,95,0.25);
}

.grid-corner {
  background: linear-gradient(135deg, #3d3425 0%, #2a2218 100%);
  font-family: var(--font-heading);
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  padding: 6px 4px;
  border-bottom: 1px solid var(--card-border);
  border-right: 1px solid var(--card-border);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── ROUND COUNTER ────────────────────────────────────────── */
.round-section {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: rgba(26,21,16,0.5);
  border: 1px solid var(--card-border);
  border-radius: 2px;
}

.round-label {
  font-family: var(--font-heading);
  font-size: 13px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.round-controls { display: flex; align-items: center; gap: 6px; }

.round-controls button {
  background: linear-gradient(180deg, #3d3425 0%, #2a2218 100%);
  color: var(--accent);
  border: 1px solid #5a4a30;
  width: 32px;
  height: 32px;
  font-size: 18px;
  cursor: pointer;
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.round-controls button:hover {
  border-color: var(--accent);
  color: #d4b87a;
}

.round-number {
  font-family: var(--font-heading);
  font-size: 32px;
  font-weight: 900;
  color: var(--accent);
  min-width: 40px;
  text-align: center;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

/* ── GRID CON RESULTS ─────────────────────────────────────── */
#grid-con-results {
  margin-top: 10px;
}

/* ── TOAST ────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: -60px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(180deg, #3d3425 0%, #2a2218 100%);
  color: var(--accent);
  padding: 10px 24px;
  border: 1px solid var(--accent);
  border-radius: 3px;
  font-family: var(--font-body);
  font-size: 14px;
  z-index: 10000;
  transition: bottom 0.3s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  white-space: nowrap;
}

.toast.visible { bottom: 24px; }

/* ── WARNINGS ─────────────────────────────────────────────── */
.warnings-panel {
  display: none;
  position: fixed;
  top: 60px;
  right: 16px;
  background: linear-gradient(180deg, #3d3425 0%, #2a2218 100%);
  border: 1px solid #7a4028;
  border-radius: 3px;
  padding: 12px 16px;
  z-index: 9999;
  max-width: 400px;
  font-size: 13px;
  color: var(--text);
  box-shadow: 0 4px 16px rgba(0,0,0,0.6);
}

.warnings-panel.visible { display: block; }
.warnings-panel ul { margin: 6px 0 0 16px; font-size: 13px; color: #c4a060; }
.warnings-panel button {
  margin-top: 8px;
  background: rgba(122,64,40,0.3);
  color: var(--accent);
  border: 1px solid #7a4028;
  padding: 4px 12px;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 13px;
  border-radius: 3px;
}

/* ── QUICK REFERENCE ──────────────────────────────────────── */
.quick-ref-toggle {
  display: block;
  width: 100%;
  background: linear-gradient(180deg, #3d3425 0%, #2a2218 100%);
  color: var(--accent);
  border: 1px solid #5a4a30;
  padding: 8px;
  font-family: var(--font-heading);
  font-size: 13px;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 2px;
  margin-top: 14px;
  transition: all 0.2s;
}

.quick-ref-toggle:hover { border-color: var(--accent); }

.quick-ref-content {
  display: none;
  padding: 10px;
  border: 1px solid var(--card-border);
  border-top: none;
  border-radius: 0 0 2px 2px;
  background: rgba(26,21,16,0.5);
}

.quick-ref-content.visible { display: block; }

.qr-title {
  font-family: var(--font-heading);
  font-size: 13px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--accent);
  margin-top: 10px;
  margin-bottom: 4px;
  padding-bottom: 2px;
  border-bottom: 1px solid var(--card-border);
}

.qr-title:first-child { margin-top: 0; }

.qr-body {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
  margin: 4px 0;
}

.qr-table {
  width: 100%;
  font-size: 13px;
  border-collapse: collapse;
  margin: 4px 0;
}

.qr-table th, .qr-table td {
  padding: 3px 8px;
  border: 1px solid var(--card-border);
  text-align: left;
}

.qr-table th {
  background: rgba(184,148,95,0.1);
  color: var(--accent);
  font-weight: normal;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── NODE POPOVER ─────────────────────────────────────────── */
.node-popover {
  display: none;
  position: fixed;
  z-index: 10000;
  background: linear-gradient(180deg, #3d3425 0%, #2a2218 100%);
  border: 2px solid var(--accent);
  border-radius: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.7);
  min-width: 220px;
  font-family: var(--font-body);
  font-size: 14px;
}

.popover-arrow {
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 8px solid var(--accent);
}

.node-popover.above .popover-arrow {
  top: auto;
  bottom: -8px;
  border-bottom: none;
  border-top: 8px solid var(--accent);
}

.popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--card-border);
}

.popover-node-label {
  font-family: var(--font-heading);
  font-size: 14px;
  color: var(--accent);
  font-weight: 700;
}

.popover-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.popover-close:hover { color: var(--accent); }

.popover-actions {
  padding: 4px 0;
}

.popover-actions button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  background: none;
  color: var(--text);
  border: none;
  border-bottom: 1px solid rgba(61,52,37,0.3);
  font-family: var(--font-body);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s;
}

.popover-actions button:last-child { border-bottom: none; }

.popover-actions button:hover {
  background: rgba(184,148,95,0.12);
  color: var(--accent);
}

.popover-actions button.destructive:hover {
  background: rgba(107,44,44,0.3);
  color: #c47a7a;
}

.popover-status {
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  font-style: italic;
  border-bottom: 1px solid rgba(61,52,37,0.3);
}

/* ── MOBILE BOTTOM NAV (hidden on desktop) ──────────────── */
.mobile-nav {
  display: none;
}

/* ── MOBILE RESPONSIVE ──────────────────────────────────── */
@media (max-width: 768px) {
  /* Body: vertical stack, no side-by-side overflow */
  body {
    height: 100vh;
    height: 100dvh; /* dynamic viewport height for mobile browsers */
    overflow: hidden;
  }

  /* ── Header: compact ──────────────────────────────────── */
  .header {
    padding: 6px 10px;
    flex-wrap: wrap;
    gap: 4px;
  }

  .header-title-area {
    flex: 1 1 100%;
    min-width: 0;
  }

  #chase-selector {
    font-size: 13px;
    max-width: 100%;
    flex: 1;
    min-width: 0;
  }

  .header-controls {
    flex: 1 1 100%;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: center;
  }

  .header-controls button {
    padding: 6px 10px;
    font-size: 12px;
  }

  /* ── Main layout: stacked, one panel visible at a time ── */
  .main-layout {
    flex: 1;
    flex-direction: column;
    position: relative;
    overflow: hidden;
  }

  /* Hide resize handles on mobile */
  .resize-handle { display: none !important; }

  /* All panels become full-width, full-height, absolutely positioned layers */
  #flavor-panel,
  .center-area,
  .right-panel {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    border: none !important;
    z-index: 1;
    display: none;
  }

  /* The active mobile panel */
  .mobile-panel-active {
    display: flex !important;
    flex-direction: column;
  }

  /* Flavor panel active override (it's not flex by default) */
  #flavor-panel.mobile-panel-active {
    display: block !important;
    overflow-y: auto;
    padding: 12px;
    padding-bottom: 70px; /* room for bottom nav */
  }

  /* Center/map area active */
  .center-area.mobile-panel-active {
    display: flex !important;
  }

  /* Right panel: when active, show the appropriate tab */
  .right-panel.mobile-panel-active {
    display: flex !important;
  }

  /* ── Diagram: scrollable & zoomable on mobile ─────────── */
  .mermaid svg {
    min-width: 100%;
    min-height: 300px;
  }

  #diagram-container {
    flex: 1;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    /* Allow native touch scroll/pan; pinch handled by JS */
    touch-action: pan-x pan-y;
  }

  #diagram-inner {
    min-width: 600px; /* still scrollable for complex diagrams */
    transform-origin: top left; /* so scaled content scrolls fully */
    justify-content: flex-start; /* override desktop center — prevents left-side clipping in scroll containers */
  }

  /* ── Token tray: compact ──────────────────────────────── */
  #token-tray {
    padding: 4px 8px;
    min-height: 42px;
    gap: 4px;
  }

  .token {
    width: 40px;
    height: 40px;
    font-size: 11px;
  }

  /* ── Right panel tabs: larger touch targets ────────────── */
  .panel-tabs {
    display: none; /* Tabs replaced by bottom nav on mobile */
  }

  /* Show all tab contents stacked inside right panel when active */
  .right-panel.mobile-panel-active .tab-content.active {
    display: block;
    padding-bottom: 70px; /* room for bottom nav */
  }

  /* ── Grid: scrollable, touch-friendly cells ────────────── */
  #speed-grid {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .grid-cell {
    min-width: 54px;
    min-height: 48px;
  }

  .grid-token {
    width: 36px;
    height: 36px;
    font-size: 11px;
  }

  /* ── Buttons: larger touch targets ────────────────────── */
  .ctrl-btn {
    padding: 10px 14px;
    font-size: 13px;
    min-height: 44px; /* Apple HIG minimum */
  }

  .round-controls button {
    width: 44px;
    height: 44px;
    font-size: 20px;
  }

  .char-delete-btn,
  .node-delete-btn {
    min-height: 44px;
    font-size: 14px;
  }

  .reroll-btn {
    padding: 6px 14px;
    min-height: 36px;
  }

  /* ── Form inputs: larger for touch ────────────────────── */
  .char-field input,
  .char-field select,
  .node-field input,
  .node-field select,
  .node-field textarea {
    font-size: 16px; /* prevents iOS zoom on focus */
    padding: 10px;
    min-height: 44px;
  }

  .manual-roll-input {
    font-size: 16px;
    min-height: 44px;
    width: 80px;
  }

  /* ── Popover: full-width on mobile ────────────────────── */
  .node-popover {
    left: 10px !important;
    right: 10px !important;
    width: auto !important;
    min-width: 0;
  }

  .popover-actions button {
    padding: 14px 12px;
    font-size: 16px;
    min-height: 48px;
  }

  /* ── Toast: above bottom nav ──────────────────────────── */
  .toast.visible {
    bottom: 70px;
  }

  /* ── Warnings panel: full-width mobile ────────────────── */
  .warnings-panel {
    left: 10px;
    right: 10px;
    max-width: none;
  }

  /* ── Bottom nav: shown on mobile ──────────────────────── */
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9000;
    background: linear-gradient(180deg, #2a2218 0%, #1a1510 100%);
    border-top: 2px solid #5a4a30;
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .mobile-nav-btn {
    flex: 1;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    padding: 10px 4px;
    font-family: var(--font-heading);
    font-size: 11px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    cursor: pointer;
    transition: color 0.2s, background 0.2s;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .mobile-nav-btn:hover {
    color: var(--accent);
  }

  .mobile-nav-btn.active {
    color: var(--accent);
    background: rgba(184,148,95,0.1);
    border-top: 2px solid var(--accent);
    margin-top: -2px;
  }
}

/* ── PRINT STYLES ─────────────────────────────────────────── */
@media print {
  body { overflow: visible; height: auto; background: #fff; color: #000; }
  .header, .center-area, .right-panel, .resize-handle, .mobile-nav { display: none !important; }
  #flavor-panel {
    width: 100%; min-width: 100%;
    border: none; padding: 20px;
    background: none;
    display: block !important;
    position: static !important;
  }
  .flavor-card { break-inside: avoid; border-color: #ccc; }
  .flavor-card .flavor-text { display: block !important; color: #333; }
  .flavor-card .node-label { color: #000; }
  .quick-ref-toggle { display: none; }
  .quick-ref-content { display: block !important; border-color: #ccc; }
}
