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

body {
  background: #0a0a1a;
  color: #c9d1d9;
  font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 20px 40px;
}

header {
  text-align: center;
  margin-bottom: 16px;
}

header h1 {
  font-size: 22px;
  letter-spacing: 4px;
  color: #00ff88;
  font-weight: 600;
}

header .subtitle {
  font-size: 11px;
  color: #6a7280;
  margin-top: 4px;
  letter-spacing: 1px;
}

/* Simulation + sidebar row */
.sim-row {
  display: flex;
  gap: 0;
  align-items: stretch;
}

/* Simulation viewport */
.sim-container {
  position: relative;
  border: 1px solid #1e1e2e;
  border-radius: 4px 0 0 4px;
  overflow: hidden;
  line-height: 0;
}

/* Queue sidebar */
.queue-sidebar {
  width: 180px;
  background: #10101c;
  border: 1px solid #1e1e2e;
  border-left: none;
  border-radius: 0 4px 4px 0;
  padding: 8px 0;
  overflow-y: auto;
  /* max-height set by JS to match canvas height */
}

/* Patron focus panel */
.patron-focus {
  padding: 8px 10px;
  border-bottom: 1px solid #1e1e2e;
  position: relative;
  background: #16162a;
}

.patron-focus .focus-close {
  position: absolute;
  top: 4px;
  right: 6px;
  background: none;
  border: none;
  color: #6a7280;
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.patron-focus .focus-close:hover {
  color: #c9d1d9;
}

.patron-focus .focus-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.patron-focus .focus-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1.5px solid rgba(255, 255, 255, 0.2);
}

.patron-focus .focus-name {
  font-size: 13px;
  font-weight: 600;
  color: #e0e0e0;
}

.patron-focus .focus-details {
  font-size: 10px;
  color: #8a8a9a;
  line-height: 1.6;
}

.patron-focus .focus-details .focus-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.patron-focus .focus-details .focus-row > span:first-child {
  flex-shrink: 0;
}

.patron-focus .focus-details .focus-val {
  color: #c9d1d9;
  font-weight: 600;
}

.patron-focus .focus-details .focus-val.accent {
  color: #00ff88;
}

.patron-focus .focus-details .focus-val.warn {
  color: #ff8855;
}

/* Patience bar */
.patience-bar {
  height: 3px;
  background: #2a2a3e;
  border-radius: 2px;
  margin-top: 4px;
  overflow: hidden;
}

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

.queue-sidebar .panel-title {
  padding: 0 10px 6px;
  border-bottom: 1px solid #1e1e2e;
  margin-bottom: 4px;
}

canvas#sim-canvas {
  display: block;
}

/* ── HTML overlay (patrons, KJ, bubbles) ── */
#sim-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
}

/* Patron circles */
.patron {
  position: absolute;
  left: 0;
  top: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  will-change: transform;
  transition: transform 80ms linear;
  border: 1.5px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  pointer-events: auto;
  cursor: pointer;
}

.patron.singing {
  border-color: #ffcc44;
  border-width: 2px;
  z-index: 3;
  animation: singing-glow 1.5s ease-in-out infinite;
}

@keyframes singing-glow {
  0%, 100% {
    box-shadow:
      0 0 8px 3px rgba(255, 200, 100, 0.3),
      0 1px 3px rgba(0, 0, 0, 0.4);
  }
  50% {
    box-shadow:
      0 0 18px 8px rgba(255, 200, 100, 0.5),
      0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

.patron.selected {
  border-color: #ffffff;
  border-width: 2px;
  box-shadow: 0 0 10px 3px rgba(255, 255, 255, 0.3), 0 1px 3px rgba(0, 0, 0, 0.4);
  z-index: 5;
}

.patron .queue-num {
  font: bold 9px/1 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  color: #0a0a1a;
  text-shadow: 0 0 3px rgba(255, 255, 255, 0.25);
  user-select: none;
}

.patron .patron-name {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  font: 7px/1 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  color: #505868;
  white-space: nowrap;
  margin-top: 3px;
  user-select: none;
}

/* KJ star */
.kj {
  position: absolute;
  left: 0;
  top: 0;
  width: 26px;
  height: 26px;
  background: #00dd77;
  clip-path: polygon(
    50% 0%, 61% 35%, 98% 35%, 68% 57%,
    79% 91%, 50% 70%, 21% 91%, 32% 57%,
    2% 35%, 39% 35%
  );
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
  will-change: transform;
}

.kj .kj-text {
  font: bold 7px/1 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  color: #0a0a1a;
  margin-top: 1px;
  user-select: none;
}

/* KJ speech bubble */
.kj-bubble {
  position: absolute;
  background: rgba(0, 220, 120, 0.92);
  color: #0a0a1a;
  font: bold 10px/1.2 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  padding: 5px 10px;
  border-radius: 6px;
  white-space: nowrap;
  z-index: 5;
  transform: translateX(-50%);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
  user-select: none;
}

.kj-bubble::before {
  content: '';
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-bottom-color: rgba(0, 220, 120, 0.92);
}

.kj-bubble.no-show {
  background: rgba(255, 100, 80, 0.92);
}

.kj-bubble.no-show::before {
  border-bottom-color: rgba(255, 100, 80, 0.92);
}

/* Patron thought bubbles */
.patron .thought {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(12, 12, 22, 0.88);
  color: #c8d0da;
  font: 8px/1.2 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  padding: 3px 6px;
  border-radius: 4px;
  white-space: nowrap;
  margin-bottom: 5px;
  z-index: 6;
  pointer-events: none;
  user-select: none;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.patron .thought::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 3px solid transparent;
  border-top-color: rgba(12, 12, 22, 0.88);
}

/* Controls */
.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.controls button {
  background: #1a1a2e;
  color: #c9d1d9;
  border: 1px solid #2a2a3e;
  padding: 6px 14px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  border-radius: 3px;
  transition: background 0.15s, border-color 0.15s;
}

.controls button:hover {
  background: #24243a;
  border-color: #00ff88;
}

.controls button.active {
  background: #00ff88;
  color: #0a0a1a;
  border-color: #00ff88;
}

.controls label {
  font-size: 11px;
  color: #6a7280;
  display: flex;
  align-items: center;
  gap: 6px;
}

.controls input[type="range"] {
  width: 100px;
  accent-color: #00ff88;
}

.controls input[type="number"] {
  width: 60px;
  background: #14141e;
  border: 1px solid #2a2a3e;
  color: #c9d1d9;
  padding: 4px 6px;
  font-family: inherit;
  font-size: 11px;
  border-radius: 3px;
}

.controls .speed-label,
.controls .venue-label {
  color: #00ff88;
  font-size: 11px;
  min-width: 48px;
}

.controls select {
  background: #14141e;
  border: 1px solid #2a2a3e;
  color: #c9d1d9;
  padding: 4px 6px;
  font-family: inherit;
  font-size: 11px;
  border-radius: 3px;
  cursor: pointer;
}

.controls select:focus {
  border-color: #00ff88;
  outline: none;
}

/* Rules panel */
.rules-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
  max-width: 100%;
}

.rules-header {
  grid-column: 1 / -1;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: #6a7280;
  padding-bottom: 2px;
}

.rule-card {
  background: #12121e;
  border: 1px solid #1e1e2e;
  border-radius: 4px;
  padding: 10px 12px;
  transition: border-color 0.2s;
}

.rule-card:has(input:checked) {
  border-color: #1a3a2a;
}

.rule-main {
  font-size: 12px;
  color: #c9d1d9;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.rule-main input[type="checkbox"] {
  accent-color: #00ff88;
  cursor: pointer;
  width: 14px;
  height: 14px;
}

.rule-desc {
  font-size: 10px;
  color: #5a5a6a;
  margin-top: 5px;
  line-height: 1.4;
}

.rule-card:has(input:checked) .rule-desc {
  color: #6a7280;
}

/* Sub-rules (nested options) */
.rule-sub {
  display: none;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #1a1a28;
}

.rule-card:has(> .rule-main input:checked) .rule-sub {
  display: block;
}

.rule-sub-label {
  font-size: 11px;
  color: #8a8a9a;
  display: flex;
  align-items: center;
  gap: 6px;
}

.rule-sub-label select {
  background: #0e0e1a;
  border: 1px solid #2a2a3e;
  color: #c9d1d9;
  padding: 3px 6px;
  font-family: inherit;
  font-size: 10px;
  border-radius: 3px;
  cursor: pointer;
}

.rule-sub-label select:focus {
  border-color: #00ff88;
  outline: none;
}

.rule-sub-desc {
  font-size: 9px;
  color: #4a4a5a;
  margin-top: 4px;
  line-height: 1.3;
}

/* Stats bar */
.stats-bar {
  display: flex;
  gap: 18px;
  margin-top: 12px;
  font-size: 11px;
  color: #6a7280;
  flex-wrap: wrap;
  justify-content: center;
}

.stats-bar .value {
  color: #c9d1d9;
  font-weight: 600;
}

.stats-bar .value.accent {
  color: #00ff88;
}

.phase-indicator {
  font-size: 10px;
  letter-spacing: 1px;
  font-weight: 700;
}

.phase-indicator.last-call {
  color: #ffaa33;
}

.phase-indicator.closing {
  color: #ff6655;
}

.phase-indicator.ended {
  color: #6a7280;
}

/* Dashboard */
.dashboard {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
  max-width: 100%;
}

.panel {
  background: #12121e;
  border: 1px solid #1e1e2e;
  border-radius: 4px;
  padding: 10px;
}

.panel-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: #6a7280;
  margin-bottom: 8px;
}

/* Queue list */
.queue-entry {
  display: flex;
  align-items: center;
  font-size: 11px;
  padding: 3px 10px;
  border-bottom: 1px solid #1a1a24;
  gap: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.queue-entry:hover {
  background: rgba(255, 255, 255, 0.04);
}

.queue-entry.selected {
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 2px 0 0 #fff;
}

.queue-entry.top-3 {
  background: rgba(255, 204, 68, 0.05);
}

.queue-entry .dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font: bold 8px/1 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  color: #0a0a1a;
  text-shadow: 0 0 2px rgba(255, 255, 255, 0.2);
  border: 1.5px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.queue-entry .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue-entry .meta {
  font-size: 9px;
  color: #6a7280;
  text-align: right;
  white-space: nowrap;
}

.queue-entry .meta .tag {
  color: #00cc66;
}

.queue-entry .meta .repeat {
  color: #8888aa;
}

.queue-empty {
  font-size: 11px;
  color: #3a3a4a;
  font-style: italic;
  padding: 8px 10px;
}

/* Chart canvases */
.panel canvas {
  width: 100%;
  height: 120px;
  display: block;
}

/* Detail stats */
.stats-detail-panel table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.stats-detail-panel th {
  text-align: left;
  color: #6a7280;
  font-weight: normal;
  padding: 3px 6px;
  border-bottom: 1px solid #1e1e2e;
}

.stats-detail-panel td {
  padding: 3px 6px;
  border-bottom: 1px solid #16161e;
}

.stats-detail-panel td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Utility */
.hidden {
  display: none !important;
}

/* Next Night button */
#btn-next-night {
  background: #1a3a2a;
  border-color: #00ff88;
  color: #00ff88;
  font-weight: 600;
}

#btn-next-night:hover {
  background: #00ff88;
  color: #0a0a1a;
}

/* Pause checkbox */
.checkbox-label {
  font-size: 11px;
  color: #6a7280;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  accent-color: #00ff88;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 5px;
}
::-webkit-scrollbar-track {
  background: #0a0a1a;
}
::-webkit-scrollbar-thumb {
  background: #2a2a3e;
  border-radius: 3px;
}
