/* ─── Global Reset ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0d0d12;
  --panel-bg:   #16161e;
  --surface:    #1e1e2a;
  --border:     #2a2a3a;
  --text:       #d4d4e0;
  --text-muted: #6a6a80;
  --accent:     #b48afa;
  --accent-2:   #64dfdf;
  --danger:     #f87171;
  --radius:     8px;
  --font:       'Inter', -apple-system, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:         #f9fafb;
    --panel-bg:   #ffffff;
    --surface:    #f3f4f6;
    --border:     #e5e7eb;
    --text:       #111827;
    --text-muted: #6b7280;
    --accent:     #8b5cf6;
    --accent-2:   #0d9488;
  }
}

:root[data-theme="light"] {
  --bg:         #f9fafb;
  --panel-bg:   #ffffff;
  --surface:    #f3f4f6;
  --border:     #e5e7eb;
  --text:       #111827;
  --text-muted: #6b7280;
  --accent:     #8b5cf6;
  --accent-2:   #0d9488;
}

:root[data-theme="dark"] {
  --bg:         #0d0d12;
  --panel-bg:   #16161e;
  --surface:    #1e1e2a;
  --border:     #2a2a3a;
  --text:       #d4d4e0;
  --text-muted: #6a6a80;
  --accent:     #b48afa;
  --accent-2:   #64dfdf;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100vh;
}

#app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ─── Sidebar ─── */
#sidebar {
  width: 320px;
  min-width: 280px;
  background: var(--panel-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding: 18px 14px 24px;
  z-index: 10;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#sidebar-header .ante-title {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 2px;
}
#sidebar-header h1 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
  letter-spacing: -0.03em;
}
#sidebar-header h1 span { color: var(--accent-2); }
.subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

#sidebar-footer {
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.app-description {
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 12px;
}
.credits {
  font-size: 0.65rem;
  color: var(--text-muted);
  line-height: 1.4;
}
.credits a {
  color: var(--accent);
  text-decoration: none;
}
.credits a:hover {
  text-decoration: underline;
}

/* ─── Theme Toggle ─── */
.theme-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s, color 0.2s;
  width: auto;
  margin-top: 0;
}
.theme-toggle:hover {
  background: var(--surface);
  color: var(--accent);
}

/* ─── Drop Zone ─── */
#dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 22px 12px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  text-align: center;
  transition: border-color .2s, background .2s;
  user-select: none;
}
#dropzone:hover, #dropzone.dragover {
  border-color: var(--accent);
  background: rgba(180, 138, 250, 0.08);
}
.drop-icon { font-size: 1.6rem; }
#dropzone span { font-size: 0.85rem; font-weight: 500; color: var(--text); }
#dropzone small { font-size: 0.72rem; color: var(--text-muted); }
#dropzone.loaded { border-style: solid; border-color: var(--accent-2); }

/* Secondary dropzones (vector + bitmap) — same visual language as the
   font dropzone but compact, stacked underneath. */
.dropzone-secondary {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 12px 10px;
  margin-top: 8px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  text-align: center;
  transition: border-color .2s, background .2s;
  user-select: none;
}
.dropzone-secondary:hover,
.dropzone-secondary.dragover {
  border-color: var(--accent);
  background: rgba(180, 138, 250, 0.08);
}
.dropzone-secondary .drop-icon { font-size: 1.2rem; }
.dropzone-secondary span  { font-size: 0.78rem; font-weight: 500; color: var(--text); }
.dropzone-secondary small { font-size: 0.68rem; color: var(--text-muted); line-height: 1.3; }
.dropzone-secondary.loaded { border-style: solid; border-color: var(--accent-2); }

/* ─── Font info ─── */
.info-tag {
  font-size: 0.78rem;
  background: rgba(100, 223, 223, 0.12);
  color: var(--accent-2);
  border: 1px solid rgba(100, 223, 223, 0.25);
  padding: 5px 10px;
  border-radius: 100px;
  display: inline-block;
  word-break: break-all;
}

/* ─── Panel ─── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.panel h3 {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* ─── Form Elements ─── */
select, input[type="text"] {
  width: 100%;
  padding: 7px 10px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font);
  font-size: 0.82rem;
  outline: none;
  transition: border-color .2s;
}
select:focus, input[type="text"]:focus { border-color: var(--accent); }

/* ─── Axis Controls ─── */
.axis-control { margin-bottom: 10px; }
.axis-control:last-child { margin-bottom: 0; }
.axis-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 3px;
}
.axis-label strong { color: var(--text); font-weight: 500; }
.axis-label .axis-val { 
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
input[type=range] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ─── Glyph Grid ─── */
.selected-count {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin: 6px 0 4px;
}
.glyph-bulk-actions {
  display: flex;
  gap: 4px;
  margin: 2px 0 4px;
}
.btn-mini {
  flex: 1;
  margin-top: 0 !important;
  padding: 5px 8px;
  font-size: 0.72rem;
  font-weight: 500;
}
#glyph-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(30px, 1fr));
  gap: 3px;
  max-height: 220px;
  overflow-y: auto;
  margin-top: 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.glyph-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 2px;
  text-align: center;
  cursor: pointer;
  border-radius: 4px;
  font-size: 1rem;
  line-height: 1;
  transition: all .15s;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.glyph-btn:hover { background: var(--surface); border-color: var(--accent); }
.glyph-btn.selected { background: var(--accent); color: #000; border-color: var(--accent); }

/* ─── Toggle ─── */
.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  cursor: pointer;
}
.toggle-label input[type=checkbox] { accent-color: var(--accent); width: 14px; height: 14px; }

/* ─── Buttons ─── */
button {
  width: 100%;
  padding: 9px 12px;
  background: var(--accent);
  color: #000;
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  margin-top: 6px;
}
button:hover { opacity: 0.88; transform: translateY(-1px); }
button:active { transform: translateY(0); }
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.export-panel { display: flex; flex-direction: column; }

/* ─── Viewport ─── */
#viewport {
  flex: 1;
  position: relative;
  background: var(--bg);
  overflow: hidden;
}
#viewport canvas { display: block; }

/* ─── Loading ─── */
#loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  background: rgba(22, 22, 30, 0.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  padding: 24px 40px;
  border-radius: 12px;
  font-size: 0.9rem;
  z-index: 100;
}
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Empty State ─── */
#empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--text-muted);
  pointer-events: none;
}
.empty-icon { font-size: 3rem; margin-bottom: 12px; opacity: 0.3; }
#empty-state p { font-size: 0.9rem; max-width: 220px; }

/* ─── Advanced Customization Accordion ─── */
.advanced-panel {
  padding: 0;
}
.advanced-panel > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  user-select: none;
}
.advanced-panel > summary::-webkit-details-marker {
  display: none;
}
.advanced-panel > summary:hover {
  color: var(--accent);
}
.advanced-panel .adv-chevron {
  display: inline-block;
  transition: transform 0.18s ease;
  color: var(--text-muted);
  font-size: 0.8rem;
}
.advanced-panel[open] > summary .adv-chevron {
  transform: rotate(90deg);
  color: var(--accent);
}
.advanced-panel[open] > summary {
  border-bottom: 1px solid var(--border);
}

.adv-section {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.adv-section:last-of-type {
  border-bottom: none;
}
.adv-section h4 {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 2px;
}
.adv-section > select {
  margin-bottom: 4px;
}

.adv-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.adv-row label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.74rem;
  color: var(--text-muted);
}
.adv-val {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-size: 0.74rem;
}
.adv-total {
  flex-direction: row;
  justify-content: space-between;
  padding-top: 4px;
  border-top: 1px dashed var(--border);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.adv-dual {
  display: flex;
  align-items: center;
  gap: 8px;
}
.adv-dual input[type="number"] {
  flex: 0 0 70px;
  padding: 5px 8px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-family: var(--font);
  font-size: 0.82rem;
  outline: none;
  -moz-appearance: textfield;
}
.adv-dual input[type="number"]::-webkit-outer-spin-button,
.adv-dual input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.adv-dual input[type="number"]:focus {
  border-color: var(--accent);
}
.adv-unit {
  color: var(--text-muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

/* Disabled state for sub-controls when parent toggle is off */
.adv-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin: 6px 0 10px;
  line-height: 1.4;
}
.adv-hint strong { color: var(--text); font-weight: 600; }

.adv-section.disabled .adv-row,
.adv-section.disabled > select {
  opacity: 0.45;
  pointer-events: none;
}

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

/* ─── Viewport overlay toolbar ─── */
#view-toolbar {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  gap: 6px;
  z-index: 30;
  pointer-events: none;
}
#view-toolbar .view-toggle {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  font: 500 0.72rem/1 var(--font);
  letter-spacing: 0.04em;
  color: var(--text);
  background: rgba(22, 22, 30, 0.72);
  border: 1px solid var(--border);
  border-radius: 999px;
  backdrop-filter: blur(6px);
  cursor: pointer;
  user-select: none;
  transition: background .15s, border-color .15s, color .15s;
}
:root[data-theme="light"] #view-toolbar .view-toggle {
  background: rgba(255, 255, 255, 0.85);
  color: var(--text);
}
#view-toolbar .view-toggle:hover {
  border-color: var(--accent);
}
#view-toolbar .view-toggle.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
#view-toolbar .view-icon { font-size: 0.9rem; line-height: 1; }
#view-toolbar .view-label { font-size: 0.7rem; text-transform: uppercase; }

/* ─── Trace-options modal ─── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}
.modal-panel {
  position: relative;
  background: var(--panel-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 26px 18px;
  width: min(720px, 92vw);
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.modal-header h3 { font-size: 1.05rem; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 6px;
}
.modal-close:hover { color: var(--text); }
.modal-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 14px;
  line-height: 1.4;
}
.modal-hint strong { color: var(--text); font-weight: 600; }

.trace-previews {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 16px;
}
.trace-col h4 {
  font-size: 0.74rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.trace-preview-box {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
.trace-preview-box img,
.trace-preview-box svg {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}
.trace-empty { font-size: 0.72rem; color: #9ca3af; }

.trace-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: 6px;
}
.trace-controls .toggle-label {
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.modal-footer button { padding: 8px 18px; }
