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

:root {
  --bg: #0f0f0f;
  --surface: #1c1c1c;
  --text: #e8e4df;
  --text-muted: #8a8480;
  --accent: #c8a96a;
  --gap: 8px;
  --radius: 3px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* ── Header ── */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 2rem;
  border-bottom: 1px solid #1f1f1f;
}

.site-name {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text);
}

.site-nav {
  display: flex;
  gap: 2rem;
}

.site-nav a {
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  transition: color 0.2s;
}

.site-nav a:hover { color: var(--text); }

/* ── Footer ── */
footer {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  border-top: 1px solid #1f1f1f;
}

footer a {
  color: var(--accent);
  transition: opacity 0.2s;
}

footer a:hover { opacity: 0.8; }

/* ══════════════════════════════════════
   Tool Shared Styles
   ══════════════════════════════════════ */

/* ── Tool layout ── */
body.tool-page { overflow: hidden; }

.tool-app {
  display: grid;
  grid-template-rows: 1fr auto;
  height: calc(100vh - 53px);
}

.tool-main {
  display: grid;
  grid-template-columns: 300px 1fr;
  overflow: hidden;
}

/* ── Sidebar ── */
.tool-sidebar {
  background: var(--surface);
  border-right: 1px solid #1f1f1f;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.tool-sidebar::-webkit-scrollbar { width: 6px; }
.tool-sidebar::-webkit-scrollbar-track { background: transparent; }
.tool-sidebar::-webkit-scrollbar-thumb { background: #2a2a2a; border-radius: 3px; }
.tool-sidebar::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Section labels ── */
.section-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* ── Control groups ── */
.control-group {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.control {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.control-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.control label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}

.control .value-display {
  font-size: 0.78rem;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  min-width: 28px;
  text-align: right;
}

/* ── Range inputs ── */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: #2a2a2a;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  cursor: pointer;
  transition: transform 0.15s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  cursor: pointer;
}

/* ── Toggle switches ── */
.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.toggle-row label {
  font-size: 0.82rem;
  font-weight: 600;
}

.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  cursor: pointer;
}

.toggle input { display: none; }

.toggle .track {
  position: absolute;
  inset: 0;
  background: #2a2a2a;
  border-radius: 11px;
  transition: background 0.2s;
}

.toggle input:checked + .track {
  background: var(--accent);
}

.toggle .knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: var(--text);
  border-radius: 50%;
  transition: transform 0.2s;
  pointer-events: none;
}

.toggle input:checked ~ .knob {
  transform: translateX(18px);
}

/* ── Buttons ── */
.btn {
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
}

.btn-primary:hover { opacity: 0.85; }

.btn-secondary {
  background: #2a2a2a;
  color: var(--text);
  border: 1px solid #333;
}

.btn-secondary:hover { background: #333; }

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

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

.btn-group .btn { flex: 1; }

/* ── Upload zone ── */
.upload-zone {
  border: 2px dashed #2a2a2a;
  border-radius: 6px;
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: transparent;
}

.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(200, 168, 106, 0.04);
}

.upload-zone .icon {
  font-size: 1.6rem;
  margin-bottom: 6px;
  opacity: 0.6;
}

.upload-zone p {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.upload-zone p strong {
  color: var(--accent);
}

#fileInput { display: none; }

/* ── Color mode selector ── */
.color-mode-group {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 3px;
}

.color-mode-btn {
  flex: 1;
  padding: 6px 8px;
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 600;
  border: none;
  border-radius: 3px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.color-mode-btn.active {
  background: var(--accent);
  color: var(--bg);
}

.color-mode-btn:hover:not(.active) {
  color: var(--text);
}

/* ── Color picker row ── */
.color-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.color-row label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}

input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 32px;
  height: 24px;
  border: 1px solid #333;
  border-radius: 3px;
  background: none;
  cursor: pointer;
  padding: 1px;
}

input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 2px; }

/* ── Divider ── */
.tool-divider {
  height: 1px;
  background: #1f1f1f;
}

/* ── Canvas area ── */
.canvas-area {
  background: #141414;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.canvas-container {
  position: relative;
  max-width: 95%;
  max-height: 95%;
  display: flex;
}

.canvas-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 1;
  min-width: 0;
}

.canvas-wrapper canvas {
  max-width: 100%;
  max-height: calc(100vh - 100px);
  object-fit: contain;
  border-radius: var(--radius);
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  color: var(--text-muted);
}

.empty-state .easel {
  font-size: 3.5rem;
  margin-bottom: 12px;
  opacity: 0.3;
}

.empty-state p {
  font-size: 1rem;
  font-style: italic;
}

/* ── Bottom toolbar ── */
.tool-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--surface);
  border-top: 1px solid #1f1f1f;
  min-height: 40px;
}

.view-toggle {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 2px;
}

.view-btn {
  padding: 5px 10px;
  font-family: var(--font);
  font-size: 0.72rem;
  font-weight: 600;
  border: none;
  border-radius: 3px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.view-btn.active {
  background: #2a2a2a;
  color: var(--text);
}

.view-btn:hover:not(.active) {
  color: var(--text);
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .tool-main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .tool-sidebar {
    max-height: 45vh;
    border-right: none;
    border-bottom: 1px solid #1f1f1f;
  }
}

@media (max-width: 640px) {
  .site-header { padding: 1rem 1.25rem; }
}
