/* dark is the default; light comes from the OS or the theme button */
:root {
  --base: #0c0d0f;
  --ink: #f2f1ed;
  --text: rgba(242, 241, 237, 0.56);
  --faint: rgba(242, 241, 237, 0.42);
  --glass: rgba(255, 255, 255, 0.05);
  --glass-tint: rgba(12, 13, 15, 0.34);
  --glass-rim: rgba(255, 255, 255, 0.34);
  --glass-pill: rgba(255, 255, 255, 0.11);
  --glass-glint: rgba(255, 255, 255, 0.14);
  --glass-shadow: rgba(0, 0, 0, 0.55);
  --track: rgba(242, 241, 237, 0.16);
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --sans: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "DM Mono", ui-monospace, Menlo, Consolas, monospace;
  --display: "Newsreader", Georgia, serif;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --base: #f2f1ed; --ink: #111111;
    --text: rgba(17, 17, 17, 0.62); --faint: rgba(17, 17, 17, 0.48);
    --glass: rgba(255, 255, 255, 0.3); --glass-tint: rgba(242, 241, 237, 0.42);
    --glass-rim: rgba(255, 255, 255, 0.9); --glass-pill: rgba(255, 255, 255, 0.55);
    --glass-glint: rgba(255, 255, 255, 0.6); --glass-shadow: rgba(20, 40, 35, 0.25);
    --track: rgba(17, 17, 17, 0.16);
  }
}
:root[data-theme="light"] {
  --base: #f2f1ed; --ink: #111111;
  --text: rgba(17, 17, 17, 0.62); --faint: rgba(17, 17, 17, 0.48);
  --glass: rgba(255, 255, 255, 0.3); --glass-tint: rgba(242, 241, 237, 0.42);
  --glass-rim: rgba(255, 255, 255, 0.9); --glass-pill: rgba(255, 255, 255, 0.55);
  --glass-glint: rgba(255, 255, 255, 0.6); --glass-shadow: rgba(20, 40, 35, 0.25);
  --track: rgba(17, 17, 17, 0.16);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  background: #0f6654;
  color: var(--text);
  font: 13px/1.35 var(--sans);
  letter-spacing: .005em;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
button { font: inherit; color: inherit; }

/* ---- shared glass: tint, blur, rim light and soft shadow ---- */
.glass {
  position: fixed;
  background: linear-gradient(var(--glass), var(--glass)), var(--glass-tint);
  -webkit-backdrop-filter: blur(18px) saturate(1.7);
  backdrop-filter: blur(18px) saturate(1.7);
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.12),
    inset 0 -8px 16px -12px rgba(255, 255, 255, 0.18),
    0 18px 40px -18px var(--glass-shadow),
    0 2px 6px -2px var(--glass-shadow);
  isolation: isolate;
}
.glass::before {
  content: "";
  position: absolute; inset: 0;
  padding: 1px;
  border-radius: inherit;
  background: linear-gradient(155deg, var(--glass-rim), transparent 32%, transparent 68%, color-mix(in srgb, var(--glass-rim) 55%, transparent));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  pointer-events: none;
}
/* soft light that follows the cursor across the glass */
.glint {
  position: absolute; inset: 0;
  border-radius: inherit;
  background: radial-gradient(140px 90px at var(--mx, 50%) var(--my, 0%), var(--glass-glint), transparent 70%);
  opacity: 0;
  transition: opacity .5s ease;
  pointer-events: none;
  z-index: -1;
}
.glass:hover > .glint { opacity: 1; }

/* ---- corner labels ---- */
.brand {
  position: fixed; left: clamp(16px, 3vw, 32px); top: clamp(16px, 3vw, 28px);
  color: #f2f1ed; font: italic 26px/1 var(--display); letter-spacing: -.01em;
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.25);
  pointer-events: none;
  animation: fade 1.2s ease .2s both;
}
.brand span { margin-left: .45ch; opacity: .75; font: 500 11px/1 var(--sans); letter-spacing: .12em; text-transform: uppercase; vertical-align: 5px; font-style: normal; }
.stats {
  position: fixed; left: clamp(16px, 3vw, 32px); bottom: clamp(16px, 3vw, 28px);
  color: rgba(242, 241, 237, 0.8); font: 11px/1.3 var(--mono);
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.3);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.stats[hidden] { display: none; }

/* ---- settings panel ---- */
.panel {
  right: clamp(12px, 2vw, 24px); top: clamp(12px, 2vw, 24px);
  width: 320px;
  max-height: calc(100svh - 120px);
  border-radius: 22px;
  padding: 6px;
  display: flex; flex-direction: column;
  transition: opacity .3s ease, transform .5s var(--ease-out), visibility 0s;
  animation: rise 1s var(--ease-out) .3s both;
}
.panel.hidden {
  opacity: 0; transform: translateX(16px) scale(.98); visibility: hidden;
  transition: opacity .25s ease, transform .4s var(--ease-out), visibility 0s .4s;
}

.tabs {
  position: relative;
  display: flex; gap: 2px;
  padding: 0;
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; z-index: 1;
  flex: 1 1 auto;
  height: 32px; padding: 0 7px;
  border: 0; border-radius: 999px;
  background: none;
  color: var(--faint);
  font-size: 12px; font-weight: 500;
  cursor: pointer; outline: none;
  transition: color .3s ease;
}
.tab:hover, .tab:focus-visible { color: var(--text); }
.tab[aria-selected="true"] { color: var(--ink); }
.tab:focus-visible { box-shadow: inset 0 0 0 1px var(--faint); }
/* the lens that slides between tabs */
.lens {
  position: absolute; top: 0; bottom: 0; left: 0; width: 0;
  border-radius: 999px;
  background: var(--glass-pill);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  transition: left .5s var(--ease-out), width .5s var(--ease-out);
  pointer-events: none;
}

.pages { overflow-y: auto; padding: 4px 10px 8px; scrollbar-width: thin; scrollbar-color: var(--track) transparent; }
.page { display: none; }
.page.active { display: block; animation: page-in .45s var(--ease-out) both; }
@keyframes page-in { from { opacity: 0; translate: 0 4px; } to { opacity: 1; translate: 0 0; } }

.group-title {
  margin: 14px 0 4px;
  color: var(--faint); font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
}
.group-title:first-child { margin-top: 8px; }

/* slider row */
.row { display: block; padding: 7px 0 3px; }
.row-head { display: flex; justify-content: space-between; gap: 8px; }
.row-head output { color: var(--ink); font: 11.5px/1.35 var(--mono); }
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  display: block; width: 100%; height: 20px;
  background: transparent; cursor: pointer;
  --p: 50%;
}
input[type="range"]:focus { outline: none; }
input[type="range"]::-webkit-slider-runnable-track {
  height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, var(--ink) var(--p), var(--track) var(--p));
}
input[type="range"]::-moz-range-track { height: 2px; border-radius: 2px; background: var(--track); }
input[type="range"]::-moz-range-progress { height: 2px; border-radius: 2px; background: var(--ink); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; margin-top: -6px; border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 0 4px var(--glass-pill), 0 2px 6px var(--glass-shadow);
  transition: scale .3s var(--ease-out);
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border: 0; border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 0 4px var(--glass-pill), 0 2px 6px var(--glass-shadow);
}
input[type="range"]:active::-webkit-slider-thumb { scale: 1.2; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--glass-pill), 0 0 0 5px var(--ink); }

/* color row */
.swatches { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 6px 0 4px; }
.swatch {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 8px;
  border-radius: 12px;
  background: var(--glass-pill);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  cursor: pointer;
  transition: background-color .25s ease;
}
.swatch:hover { background: color-mix(in srgb, var(--glass-pill) 70%, var(--ink) 8%); }
.swatch:focus-within { box-shadow: inset 0 0 0 1px var(--ink); }
.swatch input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.chip {
  width: 18px; height: 18px; flex: none; border-radius: 50%;
  background: var(--c);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35), 0 1px 4px rgba(0, 0, 0, 0.25);
}
.swatch-text { display: grid; line-height: 1.2; min-width: 0; }
.swatch-text b { color: var(--ink); font-weight: 500; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.swatch-text i { color: var(--faint); font: 11px/1.2 var(--mono); text-transform: uppercase; }

/* toggle row */
.switch {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 0; cursor: pointer;
}
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.knob {
  position: relative; width: 30px; height: 18px; border-radius: 999px;
  background: var(--track);
  transition: background-color .3s ease;
}
.knob::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--ink);
  transition: translate .4s var(--ease-out);
}
.switch input:checked + .knob { background: color-mix(in srgb, var(--ink) 45%, transparent); }
.switch input:checked + .knob::after { translate: 12px 0; }
.switch input:focus-visible + .knob { box-shadow: 0 0 0 1px var(--ink); }

/* wind direction dial */
.dial-row { display: flex; align-items: center; gap: 16px; padding: 10px 0 6px; }
.dial {
  position: relative; flex: none;
  width: 92px; height: 92px; border-radius: 50%;
  background: radial-gradient(circle, var(--glass-pill) 0 30%, transparent 31%);
  box-shadow: inset 0 0 0 1px var(--track), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  cursor: grab; touch-action: none; outline: none;
}
.dial:active { cursor: grabbing; }
.dial:focus-visible { box-shadow: inset 0 0 0 1px var(--ink); }
.dial svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.dial .ticks line { stroke: var(--faint); stroke-width: 1; }
.dial .needle { stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; fill: none; }
.dial-info { color: var(--faint); font-size: 12px; }
.dial-info output { display: block; color: var(--ink); font: italic 34px/1 var(--display); margin-bottom: 4px; }

/* small text buttons inside the panel */
.actions { display: flex; gap: 6px; margin-top: 14px; }
.chip-btn {
  flex: 1; height: 32px; border: 0; border-radius: 999px;
  background: var(--glass-pill); color: var(--text);
  font-size: 11px; cursor: pointer; outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  transition: color .25s ease, background-color .25s ease;
}
.chip-btn:hover, .chip-btn:focus-visible { color: var(--ink); }
.chip-btn:focus-visible { box-shadow: inset 0 0 0 1px var(--ink); }

/* ---- dock ---- */
.dock {
  left: 50%; bottom: clamp(14px, 3vw, 26px);
  translate: -50% 0;
  display: flex; gap: 2px;
  padding: 5px;
  border-radius: 999px;
  animation: rise 1.1s var(--ease-out) .5s both;
}
.dock-btn {
  position: relative;
  display: grid; place-items: center;
  width: 46px; height: 40px;
  border: 0; border-radius: 999px;
  background: none;
  color: color-mix(in srgb, var(--ink) 62%, transparent);
  cursor: pointer; outline: none;
  transition: color .35s ease, background-color .35s ease;
  -webkit-tap-highlight-color: transparent;
}
.dock-btn:hover, .dock-btn:focus-visible, .dock-btn[aria-expanded="true"], .dock-btn[aria-pressed="true"] {
  color: var(--ink); background: var(--glass-pill);
}
.dock-btn:focus-visible { box-shadow: inset 0 0 0 1px var(--faint); }
.dock-btn svg {
  width: 20px; height: 20px; overflow: visible;
  fill: none; stroke: currentColor; stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
  transition: scale .3s var(--ease-out), rotate .6s var(--ease-out);
}
.dock-btn:active svg { scale: .86; }
.dock-btn .dot, .dock-btn .half { fill: currentColor; stroke: none; }
.dock-btn .i-play { display: none; }
.dock-btn[aria-pressed="true"] .i-play { display: block; }
.dock-btn[aria-pressed="true"] .i-pause { display: none; }
#b-random:hover svg { rotate: 90deg; }
#b-presets:hover svg { rotate: 15deg; }

/* tooltip: small glass chip above the button, after a short pause */
.dock-btn::after {
  content: attr(data-tip);
  position: absolute; left: 50%; bottom: calc(100% + 14px);
  padding: 5px 9px; border-radius: 8px;
  background: color-mix(in srgb, var(--base) 72%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink) 12%, transparent);
  color: var(--ink); font: 500 11px/1 var(--sans); white-space: pre;
  pointer-events: none;
  opacity: 0; translate: -50% 4px;
  transition: opacity .2s ease, translate .3s var(--ease-out);
}
.dock-btn:hover::after, .dock-btn:focus-visible::after { opacity: 1; translate: -50% 0; transition-delay: .35s; }
.dock-btn[aria-expanded="true"]#b-presets::after { opacity: 0; transition-delay: 0s; }
@media (hover: none) { .dock-btn::after { display: none; } }

/* ---- presets menu, rises from the dock ---- */
.menu {
  left: 50%; bottom: calc(clamp(14px, 3vw, 26px) + 62px);
  translate: -50% 0;
  min-width: 200px; padding: 5px;
  border-radius: 18px;
  display: grid; gap: 2px;
  opacity: 0; transform: translateY(8px) scale(.94); visibility: hidden;
  transform-origin: 50% 100%;
  transition: opacity .25s ease, transform .45s var(--ease-out), visibility 0s .45s;
}
.menu.open { opacity: 1; transform: none; visibility: visible; transition: opacity .25s ease, transform .45s var(--ease-out), visibility 0s; }
.menu-item {
  display: flex; align-items: center; gap: 10px;
  height: 36px; padding: 0 12px;
  border: 0; border-radius: 13px;
  background: none; color: var(--text);
  font-size: 12px; text-align: left;
  cursor: pointer; outline: none;
  transition: background-color .25s ease, color .25s ease;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--glass-pill); color: var(--ink); }
.menu-item .dots { display: flex; margin-left: auto; }
.menu-item .dots i { width: 10px; height: 10px; border-radius: 50%; margin-left: -3px; box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--base) 50%, transparent); }
.menu.open .menu-item { animation: item-in .45s var(--ease-out) both; }
@keyframes item-in { from { opacity: 0; translate: 0 4px; } to { opacity: 1; translate: 0 0; } }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(clamp(14px, 3vw, 26px) + 66px);
  translate: -50% 0;
  padding: 7px 12px; border-radius: 10px;
  background: color-mix(in srgb, var(--base) 72%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink) 12%, transparent);
  color: var(--ink); font-size: 11px;
  opacity: 0; transform: translateY(6px);
  transition: opacity .25s ease, transform .4s var(--ease-out);
  pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ---- phones: panel becomes a sheet above the dock ---- */
@media (max-width: 640px) {
  .panel {
    left: 12px; right: 12px; top: auto; width: auto;
    bottom: calc(clamp(14px, 3vw, 26px) + 60px);
    max-height: 46svh;
  }
  .panel.hidden { transform: translateY(16px) scale(.98); }
  .dock-btn { width: 40px; }
  .stats { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---- objects tab ---- */
.lib { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 6px 0 2px; }
.lib-card {
  position: relative;
  display: grid; justify-items: center; align-content: center; gap: 4px;
  height: 78px; padding: 8px 4px 6px;
  border: 0; border-radius: 14px;
  background: var(--glass-pill); color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  font: 500 11px/1.1 var(--sans); text-align: center;
  cursor: pointer; outline: none;
  transition: background-color .25s ease, color .25s ease, box-shadow .25s ease, translate .4s var(--ease-out);
}
.lib-card img { height: 40px; width: 52px; object-fit: contain; object-position: center bottom; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.25)); }
.lib-card:hover, .lib-card:focus-within, .lib-card:focus-visible { color: var(--ink); translate: 0 -1px; }
.lib-card:focus-visible, .lib-card:focus-within { box-shadow: inset 0 0 0 1px var(--ink); }
.lib-card[aria-pressed="true"] { color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--ink); }
.lib-card.upload svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; margin: 7px 0; }
.lib-card.upload input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.hint { color: var(--faint); font-size: 11.5px; line-height: 1.4; margin: 8px 0 2px; }
.sel-box[hidden] { display: none; }
.obj-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.obj-list .hint { margin: 0; }
.obj-chip {
  width: 40px; height: 40px; padding: 5px;
  border: 0; border-radius: 12px;
  background: var(--glass-pill); color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  cursor: pointer; outline: none;
}
.obj-chip img { width: 100%; height: 100%; object-fit: contain; }
.obj-chip[aria-pressed="true"] { box-shadow: inset 0 0 0 1.5px var(--ink); }
.obj-chip:focus-visible { box-shadow: inset 0 0 0 1px var(--ink); }
.chip-btn.wide { width: 100%; flex: none; }
.chip-btn.danger:hover, .chip-btn.danger:focus-visible { color: #ff8a7a; }
:root[data-theme="light"] .chip-btn.danger:hover { color: #c0392b; }
.chip-btn[hidden] { display: none; }

/* selection ring on the ground under the chosen object */
.sel-ring {
  position: fixed; left: 0; top: 0;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.14), 0 0 18px rgba(255, 255, 255, 0.35);
  pointer-events: none;
  animation: ring-pulse 2.4s ease-in-out infinite;
}
.sel-ring[hidden] { display: none; }
@keyframes ring-pulse { 50% { box-shadow: 0 0 0 7px rgba(255, 255, 255, 0.08), 0 0 24px rgba(255, 255, 255, 0.45); } }
body.placing canvas { cursor: crosshair; }
body.dragging canvas { cursor: grabbing !important; }
.swatch.tint { margin: 6px 0 2px; }
/* white shape thumbnails turn ink-colored on the light glass */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) img.mono { filter: brightness(0.2); opacity: .72; }
}
:root[data-theme="light"] img.mono { filter: brightness(0.2); opacity: .72; }
