:root {
  --ink: #111114;
  --on-ink: #ffffff;           /* text on an --ink filled control */
  --muted: #8a8a90;
  --faint: rgba(17, 17, 20, 0.08);
  --line: rgba(17, 17, 20, 0.25);
  --bg: #ffffff;
  --dock-bg: rgba(255, 255, 255, 0.86);
  --ok: #2e6b3a;
  --error: #b3261e;
  color-scheme: light;
}

/* Background: Dark (set from the control panel) */
:root[data-theme="dark"] {
  --ink: #f2f1ee;
  --on-ink: #141416;
  --muted: #9b9aa2;
  --faint: rgba(255, 255, 255, 0.10);
  --line: rgba(255, 255, 255, 0.30);
  --bg: #000000;                /* neutral black: iOS 26 Safari keeps its bars clear, untinted */
  --dock-bg: rgba(30, 30, 34, 0.86);
  --ok: #8fd19e;
  --error: #ff8a80;
  color-scheme: dark;
}

/* iOS 26 Safari tints its glass status/URL bars from body's background-color (and from fixed
   elements touching the top/bottom edge). So: background-color lives only on <body>, is a neutral
   #fff/#000, changes instantly (no transition to sample mid-way), and nothing fixed spans the top. */

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background-color: var(--bg);
  color: var(--ink);
  font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.stage {
  position: absolute;                 /* not fixed: see the iOS Safari note above */
  inset: 0;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.stage-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  opacity: 0;
  transition: opacity 0.6s ease;
  cursor: grab;
}

.stage[data-ready] .stage-canvas { opacity: 1; }
.stage-canvas:active { cursor: grabbing; }

.stage-fallback {
  position: absolute;
  top: 45%;
  left: 50%;
  width: min(320px, 80vw);
  margin: 0;
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}


.dock {
  position: absolute;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 18px;
  background: var(--dock-bg);
  border: 1px solid var(--faint);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.dock-thumb {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 10px;
}
.dock-thumb {
  background: var(--bag, #ece4d3);
  box-shadow: inset 0 0 0 1px var(--faint);
  overflow: hidden;
}
.dock-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dock-divider {
  width: 1px;
  height: 28px;
  background: var(--faint);
}

.dock-tool {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}
.dock-tool:hover { background: var(--faint); }
.dock-tool:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }


#look-btn[aria-expanded="true"],
#save-btn:active,
#upload-btn[aria-expanded="true"] { background: var(--ink); color: var(--on-ink); }

.upload-title { margin: 0 0 10px; font-size: 15px; font-weight: 600; }

.upload-hint { margin: 0 0 8px; line-height: 1.6; }





.upload-drop {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  margin-bottom: 6px;
  border: 1.5px dashed var(--line);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.upload-drop:hover,
body[data-dragging] .upload-drop { background: var(--faint); border-color: var(--ink); }
.upload-drop:focus-within { outline: 2px solid var(--ink); outline-offset: 2px; }
.upload-note { margin: 0 0 10px; font-size: 12px; color: var(--muted); }
.upload-status { min-height: 1.4em; margin: 8px 0 0; font-size: 12px; }
.upload-status[data-kind="error"] { color: var(--error); }
.upload-status[data-kind="ok"] { color: var(--ok); }
.upload-panel[aria-busy="true"] .upload-drop { opacity: 0.5; pointer-events: none; }
body[data-dragging] .stage-canvas { opacity: 0.6; }


@media (max-width: 420px) {
  .dock { gap: 4px; padding: 6px; }
  .dock-tool { width: 40px; height: 40px; }
  .dock-thumb { display: none; }
  .dock-thumb + .dock-divider { display: none; }
}

.look-panel {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 300px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  margin: 0;
  padding: 14px 16px 12px;
  border-radius: 16px;
  background: var(--dock-bg);
  border: 1px solid var(--faint);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.12);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  user-select: none;
}
.look-panel[hidden] { display: none; }

/* phones / narrow windows: compact sheet above the dock, menu stays visible above it */
@media (max-width: 760px) {
  .look-panel {
    top: auto;
    right: auto;
    left: 50%;
    bottom: calc(max(24px, env(safe-area-inset-bottom)) + 76px);
    transform: translateX(-50%);
    width: calc(100vw - 32px);
    max-height: 42vh;
  }
}

.look-tabs {
  position: sticky;
  top: -14px;                         /* stays visible while the tab content scrolls */
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
  margin: -14px -16px 12px;
  padding: 10px 12px 8px;
  background: var(--dock-bg);
  border-bottom: 1px solid var(--faint);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.look-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 34px;
  padding: 0 2px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: 500 12px/1 inherit;
  font-family: inherit;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}
.look-tab:hover { color: var(--ink); background: var(--faint); }
.look-tab[aria-selected="true"] { background: var(--ink); color: var(--on-ink); }
.look-tab:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.look-tab-dot { display: none; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: 0.35; }
.look-tab[data-on] .look-tab-dot { display: inline-block; }
.look-tab[data-on="true"] .look-tab-dot { opacity: 1; background: #3fbf6a; }
.look-tabpanel[hidden] { display: none; }

.look-row--switch {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--faint);
}
.look-row--switch label { font-weight: 600; }
.look-row--switch input[role="switch"] {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  width: 40px;
  height: 24px;
  margin: 0;
  border-radius: 12px;
  background: var(--line);
  cursor: pointer;
  transition: background 0.2s ease;
}
.look-row--switch input[role="switch"]::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s ease;
}
.look-row--switch input[role="switch"]:checked { background: #3fbf6a; }
.look-row--switch input[role="switch"]:checked::after { transform: translateX(16px); }
.look-note { margin: -6px 2px 12px; font-size: 12px; color: var(--muted); }
.look-note:empty { display: none; }
.look-row--switch input[role="switch"]:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.look-panel fieldset {
  margin: 0 0 10px;
  padding: 0;
  border: 0;
}
.look-panel fieldset.is-frozen { opacity: 0.38; }
.look-panel fieldset.is-frozen input { cursor: not-allowed; }
.look-panel legend {
  padding: 0;
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.look-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: 8px;
  margin-bottom: 6px;
}
.look-row label { font-size: 13px; }
.look-row output {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--muted);
}
.look-row input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  height: 24px;
  margin: 0;
  accent-color: var(--ink);
  cursor: pointer;
}
.look-row--toggle input {
  width: 18px;
  height: 18px;
  margin: 3px 0;
  accent-color: var(--ink);
  cursor: pointer;
}

.look-row--color { grid-template-columns: 1fr; row-gap: 6px; }
.look-label { font-size: 13px; }
.look-swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.look-swatch {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 2px solid var(--bg);
  border-radius: 50%;
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--swatch) 45%, #fff), var(--swatch) 50%, color-mix(in srgb, var(--swatch) 70%, #000));
  box-shadow: 0 0 0 1px var(--faint);
  cursor: pointer;
}
.look-swatch[aria-pressed="true"],
.look-swatch--custom.is-active { box-shadow: 0 0 0 2px var(--ink); }
/* custom colour picker: a "+" chip */
.look-swatch--custom {
  -webkit-appearance: none;
  appearance: none;
  background:
    linear-gradient(var(--muted), var(--muted)) center / 12px 1.5px no-repeat,
    linear-gradient(var(--muted), var(--muted)) center / 1.5px 12px no-repeat,
    var(--bg);
  box-shadow: inset 0 0 0 1px var(--line);
}
.look-swatch--custom::-webkit-color-swatch-wrapper { padding: 0; }
.look-swatch--custom::-webkit-color-swatch { border: 0; border-radius: 50%; opacity: 0; }
.look-swatch--custom::-moz-color-swatch { border: 0; border-radius: 50%; opacity: 0; }
.look-swatch:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.look-row--choice {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--faint);
  border-radius: 10px;
}
.look-segment {
  display: grid;
  place-items: center;
  height: 32px;
  border-radius: 7px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}
.look-segment:hover { background: var(--faint); }
.look-segment:has(input:checked) { background: var(--ink); color: var(--on-ink); }
.look-segment:has(input:focus-visible) { outline: 2px solid var(--ink); outline-offset: 2px; }
.look-row--toggle input:disabled { cursor: not-allowed; opacity: 0.6; }

.look-hint { margin: 0 2px 10px; font-size: 12px; color: var(--muted); }

.look-reset {
  width: 100%;
  margin-top: 4px;
  height: 36px;
  border: 1px solid var(--faint);
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}
.look-reset:hover { background: var(--faint); }
.look-reset:focus-visible,
.look-row input:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .stage-canvas { transition: none; }
}

.upload-hint { color: var(--muted); font-size: 12px; }
.upload-example-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 4px 0 8px;
  padding: 6px;
  border: 1px solid var(--faint);
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.upload-example-btn:hover { background: var(--faint); }
.upload-example-btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.upload-example-btn img { border-radius: 8px; }
