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

:root {
  --bg:           #ede9df;
  --surface:      #f4f2eb;
  --surface-2:    #eae6db;
  --border:       #d8d3c6;
  --border-hover: #b8b2a4;
  --text-primary: #1c1b18;
  --text-secondary: #4a4740;
  --text-muted:   #8a8780;
  --accent:       #c86440;
  --accent-dim:   rgba(200,100,64,0.10);
  --accent-hover: #d97350;
  --radius-sm: 5px;
  --radius-md: 10px;
  --font-ui:   'Inter', system-ui, sans-serif;
  --font-serif: 'Playfair Display', Georgia, serif;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: grid;
  grid-template-areas:
    "header header"
    "canvas panel";
  grid-template-columns: 1fr 280px;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

/* ── Header ─────────────────────────────────── */
.app-header {
  grid-area: header;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

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

.brand-mark {
  display: block;
  width: 18px; height: 18px;
  background: var(--accent);
  border-radius: 3px;
  transform: rotate(10deg);
}

.brand-name {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.brand-sub {
  color: var(--text-muted);
  font-size: 12px;
  padding-left: 14px;
  border-left: 1px solid var(--border);
}

/* ── Canvas area ─────────────────────────────── */
.canvas-wrapper {
  grid-area: canvas;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background: var(--bg);
}

.canvas-container {
  width: 100%;
  max-width: 1100px;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow:
    0 0 0 1px var(--border),
    0 16px 48px rgba(28,27,24,0.15);
}

.canvas-container canvas {
  display: block;
  width: 100%;
  height: auto;
}

/* ── Control panel ───────────────────────────── */
.control-panel {
  grid-area: panel;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.panel-section {
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-section:last-child { border-bottom: none; }

.section-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ── Theme grid ──────────────────────────────── */
.theme-grid { display: flex; flex-direction: column; gap: 5px; }

.theme-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.14s ease;
  text-align: left;
}

.theme-btn:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
  background: var(--surface-2);
}

.theme-btn.active {
  border-color: var(--accent);
  color: var(--text-primary);
  background: var(--accent-dim);
}

.theme-icon {
  display: inline-flex;
  width: 34px;
  height: 20px;
  border-radius: 3px;
  flex-shrink: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 7px;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

/* ── Form fields ─────────────────────────────── */
.field-group { display: flex; flex-direction: column; gap: 5px; }

.field-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.field-hint {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 400;
}

.seed-value {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  font-weight: 500;
}

.field-input {
  padding: 7px 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 13px;
  transition: border-color 0.14s;
  outline: none;
}

.field-input:focus { border-color: var(--accent); }

/* ── Select ──────────────────────────────────── */
.field-select {
  padding: 7px 28px 7px 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 13px;
  outline: none;
  cursor: pointer;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238a8780'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border-color 0.14s;
}

.field-select:focus { border-color: var(--accent); }

/* ── Color pickers ───────────────────────────── */
.color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.color-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  flex: 1;
}

.color-input {
  width: 40px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
  padding: 2px 3px;
  flex-shrink: 0;
}

/* ── Ticker row ──────────────────────────────── */
.ticker-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ticker-row .field-input { flex: 1; }

.ticker-status {
  font-family: var(--font-mono);
  font-size: 14px;
  min-width: 18px;
  text-align: center;
  color: var(--accent);
  flex-shrink: 0;
}

/* ── File upload ─────────────────────────────── */
.upload-btn {
  display: block;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: all 0.14s ease;
}

.upload-btn:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
  background: var(--surface-2);
}

/* ── Toggle group ────────────────────────────── */
.toggle-group { display: flex; gap: 4px; }

.toggle-btn {
  flex: 1;
  padding: 6px 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.14s ease;
}

.toggle-btn:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.toggle-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Range input ─────────────────────────────── */
.range-input {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.range-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--surface);
  transition: transform 0.1s;
}

.range-input::-webkit-slider-thumb:hover { transform: scale(1.2); }

/* ── Buttons ─────────────────────────────────── */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.14s ease;
  width: 100%;
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(200,100,64,0.30);
}

.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  padding: 7px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.14s ease;
  width: 100%;
}

.btn-secondary:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
  background: var(--surface-2);
}

.export-note {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.4;
}

/* ── Theme legend ────────────────────────────── */
.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.legend-btn {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.14s ease;
}

.legend-btn:hover,
.legend-btn[aria-expanded="true"] {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

.theme-legend {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.legend-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.legend-key {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--accent);
  letter-spacing: 0.04em;
  opacity: 0.85;
}

.legend-val {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.35;
}

/* ── Easter egg: brand-mark spin ─────────────── */
.brand-name {
  cursor: default;
  user-select: none;
}

.brand-name:hover { cursor: pointer; }

@keyframes spin-once {
  from { transform: rotate(10deg); }
  to   { transform: rotate(370deg); }
}

.brand-mark.spinning {
  animation: spin-once 0.65s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

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

/* ── Scrollbar ───────────────────────────────── */
.control-panel::-webkit-scrollbar { width: 4px; }
.control-panel::-webkit-scrollbar-track { background: transparent; }
.control-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Responsive ──────────────────────────────── */
@media (max-width: 860px) {
  .app {
    grid-template-areas: "header" "canvas" "panel";
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }
  .control-panel {
    border-left: none;
    border-top: 1px solid var(--border);
    flex-direction: row;
    flex-wrap: wrap;
    padding: 16px;
    gap: 16px;
  }
  .panel-section {
    min-width: 160px;
    flex: 1;
    border-bottom: none;
    border-right: 1px solid var(--border);
    padding: 0 16px 0 0;
  }
  .panel-section:last-child { border-right: none; }
  .canvas-wrapper { padding: 16px; }
}
