/* --- Reset & Base --- */
:root {
  --bg-color: #f7f7f7;
  --text-color: #222;
  --accent-color: #2a7a8a;
  --header-bg: #fff;
  --card-bg: #fff;
  --border-color: #ddd;
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  --header-text: #333;
  --secondary-bg: #fafafa;
  --code-bg: #fff;
}

/* Dark Theme Overrides */
body.dark-theme {
  --bg-color: #1a1a1a;
  --text-color: #e0e0e0;
  --accent-color: #4CAF50;
  --header-bg: #111;
  --card-bg: #2d2d2d;
  --border-color: #444;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  --header-text: #fff;
  --secondary-bg: #222;
  --code-bg: #111;
}

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

html,
body {
  height: 100%;
  font-family: 'SF Mono', 'Menlo', 'Consolas', 'Liberation Mono', monospace;
  font-size: 14px;
  color: var(--text-color);
  background: var(--bg-color);
  transition: background 0.3s, color 0.3s;
}

body {
  display: flex;
  flex-direction: column;
}

/* --- Toolbar --- */
#toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  transition: background 0.3s, border-bottom 0.3s;
}

#toolbar h1 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--header-text);
}

.toolbar-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toolbar-info {
  font-size: 12px;
  color: #777;
  background: var(--secondary-bg);
  padding: 3px 8px;
  border-radius: 3px;
}

#toolbar button {
  padding: 5px 12px;
  font-size: 12px;
  font-family: inherit;
  border: 1px solid var(--border-color);
  border-radius: 3px;
  background: var(--card-bg);
  color: var(--text-color);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

#toolbar button:hover {
  background: #f0f0f0;
  border-color: #aaa;
}

#toolbar button:active {
  background: #e8e8e8;
}

#btn-open-config {
  font-size: 16px !important;
  line-height: 1;
  padding: 4px 8px !important;
}

#btn-open-config:hover {
  transform: rotate(30deg);
}

/* --- Modal Actions --- */
.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-reload-js {
  padding: 6px 16px;
  font-size: 12px;
  font-family: inherit;
  border: 1px solid var(--border-color);
  border-radius: 3px;
  background: var(--card-bg);
  color: var(--text-color);
  cursor: pointer;
  transition: background 0.15s;
}

.modal-reload-js:hover {
  background: var(--secondary-bg);
}

/* --- Hint text --- */
/* --- Timeline Container --- */
#timeline-container {
  flex: 1 1 50%;
  overflow: auto;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  position: relative;
  min-height: 200px;
}

#timeline-canvas {
  display: block;
}

/* --- Tooltip --- */
.tooltip {
  display: none;
  position: fixed;
  z-index: 100;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-color);
  box-shadow: var(--shadow);
  max-width: 300px;
  pointer-events: none;
}

.tooltip code {
  font-size: 10px;
  color: #555;
  word-break: break-all;
}

/* --- Resizer Bar --- */
#resizer {
  flex: 0 0 6px;
  background: #eee;
  cursor: row-resize;
  border-top: 1px solid #ddd;
  border-bottom: 1px solid #ddd;
  transition: background 0.1s;
  z-index: 10;
}

#resizer:hover,
#resizer.dragging {
  background: #ccc;
}

/* --- State Inspector --- */
#state-inspector {
  flex: 0 0 auto;
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  overflow-x: auto;
  overflow-y: hidden;
  background: var(--secondary-bg);
  min-height: 120px;
}

.state-card {
  flex: 0 0 auto;
  min-width: 180px;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.3s;
  resize: horizontal;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.state-card:hover {
  border-color: #aaa;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.state-card.crashed {
  border-color: #f44336;
  background: #fff5f5;
  opacity: 0.85;
}

.state-card.crashed .state-card-header {
  background: #ffebee;
  border-bottom-color: #ffcdd2;
}

body.dark-theme .state-card.crashed {
  background: #3d2a2a;
  border-color: #f44336;
}

.state-card-header {
  padding: 4px 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--header-text);
  background: var(--header-bg);
  border-bottom: 1px solid var(--border-color);
  border-radius: 4px 4px 0 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  min-height: 32px;
  min-width: 0;
}

.state-badge {
  font-size: 10px;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 10px;
  color: white;
  /* Dynamically overridden in JS */
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}


.state-card-name {
  cursor: pointer;
}

.state-card-name:hover {
  color: #2a7a8a;
}

.state-card-name-input {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: #333;
  border: 1px solid #ccc;
  border-radius: 2px;
  padding: 0 4px;
  width: 100%;
  outline: none;
}

.state-card-body {
  padding: 6px 0;
  font-size: 11px;
  line-height: 1.4;
  color: #333;
  flex: 1;
  overflow-y: auto;
}

.state-table {
  width: 100%;
  border-collapse: collapse;
}

.state-table tr:not(:last-child) {
  border-bottom: 1px solid #f0f0f0;
}

.state-table td {
  padding: 3px 10px;
  vertical-align: top;
}

.state-key {
  color: #777;
  font-weight: 500;
  white-space: nowrap;
  width: 1%;
}

.state-val {
  color: #222;
  word-break: break-word;
}

.state-empty {
  display: block;
  padding: 6px 10px;
  color: #bbb;
  font-style: italic;
}

.state-error {
  padding: 4px 10px;
  color: #b33;
  font-size: 10px;
}

/* --- Code Editor Modal --- */
.modal {
  display: none;
}

.modal.open {
  display: flex;
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
}

.modal-content {
  position: relative;
  z-index: 1;
  width: 90%;
  max-width: 640px;
  max-height: 80vh;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid #eee;
}

.modal-title {
  font-size: 13px;
  font-weight: 600;
  color: #333;
}

.modal-header button {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: #777;
  padding: 2px 6px;
}

.modal-header button:hover {
  color: #333;
}

.modal-editor-wrap {
  flex: 1;
  min-height: 200px;
  overflow: auto;
}

.modal-editor-wrap .CodeMirror {
  height: 100%;
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.6;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border-top: 1px solid #eee;
}

.modal-error {
  font-size: 11px;
  color: #c33;
}

.modal-save {
  padding: 6px 16px;
  font-size: 12px;
  font-family: inherit;
  border: 1px solid #2a7a8a;
  border-radius: 3px;
  background: #2a7a8a;
  color: #fff;
  cursor: pointer;
  transition: background 0.15s;
}

.modal-save:hover {
  background: #237080;
}

/* --- Hint text --- */
#state-inspector::after {
  content: 'Double-click a card to edit code';
  position: absolute;
  bottom: 4px;
  right: 16px;
  font-size: 10px;
  color: #bbb;
}

#state-inspector {
  position: relative;
}