/* ButtonZilla: one small light-glass dock floating under the stage; the button is the loud part.
   The glass blurs whatever backdrop is behind it, so the UI takes on the scene's colour; on a dark
   backdrop (html.is-dark, set by app.js) it turns more opaque so dark ink stays readable. */
:root {
  --page: #d6d0f3;
  --ink: #1d1736;
  --text: #3b3556;
  --muted: #7a7491;
  --ring: #1d1736;
  --glass: linear-gradient(180deg, rgba(255, 255, 255, 0.6) 0%, rgba(255, 255, 255, 0.38) 100%);
  --glass-solid: linear-gradient(180deg, rgba(255, 255, 255, 0.82) 0%, rgba(255, 255, 255, 0.66) 100%);
  --blur: blur(22px) saturate(180%);
  --edge: inset 0 1px 0 rgba(255, 255, 255, 0.9), inset 0 0 0 1px rgba(255, 255, 255, 0.45);
  --lift: 0 18px 44px rgba(24, 16, 60, 0.16), 0 3px 10px rgba(24, 16, 60, 0.08);
  --raised-bg: rgba(255, 255, 255, 0.58);
  --raised: 0 1px 2px rgba(24, 16, 60, 0.12), 0 4px 10px rgba(24, 16, 60, 0.06), inset 0 1px 0 #fff;
  --pressed: inset 0 1px 3px rgba(24, 16, 60, 0.2);
  --well: rgba(29, 23, 54, 0.06);
  --inset: inset 0 1px 2px rgba(24, 16, 60, 0.1);
  --hover: rgba(29, 23, 54, 0.06);
  --dark-bg: linear-gradient(180deg, #342b5c 0%, #1d1736 100%);
  --font: "Nunito Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}
.is-dark {
  --glass: linear-gradient(180deg, rgba(255, 255, 255, 0.82) 0%, rgba(255, 255, 255, 0.66) 100%);
  --glass-solid: linear-gradient(180deg, rgba(255, 255, 255, 0.9) 0%, rgba(255, 255, 255, 0.8) 100%);
  --lift: 0 18px 44px rgba(0, 0, 0, 0.4), 0 3px 10px rgba(0, 0, 0, 0.2);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  :root, .is-dark { --glass: var(--glass-solid); }
}
@media (prefers-reduced-transparency: reduce) {
  :root, .is-dark { --glass: var(--glass-solid); }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--page);
  color: var(--ink);
  font: 400 14px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

.app { position: relative; height: 100dvh; overflow: hidden; }

.i { display: inline-grid; place-items: center; flex: none; }
.i svg { width: 22px; height: 22px; }

/* ---------- stage ---------- */
.stage-wrap { position: absolute; inset: 0; overflow: hidden; background: var(--page); }
.stage { position: absolute; inset: 0; }
.stage:focus-visible { outline: 2px solid #6a4cf5; outline-offset: -4px; }
.fallback { display: grid; place-items: center; height: 100%; margin: 0; padding: 24px; color: #6d6687; text-align: center; }

.brand {
  position: absolute; top: 20px; left: 24px;
  color: #1d1736;
  pointer-events: none;
}
.brand h1 { margin: 0; font: 700 21px/1 "Unbounded", var(--font); letter-spacing: -0.01em; }
.credit {
  position: absolute; top: 22px; right: 24px;
  color: #6d6687; text-decoration: none; font-size: 13px; font-weight: 600;
}
.credit:hover { color: #1d1736; text-decoration: underline; text-underline-offset: 3px; }

/* the hint sits just above the dock (--dock-space is set by app.js) */
.hint {
  position: absolute; left: 50%; bottom: calc(var(--dock-space, 84px) + 10px); margin: 0;
  font-size: 12.5px; font-weight: 600; color: #6d6687; text-align: center; white-space: nowrap;
  transform: translateX(-50%);
  pointer-events: none;
}
.is-dark .brand { color: #f4f1ff; }
.is-dark .credit, .is-dark .hint { color: rgba(244, 241, 255, 0.62); }
.is-dark .credit:hover { color: #f4f1ff; }
.is-dark .credit:focus-visible { outline-color: #f4f1ff; }

/* ---------- dock: one floating row under the button ---------- */
.dock {
  position: absolute; left: 50%; bottom: 20px; z-index: 2;
  display: flex; align-items: center; gap: 6px;
  max-width: calc(100% - 32px); padding: 5px;
  transform: translateX(-50%);
  border-radius: 23px;
  color: var(--text);
}
/* the glass lives on a layer under the controls: a backdrop-filter on the dock itself would make
   it a backdrop root, and the popups inside it could then only blur the dock, not the scene */
.dock::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  border-radius: inherit;
  background: var(--glass);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  box-shadow: var(--lift), var(--edge);
}
.sep { flex: none; width: 1px; height: 20px; margin: 0 2px; background: rgba(29, 23, 54, 0.12); }

.round {
  display: grid; place-items: center; flex: none;
  width: 36px; height: 36px; border: 0; border-radius: 50%; cursor: pointer;
  background: var(--raised-bg); box-shadow: var(--raised); color: var(--text);
  transition: box-shadow 0.15s, color 0.15s, background 0.15s;
}
.round:hover { background: rgba(255, 255, 255, 0.85); color: var(--ink); }
.round:active { background: var(--hover); box-shadow: var(--pressed); }

/* the main actions: a dark ink pill, the one solid thing on the glass */
.pill, .primary {
  border: 0; cursor: pointer;
  background: var(--dark-bg); color: #fff;
  box-shadow: 0 6px 14px rgba(29, 23, 54, 0.28), 0 1px 3px rgba(29, 23, 54, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.16);
  font-weight: 800;
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
}
.pill:hover, .primary:hover { background: linear-gradient(180deg, #41376f 0%, #272047 100%); }
.pill:active, .primary:active { transform: translateY(1px); box-shadow: 0 2px 6px rgba(29, 23, 54, 0.3), inset 0 2px 5px rgba(0, 0, 0, 0.3); }
.pill { height: 46px; padding: 0 22px; border-radius: 23px; font-size: 14.5px; }
.primary {
  display: flex; align-items: center; justify-content: center; gap: 8px; flex: none;
  height: 36px; padding: 0 15px 0 12px; border-radius: 18px;
  font: 800 14px/1 var(--font); letter-spacing: 0.01em;
}
.primary .i svg { width: 18px; height: 18px; stroke-width: 1.9; }
.primary:focus-visible { outline-offset: 3px; }

/* presets: a glass bead each, the name pops up above on hover. The chosen one
   sinks into a pressed well, like an open Tт or ⋯; the gap is wider than the
   well's 5px rim, so a well never touches the next bead */
.presets { display: flex; gap: 10px; padding: 0 4px 0 8px; }
.preset {
  --bead: inset 0 1px 1px rgba(255, 255, 255, 0.7), inset 0 -3px 5px rgba(0, 0, 0, 0.2), 0 1px 3px rgba(24, 16, 60, 0.2);
  position: relative; flex: none; width: 28px; height: 28px; padding: 0;
  border: 0; border-radius: 50%; cursor: pointer;
  background: radial-gradient(120% 120% at 30% 22%, #fff 0 6%, var(--a) 36%, var(--b) 100%);
  box-shadow: var(--bead);
  transition: box-shadow 0.15s, transform 0.15s;
}
.preset:hover { transform: translateY(-1px); box-shadow: var(--bead), 0 0 0 2.5px rgba(255, 255, 255, 0.9), 0 0 0 4px rgba(29, 23, 54, 0.22); }
/* the bead loses its lift and takes a shadow from the rim above; the well is a
   pseudo-element behind it, so the bead must not transform (that would make it
   a stacking context and lift the well over its own colour) */
.preset[aria-pressed="true"],
.preset[aria-pressed="true"]:hover {
  transform: none;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.45), inset 0 4px 6px rgba(24, 16, 60, 0.38), inset 0 -2px 4px rgba(0, 0, 0, 0.12);
}
/* the well is tinted with the bead's own colour and cut deeper than an open
   Tт or ⋯, so a chosen look never reads as one more round button */
.preset[aria-pressed="true"]::before {
  content: ""; position: absolute; inset: -5px; z-index: -1;
  border-radius: 50%;
  background: color-mix(in srgb, var(--b) 30%, rgba(29, 23, 54, 0.1));
  box-shadow: inset 0 2px 5px rgba(24, 16, 60, 0.4), inset 0 -1px 1px rgba(255, 255, 255, 0.75);
}
.preset:focus-visible { outline: none; box-shadow: 0 0 0 2.5px #fff, 0 0 0 4px var(--ring); }
.preset::after {
  content: attr(data-name);
  position: absolute; left: 50%; bottom: calc(100% + 12px);
  padding: 6px 10px; border-radius: 10px;
  background: var(--glass-solid); color: var(--ink); white-space: nowrap;
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  font-size: 12.5px; font-weight: 700; line-height: 1;
  box-shadow: var(--lift), var(--edge);
  transform: translate(-50%, 4px); opacity: 0; pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
}
.preset:hover::after, .preset:focus-visible::after { opacity: 1; transform: translate(-50%, 0); }

/* ---------- popups: rise from their dock button ---------- */
.menu-wrap { position: relative; flex: none; }
.round[aria-expanded="true"] { background: var(--hover); box-shadow: var(--pressed); color: var(--ink); }
.round .i svg { width: 20px; height: 20px; }
.menu {
  position: absolute; bottom: calc(100% + 11px); left: -5px; z-index: 3;
  display: grid; gap: 2px; min-width: 212px; padding: 6px;
  border-radius: 20px;
  background: var(--glass-solid);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  box-shadow: var(--lift), var(--edge);
  transform-origin: 23px calc(100% + 11px);
  animation: menu-in 0.16s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.menu[hidden] { display: none; }
@keyframes menu-in { from { opacity: 0; transform: scale(0.92) translateY(4px); } }
.menu [role="menuitem"] {
  display: flex; align-items: center; gap: 12px;
  height: 44px; padding: 0 14px 0 12px; border: 0; border-radius: 14px;
  background: none; color: var(--text); cursor: pointer; text-align: left;
  font-size: 14px; font-weight: 600;
  transition: color 0.15s, background 0.15s;
}
.menu [role="menuitem"]:hover, .menu [role="menuitem"]:focus-visible { background: var(--hover); color: var(--ink); outline: none; }
.menu .i svg { width: 20px; height: 20px; }
.menu hr { width: calc(100% - 20px); margin: 4px auto; border: 0; border-top: 1px solid rgba(29, 23, 54, 0.1); }

/* label popup: text on top, icons below */
.pop { width: 252px; gap: 8px; padding: 8px; }
.field {
  width: 100%; height: 40px; padding: 0 14px;
  border: 0; border-radius: 14px;
  background: rgba(255, 255, 255, 0.75); box-shadow: var(--inset), 0 0 0 1px rgba(29, 23, 54, 0.06); color: var(--ink);
  font-size: 14px; font-weight: 700;
}
.field:focus { outline: 1.5px solid var(--ring); outline-offset: 0; }
.segments {
  display: flex; justify-content: space-between; padding: 3px;
  border-radius: 14px; background: var(--well); box-shadow: var(--inset);
}
.seg {
  display: grid; place-items: center; height: 34px;
  border: 0; border-radius: 11px; background: none; color: var(--muted); cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.seg svg { width: 17px; height: 17px; }
.seg:hover { color: var(--ink); }
.seg[aria-checked="true"] { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(24, 16, 60, 0.18); }
.seg:focus-visible { outline-offset: 0; }
.icons { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
.sides .seg { flex: 1; font-size: 13px; font-weight: 700; }
.seg:disabled { opacity: 0.35; cursor: default; }
.seg:disabled:hover { color: var(--muted); }

/* ---------- toast and dialog ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--dock-space, 84px) + 40px); z-index: 10;
  padding: 11px 18px; border-radius: 99px;
  background: var(--glass-solid); color: var(--ink); font-weight: 700;
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  box-shadow: var(--lift), var(--edge);
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

.dialog {
  width: min(640px, calc(100vw - 32px)); padding: 22px;
  border: 0; border-radius: 26px; color: var(--ink);
  background: var(--glass-solid);
  -webkit-backdrop-filter: blur(30px) saturate(180%); backdrop-filter: blur(30px) saturate(180%);
  box-shadow: 0 30px 70px rgba(24, 16, 60, 0.3), var(--edge);
}
.dialog::backdrop { background: rgba(24, 16, 60, 0.28); }
.dialog h2 { margin: 0; font-size: 18px; font-weight: 800; }
.dialog-note { margin: 6px 0 14px; color: var(--muted); }
.dialog textarea {
  width: 100%; height: 260px; padding: 14px; resize: vertical;
  border: 0; border-radius: 16px; background: var(--well); box-shadow: var(--inset); color: var(--text);
  font: 12px/1.55 ui-monospace, "SF Mono", Menlo, monospace;
}
.dialog-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 16px; }
.ghost {
  height: 46px; padding: 0 18px; border: 0; border-radius: 23px;
  background: none; color: var(--muted); font-weight: 700; cursor: pointer;
}
.ghost:hover { color: var(--ink); background: var(--hover); }

/* ---------- small screens: two rows, looks on top, label, ⋯ and Shuffle below ---------- */
@media (max-width: 820px) {
  .brand { top: 14px; left: 16px; }
  .credit { top: 16px; right: 16px; }
  .hint { display: none; }
  .dock {
    left: 8px; right: 8px; bottom: 8px; max-width: none;
    display: grid; grid-template-columns: auto auto minmax(0, 1fr);
    grid-template-areas: "presets presets presets" "label more shuffle";
    transform: none;
  }
  .dock .sep { display: none; }
  .presets { grid-area: presets; justify-content: space-between; gap: 8px; padding: 6px 6px 2px; }
  .menu-wrap { grid-area: label; }
  .more-wrap { grid-area: more; }
  .primary { grid-area: shuffle; }
  .preset::after { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
