:root {
  --bg: #06080b;
  --ink: #e9eef4;
  --muted: #8e9aa8;
  --line: rgba(255, 255, 255, 0.09);
  --line-soft: rgba(255, 255, 255, 0.055);
  --panel: rgba(11, 14, 19, 0.82);
  --panel-solid: #0b0e13;
  --accent: #57f0c4;
  --accent-ink: #04130e;
  --shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
  --radius: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto,
    "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
  touch-action: none;
}

/* ---- top bar ------------------------------------------------------------------------------ */

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 16px 20px;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

.topbar > * { pointer-events: auto; }

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  align-self: center;
  background: radial-gradient(circle at 35% 35%, #d8fff4, var(--accent) 45%, #1aa47c 100%);
  box-shadow: 0 0 0 1px rgba(87, 240, 196, 0.25), 0 0 18px rgba(87, 240, 196, 0.65);
  animation: breathe 5s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 1px rgba(87, 240, 196, 0.25), 0 0 14px rgba(87, 240, 196, 0.5); }
  50% { box-shadow: 0 0 0 1px rgba(87, 240, 196, 0.4), 0 0 26px rgba(87, 240, 196, 0.8); }
}

.brand-name {
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0.17em;
  text-transform: uppercase;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(14, 18, 24, 0.55);
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
  letter-spacing: 0.02em;
  padding: 9px 15px;
  cursor: pointer;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: background 0.18s, border-color 0.18s, color 0.18s, transform 0.1s;
}

.btn:hover {
  background: rgba(22, 28, 36, 0.8);
  border-color: rgba(87, 240, 196, 0.42);
}

.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
  font-weight: 620;
}

.btn-primary:hover {
  background: #7cf7d5;
  border-color: transparent;
}

.btn:focus-visible,
.icon-btn:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 2px solid rgba(87, 240, 196, 0.75);
  outline-offset: 3px;
}

/* ---- panel -------------------------------------------------------------------------------- */

.panel {
  position: fixed;
  top: 76px;
  right: 16px;
  bottom: 16px;
  z-index: 30;
  width: min(384px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px) saturate(1.25);
  -webkit-backdrop-filter: blur(22px) saturate(1.25);
  opacity: 0;
  pointer-events: none;
  transform: translateX(calc(100% + 32px));
  transition: transform 0.38s cubic-bezier(0.22, 0.8, 0.24, 1), opacity 0.3s ease;
}

body.panel-open .panel {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 12px;
}

.panel-head h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.panel-head p {
  margin: 5px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.icon-btn {
  flex: none;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.18s, border-color 0.18s, background 0.18s;
}

.icon-btn:hover {
  color: var(--ink);
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.04);
}

.icon-btn svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
}

.panel-scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 14px 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
}

.panel-scroll::-webkit-scrollbar { width: 8px; }
.panel-scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.panel-foot {
  display: flex;
  gap: 8px;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--line-soft);
}

.panel-foot .btn { padding: 9px 13px; }
.panel-foot #btn-share { flex: 1; }

/* ---- sections and controls ---------------------------------------------------------------- */

.section { border-top: 1px solid var(--line-soft); }
.section:first-child { border-top: 0; }

.section summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 4px;
  list-style: none;
  cursor: pointer;
  user-select: none;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #b6c1cd;
  transition: color 0.18s;
}

.section summary::-webkit-details-marker { display: none; }
.section summary:hover { color: var(--ink); }

.section summary svg {
  width: 11px;
  height: 8px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.6;
  stroke-linecap: round;
  transition: transform 0.22s ease;
  margin-right: 3px;
}

.section[open] summary svg { transform: rotate(180deg); }

.section-body {
  display: flex;
  flex-direction: column;
  gap: 15px;
  padding: 2px 4px 16px;
}

.control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.control.hidden { display: none; }

.control label {
  font-size: 12.5px;
  line-height: 1.35;
  color: #c6d0da;
  cursor: pointer;
}

.control-range { display: block; }

.row-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.row-head .val {
  font-size: 11.5px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.control select {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  font-size: 12px;
  color: var(--ink);
  background-color: rgba(255, 255, 255, 0.045);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238e9aa8' stroke-width='1.4' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 30px 8px 10px;
  max-width: 54%;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}

.control select:hover { border-color: rgba(255, 255, 255, 0.2); }
.control select option { background: #0d1117; color: var(--ink); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  margin: 9px 0 0;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 3px;
  background: linear-gradient(to right,
    var(--accent) 0 var(--p, 50%),
    rgba(255, 255, 255, 0.13) var(--p, 50%) 100%);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  margin-top: -5px;
  border: 0;
  border-radius: 50%;
  background: #f2fffb;
  box-shadow: 0 0 0 3px rgba(87, 240, 196, 0.16), 0 0 14px rgba(87, 240, 196, 0.45);
  transition: box-shadow 0.15s, transform 0.15s;
}

input[type="range"]:hover::-webkit-slider-thumb {
  transform: scale(1.08);
  box-shadow: 0 0 0 4px rgba(87, 240, 196, 0.22), 0 0 18px rgba(87, 240, 196, 0.6);
}

input[type="range"]::-moz-range-track {
  height: 3px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.13);
}

input[type="range"]::-moz-range-progress {
  height: 3px;
  border-radius: 3px;
  background: var(--accent);
}

input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border: 0;
  border-radius: 50%;
  background: #f2fffb;
  box-shadow: 0 0 0 3px rgba(87, 240, 196, 0.16), 0 0 14px rgba(87, 240, 196, 0.45);
}

.switch {
  position: relative;
  flex: none;
  display: inline-flex;
  width: 38px;
  height: 22px;
}

.switch input {
  position: absolute;
  inset: 0;
  z-index: 1;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch .track {
  position: absolute;
  inset: 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  transition: background 0.22s, border-color 0.22s;
}

.switch .track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #cfd8e2;
  transition: transform 0.22s, background 0.22s, box-shadow 0.22s;
}

.switch input:checked + .track {
  background: rgba(87, 240, 196, 0.28);
  border-color: rgba(87, 240, 196, 0.4);
}

.switch input:checked + .track::after {
  transform: translateX(16px);
  background: var(--accent);
  box-shadow: 0 0 12px rgba(87, 240, 196, 0.6);
}

input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 36px;
  height: 25px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: none;
  cursor: pointer;
}

input[type="color"]::-webkit-color-swatch-wrapper { padding: 3px; }
input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 5px; }
input[type="color"]::-moz-color-swatch { border: 0; border-radius: 5px; }

/* ---- hint, toast, loader, error ----------------------------------------------------------- */

.hint {
  position: fixed;
  left: 20px;
  bottom: 16px;
  z-index: 10;
  font-size: 11px;
  color: rgba(200, 211, 222, 0.5);
  letter-spacing: 0.03em;
  transition: opacity 0.4s;
}

.hint kbd {
  font: inherit;
  font-size: 10px;
  color: #9aa7b5;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
}

.hint i { font-style: normal; opacity: 0.35; margin: 0 4px; }
body.panel-open .hint { opacity: 0; }
body.idle .topbar { opacity: 0.07; }
body.idle .hint { opacity: 0; }

body.ui-hidden .topbar,
body.ui-hidden .panel,
body.ui-hidden .hint {
  opacity: 0 !important;
  pointer-events: none !important;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 50;
  transform: translate(-50%, 14px);
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(12, 16, 21, 0.9);
  color: var(--ink);
  font-size: 12.5px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: opacity 0.25s, transform 0.25s;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

.loader {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  background: radial-gradient(120% 120% at 50% 40%, #0b1016, #04060a 70%);
  transition: opacity 0.6s, visibility 0.6s;
}

.loader:not(.show) { opacity: 0; visibility: hidden; }

.loader p {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.spinner {
  width: 34px;
  height: 34px;
  border: 2px solid rgba(87, 240, 196, 0.16);
  border-top-color: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 30px rgba(87, 240, 196, 0.2);
  animation: spin 1s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: none;
  place-items: center;
  padding: 24px;
  background: rgba(4, 6, 10, 0.92);
}

.error.show { display: grid; }

.error-card {
  width: min(440px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel-solid);
  box-shadow: var(--shadow);
}

.error-card h2 { margin: 0 0 10px; font-size: 18px; }
.error-card p { margin: 0 0 10px; font-size: 13.5px; line-height: 1.55; color: #c3ccd6; }
.error-card .muted { margin: 0; font-size: 12px; color: var(--muted); }

/* ---- small screens ------------------------------------------------------------------------ */

@media (max-width: 759px) {
  .topbar { padding: 12px 14px; gap: 10px; }
  .brand-sub { display: none; }
  .actions { gap: 6px; }
  .btn { padding: 8px 12px; font-size: 12px; }
  #btn-shuffle { display: none; }

  .panel {
    top: auto;
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    max-height: min(72vh, 580px);
    border-radius: 18px;
    transform: translateY(calc(100% + 24px));
  }

  body.panel-open .panel { transform: none; }

  .hint { display: none; }
  .toast { bottom: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .brand-mark, .spinner { animation: none; }
  .panel, .toast, .loader { transition: none; }
}
