:root {
  --bg: #0d0e11;
  --surface: #15171c;
  --surface-2: #1b1e24;
  --border: #2a2e36;
  --border-soft: #22262d;
  --text: #e9e7e2;
  --text-muted: #8b8f98;
  --accent: #ff5a1f;
  --accent-soft: rgba(255, 90, 31, 0.14);
  --radius: 12px;
  --radius-sm: 8px;
  --font-display: 'Clash Display', 'Satoshi', sans-serif;
  --font-body: 'Satoshi', 'Helvetica Neue', sans-serif;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

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

html { -webkit-text-size-adjust: none; text-size-adjust: none; }

body {
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  overflow: hidden;
}

#stage { position: relative; min-height: 0; }
#viewport { position: absolute; inset: 0; z-index: 0; }
#viewport canvas { display: block; }
#stage > *:not(#viewport) { position: absolute; z-index: 1; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
img { display: block; max-width: 100%; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- app layout ---------- */
#app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  pointer-events: none;
}
#app > * { pointer-events: auto; }

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  background: rgba(13, 14, 17, 0.72);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-soft);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.1;
}
.brand p {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.2;
  letter-spacing: 0.04em;
}

.top-actions { display: flex; gap: 8px; }

main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 360px;
  min-height: 0;
}

#stage { position: relative; }

#viewport-hint {
  position: absolute;
  left: 20px;
  bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}

#view-chips {
  position: absolute;
  top: 16px;
  left: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  padding: 6px 13px;
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0.03em;
  color: var(--text);
  background: rgba(21, 23, 28, 0.82);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: border-color 160ms ease, color 160ms ease, background 160ms ease;
}
.chip:hover { border-color: #3a4049; }
.chip.active {
  color: #0e0f12;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
}

#zone-flash {
  position: absolute;
  top: 16px;
  right: 20px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  background: rgba(21, 23, 28, 0.85);
  border: 1px solid var(--border);
  border-radius: 999px;
  pointer-events: none;
}

/* ---------- panel ---------- */
#panel {
  min-height: 0;
  overflow-y: auto;
  background: rgba(13, 14, 17, 0.82);
  backdrop-filter: blur(14px);
  border-left: 1px solid var(--border-soft);
}
.panel-inner {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 16px 28px;
}
.panel-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

#zone-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
}
#zone-tabs button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 10px 4px 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: 6px;
  transition: background 160ms ease, color 160ms ease;
}
#zone-tabs button:hover { color: var(--text); }
#zone-tabs button[aria-selected='true'] {
  color: var(--accent);
  background: var(--accent-soft);
}
.zone-ic { display: flex; }

.card {
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
}
.card-head { margin-bottom: 12px; }
.card-label {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}
.card-label b { color: var(--accent); font-weight: 700; }

/* upload */
.upload-row {
  display: flex;
  gap: 12px;
  align-items: stretch;
}
.thumb {
  flex: 0 0 96px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 160ms ease;
}
.thumb:hover { border-color: var(--accent); }
.thumb-empty {
  font-size: 11.5px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.45;
}
.thumb img { width: 100%; height: 100%; object-fit: contain; }
.upload-btns {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  justify-content: center;
}

/* buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  font-size: 13.5px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}
.btn.primary {
  background: var(--accent);
  color: #14090b;
  font-weight: 700;
}
.btn.primary:hover { background: #ff6d38; }
.btn.ghost {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}
.btn.ghost:hover { border-color: #3a4049; background: #20242b; }
.btn.ghost[aria-pressed='true'] {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}
.btn.ghost.danger:hover { border-color: #e5484d; color: #ff6b6b; }
.btn.small { padding: 6px 10px; font-size: 12.5px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* controls */
.ctl { margin-bottom: 14px; }
.ctl:last-child { margin-bottom: 2px; }
.ctl-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 500;
}
.ctl-val {
  font-size: 12px;
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums lining-nums;
}

input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: var(--border);
  cursor: pointer;
}
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text);
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border);
  transition: background 160ms ease;
}
input[type='range']::-webkit-slider-thumb:hover { background: var(--accent); }
input[type='range']::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--surface);
}

/* segmented control */
.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
}
.seg button {
  padding: 6px 4px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: 5px;
  transition: background 160ms ease, color 160ms ease;
}
.seg button:hover { color: var(--text); }
.seg button.active {
  color: var(--text);
  background: #262b33;
  font-weight: 700;
}

/* paint swatches */
.paint-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--border);
  transition: border-color 160ms ease, transform 160ms ease;
}
.swatch:hover { border-color: var(--text); transform: scale(1.08); }
.swatch.custom {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: conic-gradient(#ff5a1f, #e8b419, #2ecc71, #3aa0ff, #b06bff, #ff5a1f);
  overflow: hidden;
}
.swatch.custom input {
  position: absolute;
  inset: -4px;
  width: 40px;
  height: 40px;
  opacity: 0;
  cursor: pointer;
}

.preset-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.hint {
  margin-top: 10px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
}

/* scrollbar */
#panel::-webkit-scrollbar { width: 8px; }
#panel::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* ---------- responsive ---------- */
@media (max-width: 920px) {
  body { overflow: auto; }
  #app { height: auto; min-height: 100dvh; }
  main {
    grid-template-columns: 1fr;
    grid-template-rows: 62vh auto;
  }
  #panel {
    border-left: none;
    border-top: 1px solid var(--border-soft);
    overflow: visible;
    backdrop-filter: none;
    background: var(--bg);
  }
  .panel-inner { padding-bottom: 16px; }
  #view-chips { top: 12px; left: 12px; }
  .chip { padding: 5px 11px; font-size: 12px; }
  #viewport-hint { left: 12px; bottom: 10px; }
  #topbar { padding: 10px 14px; }
  #btnScreenshot span { display: none; }
}
