:root {
  --primary: #6750a4; --on-primary: #fff;
  --secondary-container: #e8def8; --on-secondary-container: #1d192b;
  --surface: #fef7ff; --surface-container: #f3edf7; --surface-high: #ece6f0;
  --on-surface: #1d1b20; --on-surface-variant: #49454f; --outline: #79747e;
  --checker: #e7e0ec;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --primary: #d0bcff; --on-primary: #381e72;
    --secondary-container: #4a4458; --on-secondary-container: #e8def8;
    --surface: #141218; --surface-container: #211f26; --surface-high: #2b2930;
    --on-surface: #e6e0e9; --on-surface-variant: #cac4d0; --outline: #938f99;
    --checker: #2b2930;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Google Sans", Roboto, "Noto Sans SC", system-ui, sans-serif;
  background: var(--surface); color: var(--on-surface);
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
button { font: inherit; cursor: pointer; border: 0; }
button:disabled { opacity: .38; cursor: default; }

.topbar { display: flex; align-items: center; gap: 8px; padding: 12px 16px; }
.topbar h1 { flex: 1; margin: 0; font-size: 22px; font-weight: 500; }
.topbar h1 span { font-size: 14px; color: var(--on-surface-variant); margin-left: 6px; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; background: transparent; display: grid; place-items: center; }
.icon-btn svg { width: 26px; height: 26px; fill: var(--on-surface); }
.icon-btn:active { background: var(--surface-high); }

main { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 0 16px 16px; }

.stage {
  border-radius: 28px; min-height: 46vh; display: grid; place-items: center; padding: 16px;
  background:
    repeating-conic-gradient(var(--checker) 0 25%, transparent 0 50%) 50% / 20px 20px,
    var(--surface-container);
  overflow: hidden;
}
.stage canvas { max-width: 100%; max-height: 56vh; display: block; border-radius: 6px; }
.stage.empty canvas { display: none; }
.stage:not(.empty) .empty-state { display: none; }
.stage.drag { outline: 3px dashed var(--primary); outline-offset: -8px; }
.empty-state { text-align: center; color: var(--on-surface-variant); display: grid; justify-items: center; gap: 10px; }
.empty-state svg { width: 56px; height: 56px; fill: var(--primary); }
.empty-state p { margin: 0; font-size: 16px; color: var(--on-surface); }
.empty-state small { max-width: 240px; }

.thumbs { display: flex; gap: 8px; overflow-x: auto; padding: 12px 2px 0; }
.thumb { position: relative; flex: none; width: 56px; height: 76px; border-radius: 12px; overflow: hidden; background: var(--surface-high); outline: 2px solid transparent; }
.thumb.active { outline-color: var(--primary); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .x { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; font-size: 13px; line-height: 20px; padding: 0; }

.panel { margin-top: 16px; display: grid; gap: 14px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row > label:first-child:not(.switch) { width: 36px; font-size: 14px; color: var(--on-surface-variant); flex: none; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; min-width: 0; }
.chips button {
  height: 32px; padding: 0 14px; border-radius: 8px; font-size: 14px;
  background: transparent; color: var(--on-surface-variant); border: 1px solid var(--outline);
}
.chips button.on { background: var(--secondary-container); color: var(--on-secondary-container); border-color: transparent; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatches button { width: 32px; height: 32px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.swatches button.on { outline: 3px solid var(--primary); outline-offset: 2px; }
input[type=color] { width: 40px; height: 32px; border: 0; padding: 0; background: none; border-radius: 8px; }
input[type=range] { flex: 1; min-width: 0; accent-color: var(--primary); }

.switches { gap: 24px; }
.switch { display: flex; white-space: nowrap; align-items: center; gap: 10px; font-size: 14px; }
.switch input { display: none; }
.switch span { flex: none; width: 52px; height: 32px; border-radius: 16px; background: var(--surface-high); border: 2px solid var(--outline); position: relative; transition: .2s; }
.switch span::after { content: ""; position: absolute; top: 6px; left: 6px; width: 16px; height: 16px; border-radius: 50%; background: var(--outline); transition: .2s; }
.switch input:checked + span { background: var(--primary); border-color: var(--primary); }
.switch input:checked + span::after { left: 24px; top: 2px; width: 24px; height: 24px; background: var(--on-primary); }

.bottombar {
  display: flex; gap: 12px; justify-content: flex-end; padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: var(--surface-container);
}
.filled-btn, .tonal-btn { height: 44px; padding: 0 22px; border-radius: 22px; font-size: 15px; font-weight: 500; }
.filled-btn { background: var(--primary); color: var(--on-primary); }
.tonal-btn { background: var(--secondary-container); color: var(--on-secondary-container); }
.bottombar .filled-btn { flex: 1; max-width: 220px; }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--on-surface); color: var(--surface); padding: 12px 18px; border-radius: 8px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: .25s; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
[hidden]{display:none!important}
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-right: -16px; padding-right: 16px; flex-basis: 0; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chips button { flex: none; white-space: nowrap; }
.color-name { font-size: 13px; color: var(--on-surface-variant); }

/* keep bottom bar clear of host badges */
.bottombar { position: relative; z-index: 10; }
