/* ── Reset & custom properties ────────────────────────────────────────────── */

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

:root {
  --bg:                   #f1f5f9;
  --panel:                #ffffff;
  --border:               #e2e8f0;
  --primary:              #3b82f6;
  --primary-hover:        #2563eb;
  --primary-active:       #1d4ed8;
  --danger:               #ef4444;
  --danger-hover:         #dc2626;
  --secondary-text:       #374151;
  --text:                 #0f172a;
  --text-muted:           #64748b;
  --console-bg:           #1a1b26;
  --console-text:         #a9b1d6;
  --console-error:        #f7768e;
  --resizer:              #e2e8f0;
  --resizer-hover:        #94a3b8;
  --chip-bg:              #f1f5f9;
  --chip-border:          #e2e8f0;
  --chip-checked-bg:      #dbeafe;
  --chip-checked-border:  #93c5fd;
  --chip-checked-text:    #1d4ed8;
  --tab-bar-bg:           #21222c;
  --tab-editor-bg:        #282a36;
  --tab-active-color:     #8be9fd;
  --tab-inactive-color:   #6272a4;
  --font-ui:              system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --shadow-sm:            0 1px 2px 0 rgb(0 0 0 / 0.06);
  --shadow:               0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  font-size: 15pt;
}


/* ── Top-level layout ─────────────────────────────────────────────────────── */

.container {
  display: flex;
  height: 100vh;
}

.column {
  overflow: hidden;
}

.left-column {
  width: 45%;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  box-shadow: 2px 0 12px rgb(0 0 0 / 0.08);
  z-index: 1;
}

.right-column {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  height: 100%;
  background: #f8fafc;
}


/* ── Resizer handles ──────────────────────────────────────────────────────── */

.column-resizer {
  width: 4px;
  background: var(--resizer);
  cursor: col-resize;
  transition: background 0.15s;
  flex-shrink: 0;
}

.column-resizer:hover,
.column-resizer:active {
  background: var(--resizer-hover);
}

.row-resizer {
  height: 4px;
  background: var(--resizer);
  cursor: row-resize;
  transition: background 0.15s;
  flex-shrink: 0;
}

.row-resizer:hover,
.row-resizer:active {
  background: var(--resizer-hover);
}


/* ── Row layout (inside left column) ─────────────────────────────────────── */

.row {
  overflow: hidden;
}

.top-row {
  height: 75%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.bottom-row {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  background: var(--console-bg);
  overflow: hidden;
}


/* ── Shared content wrapper ───────────────────────────────────────────────── */

.content {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  overflow: hidden;
  min-height: 0;
}


/* ── Toolbar ──────────────────────────────────────────────────────────────── */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0;
}

.toolbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--primary);
  flex-shrink: 0;
}

.brand-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  letter-spacing: -0.01em;
}

.import-chips {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.font-size-control {
  display: flex;
  align-items: center;
  gap: 4px;
}

.font-size-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid var(--chip-border);
  background: var(--chip-bg);
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  padding: 0;
  line-height: 1;
}

.font-size-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--chip-checked-bg);
}

#fontSizeDisplay {
  min-width: 22px;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

.chips-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-right: 3px;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--chip-border);
  background: var(--chip-bg);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  user-select: none;
}

.chip:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.chip input[type="checkbox"] {
  display: none;
}

.chip:has(input:checked) {
  background: var(--chip-checked-bg);
  border-color: var(--chip-checked-border);
  color: var(--chip-checked-text);
}


/* ── Tab widget ───────────────────────────────────────────────────────────── */

.tab-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  min-height: 0;
  background: var(--tab-editor-bg);
}

.tab-links {
  list-style: none;
  padding: 0 8px;
  margin: 0;
  display: flex;
  align-items: flex-end;
  background: var(--tab-bar-bg);
  border-bottom: 1px solid #181a1f;
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
}

.tab-links::-webkit-scrollbar { display: none; }

.tab-links li {
  margin-right: 2px;
}

.tab-links a {
  text-decoration: none;
  padding: 9px 14px;
  display: inline-block;
  color: var(--tab-inactive-color);
  font-size: 12px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.tab-links a:hover {
  color: #cdd6f4;
}

.tab-links li.active a {
  color: var(--tab-active-color);
  border-bottom-color: var(--tab-active-color);
}

/* Panels are hidden by default; JS adds .active to show the selected one. */
.tab-content {
  display: none;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.tab-content.active {
  display: flex;
  flex-direction: column;
  flex: 1;
}


/* ── Code editors (CodeMirror) ────────────────────────────────────────────── */

textarea {
  font-family: 'Cascadia Code', 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  resize: none;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
}

.CodeMirror {
  flex: 1;
  height: 100% !important;
  font-family: 'Cascadia Code', 'JetBrains Mono', 'Fira Code', 'Consolas', monospace !important;
  font-size: 13px;
  line-height: 1.55 !important;
}

.CodeMirror-scroll {
  /* Allow the scroll area to fully expand inside its flex container. */
  height: 100%;
}


/* ── Button array ─────────────────────────────────────────────────────────── */

.button-array {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.button-group {
  display: flex;
  gap: 8px;
}


/* ── Buttons ──────────────────────────────────────────────────────────────── */

.button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  line-height: 1;
}

.button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.button--primary {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.button--primary:hover {
  background: var(--primary-hover);
  box-shadow: var(--shadow);
}

.button--primary:active {
  background: var(--primary-active);
  box-shadow: none;
}

.button--secondary {
  background: var(--panel);
  color: var(--secondary-text);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.button--secondary:hover {
  background: var(--bg);
  border-color: #cbd5e1;
}

.button--danger {
  background: var(--panel);
  color: var(--danger);
  border-color: #fecaca;
  box-shadow: var(--shadow-sm);
}

.button--danger:hover {
  background: #fef2f2;
  border-color: var(--danger);
}

.button--ghost {
  background: transparent;
  color: #4b5568;
  border-color: transparent;
  padding: 5px 10px;
  font-size: 11px;
}

.button--ghost:hover {
  background: rgba(255 255 255 / 0.08);
  color: #9ca3af;
}


/* ── Console panel ────────────────────────────────────────────────────────── */

.console-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid rgba(255 255 255 / 0.06);
  flex-shrink: 0;
}

.console-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #4b5568;
}

.console-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  flex-shrink: 0;
}

#console-output {
  background-color: var(--console-bg);
  color: var(--console-text);
  font-family: 'Cascadia Code', 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.65;
  padding: 12px 16px;
  overflow-x: hidden;
  overflow-y: auto;
  flex-grow: 1;
}

#console-output .console-error {
  color: var(--console-error);
  font-weight: 600;
}

/* CindyJS appends its own error nodes to the csconsole element. */
#console-output p,
#console-output span:not(.console-error) {
  margin: 0;
  display: inline;
}


/* ── Canvas ───────────────────────────────────────────────────────────────── */

.right-column .content {
  position: relative;
}

#canvas-size-label {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.45);
  color: #e2e8f0;
  font-family: 'Cascadia Code', 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  pointer-events: none;
  z-index: 10;
  letter-spacing: 0.03em;
}

#CSCanvas {
  flex-grow: 1;
  width: 100%;
  height: 100%;
  background-color: white;
  display: block;
}


/* ── Export modal ─────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: #24283b;
  border: 1px solid #414868;
  border-radius: 8px;
  padding: 24px;
  width: 420px;
  max-width: 90vw;
  color: #a9b1d6;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.modal-title {
  font-size: 15px;
  font-weight: 600;
  color: #c0caf5;
  margin: 0 0 18px 0;
}

.modal-section {
  margin-bottom: 14px;
}

.export-options {
  display: flex;
  gap: 10px;
}

.export-option {
  flex: 1;
  display: flex;
  gap: 10px;
  padding: 12px;
  border: 1px solid #414868;
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.export-option:has(input:checked) {
  border-color: #7aa2f7;
  background: rgba(122, 162, 247, 0.07);
}

.export-option input[type="radio"] {
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: #7aa2f7;
}

.export-option-title {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #c0caf5;
  margin-bottom: 3px;
}

.export-option-desc {
  display: block;
  font-size: 11px;
  color: #a9b1d6;
  line-height: 1.4;
}

.modal-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #c0caf5;
  cursor: pointer;
}

.modal-checkbox input[type="checkbox"] {
  accent-color: #7aa2f7;
}

.modal-label {
  display: block;
  font-size: 12px;
  color: #a9b1d6;
  margin-bottom: 6px;
}

.modal-input {
  width: 100%;
  background: #1a1b26;
  border: 1px solid #414868;
  border-radius: 4px;
  padding: 7px 10px;
  color: #c0caf5;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.modal-input:focus {
  border-color: #7aa2f7;
}

.modal-buttons {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding-top: 6px;
}
