/* ═══════════════════════════════════════════
   LABYRINTH CIRCUIT MAKER — Atelier Dark
   Cinzel + Courier Prime · Amber on near-black
═══════════════════════════════════════════ */

:root {
  --bg:           #0b0b09;
  --panel:        #111110;
  --panel-mid:    #161614;
  --border:       #232118;
  --border-mid:   #2e2b22;

  --accent:       #c4944a;
  --accent-dim:   rgba(196, 148, 74, 0.10);
  --accent-mid:   rgba(196, 148, 74, 0.22);

  --text:         #d6d1c4;
  --text-dim:     #7a7468;
  --text-muted:   #42403a;

  --danger:       rgba(160, 60, 60, 0.6);
  --danger-text:  #c07070;
  --danger-hover: rgba(160, 60, 60, 0.18);

  --shape-stroke: #888888;
  --shape-fill:   rgba(255, 255, 255, 0.03);
  --point-color:  #aaaaaa;

  --canvas-dot:   rgba(255, 255, 255, 0.055);
}

/* ── Light mode ──────────────────────────── */

body.light {
  --bg:           #f0ead6;
  --panel:        #e8e2ca;
  --panel-mid:    #e0dabb;
  --border:       #c4bc9c;
  --border-mid:   #b0a880;

  --accent:       #7a5828;
  --accent-dim:   rgba(122, 88, 40, 0.10);
  --accent-mid:   rgba(122, 88, 40, 0.22);

  --text:         #1c1a13;
  --text-dim:     #5c5440;
  --text-muted:   #9a9078;

  --danger:       rgba(130, 40, 40, 0.45);
  --danger-text:  #8a3838;
  --danger-hover: rgba(130, 40, 40, 0.12);

  --shape-stroke: #706858;
  --shape-fill:   rgba(0, 0, 0, 0.02);
  --point-color:  #706858;

  --canvas-dot:   rgba(0, 0, 0, 0.065);
}

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

body {
  font-family: 'Courier Prime', 'Courier New', monospace;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
  transition: background 0.25s ease, color 0.25s ease;
}

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

/* ── Sidebar shell ──────────────────────── */

.sidebar {
  width: 268px;
  min-width: 268px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border-mid) transparent;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-mid); }

/* ── Header ─────────────────────────────── */

header {
  padding: 1.5rem 1.375rem 1.25rem;
  position: relative;
  flex-shrink: 0;
  transition: background 0.25s ease;
}

.header-rule {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent) 0%, transparent 70%);
}

header h1 {
  font-family: 'Cinzel', serif;
  font-size: 1.3125rem;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--text);
  line-height: 1;
  margin-bottom: 0.3rem;
}

header p {
  font-size: 0.5625rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-family: 'Courier Prime', monospace;
}

.theme-toggle {
  position: absolute;
  top: 1.25rem;
  right: 1.125rem;
  padding: 0.3rem;
  width: 28px;
  height: 28px;
  border-color: var(--border-mid);
  color: var(--text-dim);
}

.kofi-btn {
  display: inline-block;
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 999;
  background: #00d9ff;
  color: #1a1a2e;
  font-size: 14px;
  font-weight: 700;
  font-family: 'Courier New', monospace;
  letter-spacing: normal;
  padding: 8px 16px;
  border-radius: 4px;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.3s ease;
}

.kofi-btn:hover {
  background: #00b8d4;
  transform: translateY(-2px);
}

.page-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  padding: 8px;
  font-size: 13px;
  color: #888;
  z-index: 999;
  pointer-events: none;
}

.page-footer a {
  color: #aaa;
  pointer-events: all;
}

/* ── Panel sections ──────────────────────── */

.panel-section {
  padding: 1rem 1.375rem;
  border-top: 1px solid var(--border);
}

.section-label {
  font-family: 'Cinzel', serif;
  font-size: 0.5rem;
  font-weight: 600;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.875rem;
}

/* ── Controls ────────────────────────────── */

.control-group {
  margin-bottom: 0.875rem;
}

.control-group:last-child { margin-bottom: 0; }

.control-group label {
  display: block;
  font-size: 0.5625rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
}

.slider-wrapper {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

/* Range track */
input[type="range"] {
  flex-grow: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 1px;
  background: var(--border-mid);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 10px;
  height: 10px;
  background: var(--accent);
  border: none;
  border-radius: 0;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease;
}

input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.4); }
input[type="range"]:focus::-webkit-slider-thumb { background: #d4a45c; }

input[type="range"]::-moz-range-thumb {
  width: 10px;
  height: 10px;
  background: var(--accent);
  border: none;
  border-radius: 0;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  background: linear-gradient(90deg, var(--accent) 0%, var(--border-mid) 0%);
}

.value-display {
  font-size: 0.625rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
  color: var(--accent);
  min-width: 2.5rem;
  text-align: right;
}

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

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.4375rem 0.625rem;
  border: 1px solid var(--border-mid);
  background: transparent;
  color: var(--text-dim);
  border-radius: 0;
  font-family: 'Courier Prime', monospace;
  font-size: 0.5625rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
  white-space: nowrap;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--text);
  background: var(--accent-dim);
}

button:active:not(:disabled) { background: var(--accent-mid); }

button:disabled {
  opacity: 0.2;
  cursor: not-allowed;
}

button.danger {
  border-color: var(--danger);
  color: var(--danger-text);
}

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

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b0b09;
  font-weight: 700;
}

button.primary:hover {
  background: #d4a45a;
  border-color: #d4a45a;
}

button.full-width { width: 100%; }

button.active {
  background: var(--accent-mid);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Toggle group ────────────────────────── */

.toggle-group {
  display: flex;
}

.toggle-group button {
  flex: 1;
  border-right-width: 0;
}

.toggle-group button:last-child { border-right-width: 1px; }

/* ── Shape grid ──────────────────────────── */

.shape-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}

.shape-grid button {
  border-right-width: 0;
  border-bottom-width: 0;
}

.shape-grid button:nth-child(even) { border-right-width: 1px; }
.shape-grid button:nth-last-child(-n+2):nth-child(odd),
.shape-grid button:last-child { border-bottom-width: 1px; }

.shape-grid button:last-child:nth-child(odd) { grid-column: span 2; border-right-width: 1px; }

/* ── Actions ─────────────────────────────── */

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}

.actions button {
  border-right-width: 0;
  border-bottom-width: 0;
}

.actions button:nth-child(even)          { border-right-width: 1px; }
.actions button:nth-last-child(-n+2):not(.primary) { border-bottom-width: 1px; }
.actions button.primary                  { grid-column: span 2; border-right-width: 1px; border-bottom-width: 1px; }

/* ── Sidebar footer / reference ─────────── */

.sidebar-footer {
  margin-top: auto;
  padding: 1rem 1.375rem 1.375rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.key-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.5rem;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  line-height: 1.6;
}

.key {
  display: inline-block;
  color: var(--text-dim);
  min-width: 5.5rem;
  font-weight: 700;
}

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

.canvas-container {
  flex-grow: 1;
  position: relative;
  background-color: var(--bg);
  background-image:
    radial-gradient(circle, var(--canvas-dot) 1px, transparent 1px);
  background-size: 28px 28px;
  cursor: crosshair;
}

#canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ── SVG element styles ──────────────────── */

.bg-ring {
  fill: var(--shape-fill);
  stroke: rgba(136, 136, 136, 0.25);
  stroke-width: 1;
  pointer-events: none;
}

.main-path {
  fill: var(--shape-fill);
  stroke: var(--shape-stroke);
  stroke-width: 2;
  stroke-linejoin: miter;
  stroke-linecap: square;
}

.incomplete-path {
  stroke-dasharray: 7 3;
  fill: none;
}

.point {
  fill: var(--bg);
  stroke: var(--point-color);
  stroke-width: 1.5;
  cursor: grab;
  transition: r 0.1s ease;
}

.point:hover { fill: var(--point-color); }
.point:active { cursor: grabbing; }

.point.selected {
  stroke: var(--accent);
  fill: var(--accent-dim);
  stroke-width: 1.5;
}

.sharp-node {
  stroke: #888;
}

.handle {
  fill: var(--accent);
  stroke: var(--bg);
  stroke-width: 1;
  cursor: grab;
  transition: r 0.1s ease;
}

.handle:active { cursor: grabbing; }

.handle-line {
  stroke: var(--accent);
  stroke-width: 1;
  stroke-dasharray: 2 3;
  pointer-events: none;
  opacity: 0.45;
}

/* ── Center origin marker ────────────────── */

.center-marker {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
  pointer-events: none;
  opacity: 0.7;
}

.center-hit {
  fill: transparent;
  stroke: none;
  cursor: move;
  pointer-events: all;
}

/* ── Confirmation 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;
  backdrop-filter: blur(2px);
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--panel);
  border: 1px solid var(--border-mid);
  min-width: 280px;
  max-width: 360px;
}

.modal-header {
  padding: 0.875rem 1.125rem 0.625rem;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-family: 'Cinzel', serif;
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.modal-message {
  padding: 1rem 1.125rem;
  font-size: 0.625rem;
  letter-spacing: 0.08em;
  color: var(--text);
  line-height: 1.7;
}

.modal-actions {
  display: flex;
  border-top: 1px solid var(--border);
}

.modal-actions button {
  flex: 1;
  border: none;
  border-right: 1px solid var(--border);
  padding: 0.625rem;
  font-size: 0.5625rem;
}

.modal-actions button:last-child { border-right: none; }
