:root {
  --bg: #0e1014;
  --panel: #161a21;
  --panel-2: #1d222b;
  --border: #2a313d;
  --text: #e6e9ef;
  --muted: #8a93a6;
  --accent: #ff5252;
  --accent-2: #6cc7ff;
  --primary: #4a7dff;
  --primary-hover: #6390ff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif;
  font-size: 13px;
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-columns: 1fr 340px;
  height: 100vh;
}

#stage {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: hidden;
  background:
    linear-gradient(45deg, #0a0c10 25%, transparent 25%),
    linear-gradient(-45deg, #0a0c10 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #0a0c10 75%),
    linear-gradient(-45deg, transparent 75%, #0a0c10 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-color: #0e1014;
}

#canvas-wrap {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  display: inline-block;
}

#image-canvas {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 48px);
  width: auto;
  height: auto;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  border-radius: 4px;
  position: relative;
  z-index: 1;
}

#freckle-canvas,
#constellation-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
#freckle-canvas { z-index: 2; }
#constellation-svg { z-index: 3; }

#empty-state {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  border: 2px dashed var(--border);
  border-radius: 8px;
  min-width: 400px;
  min-height: 300px;
  padding: 40px;
}
#empty-state.hidden { display: none; }
#empty-state p { margin: 0; }

#settings {
  background: var(--panel);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

#settings header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 5;
}
#settings h1 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.panel {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel h2 {
  margin: 0 0 4px 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.row {
  display: flex;
  gap: 8px;
}
.row > * { flex: 1; }

button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 7px 12px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
button:hover { background: #252b36; border-color: #3a4150; }
button.primary { background: var(--primary); border-color: var(--primary); color: white; }
button.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.stat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: var(--panel-2);
  border-radius: 5px;
  border: 1px solid var(--border);
}
.stat span { color: var(--muted); font-size: 11px; }
.stat strong { font-size: 16px; font-variant-numeric: tabular-nums; }

.slider { display: flex; flex-direction: column; gap: 4px; }
.slider > span {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
}
.slider em {
  font-style: normal;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  background: var(--primary);
  border-radius: 50%;
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--primary);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font-family: inherit;
  font-size: 12px;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  cursor: pointer;
}
.checkbox input { margin: 0; }

#match-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 220px;
  overflow-y: auto;
}
#match-list li {
  display: flex;
  justify-content: space-between;
  padding: 6px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 11px;
}
#match-list li .stars {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
#match-list:empty::after {
  content: "No matches yet";
  color: var(--muted);
  font-size: 11px;
  font-style: italic;
}

#status {
  padding: 10px 18px;
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
  min-height: 30px;
}
#status.busy { color: var(--accent-2); font-style: normal; }
#status.error { color: var(--accent); font-style: normal; }

/* Constellation library overlay */
#library-overlay {
  display: none;
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 9999;
  background: rgba(5, 7, 12, 0.92);
  overflow-y: auto;
  padding: 24px;
}

#library-inner {
  max-width: 1100px;
  margin: 0 auto;
}

#library-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
#library-header h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text);
}
#library-header span {
  font-size: 11px;
  color: var(--muted);
  margin-left: 10px;
}
#library-close {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
}
#library-close:hover { background: #252b36; }

#library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

#library-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.lib-cell {
  background: var(--panel);
  border: 2px solid rgba(255, 255, 255, 0.75);
  box-shadow: 0 0 8px rgba(108, 199, 255, 0.4);
  border-radius: 6px;
  padding: 8px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, opacity 0.15s;
  user-select: none;
}
.lib-cell:hover {
  border-color: #fff;
  box-shadow: 0 0 12px rgba(108, 199, 255, 0.6);
}
.lib-cell.inactive {
  border: 1px solid var(--border);
  box-shadow: none;
  opacity: 0.22;
}
.lib-cell.inactive:hover { opacity: 0.55; }
.lib-cell svg {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  background: #000;
  border-radius: 3px;
}
.lib-name {
  padding: 5px 2px 2px;
  font-size: 10px;
  text-align: center;
  color: var(--accent-2);
  font-family: inherit;
  letter-spacing: 0.03em;
}
