:root {
  color-scheme: dark;
  --bg: #000;
  --panel: rgba(14, 12, 20, 0.84);
  --panel-solid: #0e0c14;
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.22);
  --text: #eeeaf4;
  --muted: #a39cb2;
  --accent: #ffb84a;
  --accent-2: #ff5a7a;
  --control: rgba(255, 255, 255, 0.06);
  --control-hover: rgba(255, 255, 255, 0.11);
  --radius: 10px;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--ui);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

#stage { position: fixed; inset: 0; overflow: hidden; touch-action: manipulation; }
#screen { position: absolute; left: 0; top: 0; display: block; image-rendering: auto; }
#screen.crisp { image-rendering: crisp-edges; image-rendering: pixelated; }
#lvh { position: fixed; top: 0; left: 0; width: 0; height: 100vh; height: 100lvh; visibility: hidden; pointer-events: none; }

body.idle, body.idle #stage { cursor: none; }

/* The module's start-up line: bold system font, white on black. */
#status {
  position: absolute;
  color: #fff;
  font-family: "Microsoft Sans Serif", "MS Sans Serif", Tahoma, Geneva, Arial, sans-serif;
  font-weight: bold;
  line-height: 1.15;
  white-space: pre;
  pointer-events: none;
  user-select: none;
  visibility: hidden;
}
#status.show { visibility: visible; }

.sr {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }

button, select, input { font: inherit; color: inherit; }

/* ------------------------------------------------------------ toolbar */

#toolbar {
  position: fixed;
  right: calc(16px + var(--safe-r));
  bottom: calc(16px + var(--safe-b));
  display: flex;
  gap: 2px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(12, 10, 18, 0.62);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: opacity 0.6s ease, transform 0.6s ease;
  z-index: 3;
}
#toolbar button {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 0; border-radius: 999px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  opacity: 0.82;
}
#toolbar button:hover { background: var(--control-hover); opacity: 1; }
#toolbar button[aria-pressed="true"], #toolbar button[aria-expanded="true"] { color: var(--accent); opacity: 1; }
#toolbar button .off { display: none; }
#btn-music[aria-pressed="false"] .on { display: none; }
#btn-music[aria-pressed="false"] .off { display: block; }
body.fullscreen #btn-fullscreen .on { display: none; }
body.fullscreen #btn-fullscreen .off { display: block; }
body.idle #toolbar, body.idle #hint { opacity: 0; transform: translateY(8px); pointer-events: none; }
body.no-fullscreen #btn-fullscreen { display: none; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#hint {
  position: fixed;
  left: 50%;
  bottom: calc(22px + var(--safe-b));
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(12, 10, 18, 0.62);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.6s ease, transform 0.6s ease;
  z-index: 2;
}
#hint svg { width: 16px; height: 16px; color: var(--accent); }
body.idle #hint { transform: translate(-50%, 8px); }

#toast {
  position: fixed;
  top: 16px; left: 50%;
  transform: translate(-50%, -8px);
  max-width: calc(100vw - 32px);
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(12, 10, 18, 0.78);
  border: 1px solid var(--line);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 4;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#hud {
  position: fixed;
  left: 12px; bottom: calc(12px + var(--safe-b));
  margin: 0;
  max-width: calc(100vw - 24px);
  padding: 6px 8px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font: 12px/1.35 var(--mono);
  white-space: pre-wrap;
  pointer-events: none;
  z-index: 2;
}

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

#panel {
  position: fixed;
  top: 12px; right: 12px; bottom: 12px;
  width: 340px;
  display: flex; flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  z-index: 5;
  animation: panel-in 0.22s ease-out;
}
#panel[hidden] { display: none; }
@keyframes panel-in { from { opacity: 0; transform: translateX(12px); } }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  #panel { background: var(--panel-solid); }
}

.panel-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--line);
  position: relative;
}
.panel-head::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: -1px; height: 2px;
  background: var(--palette-gradient, linear-gradient(90deg, #ffe14a, #ff8a3d, #ff3d6e, #b44cff));
  opacity: 0.9;
}
#panel h1 { margin: 0; font-size: 18px; font-weight: 650; letter-spacing: 0.01em; }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 13px; font-style: italic; }

button.icon {
  width: 34px; height: 34px; margin: -4px -6px 0 0;
  display: grid; place-items: center;
  border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); cursor: pointer;
}
button.icon:hover { background: var(--control-hover); color: var(--text); }

#settings { overflow-y: auto; padding: 6px 18px 18px; scrollbar-width: thin; }

section, fieldset { margin: 0; padding: 14px 0; border: 0; border-bottom: 1px solid var(--line); }
legend {
  float: left; width: 100%; padding: 0; margin-bottom: 8px;
  font-size: 11px; font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
legend + * { clear: both; }

.row { display: flex; align-items: center; gap: 10px; }
.row.spread { justify-content: space-between; }
label { color: var(--text); }
output { color: var(--accent); font-weight: 600; }
.note { margin: 6px 0 0; color: var(--muted); font-size: 12.5px; }
.note:empty { display: none; }

.field { display: grid; grid-template-columns: 76px 1fr; align-items: center; gap: 10px; margin-top: 10px; }

select {
  width: 100%;
  height: 34px;
  padding: 0 30px 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--control) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a39cb2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 8px center / 16px;
  appearance: none;
  cursor: pointer;
}
select:hover { background-color: var(--control-hover); }
select option { background: var(--panel-solid); color: var(--text); }

input[type="range"] { width: 100%; margin: 8px 0 0; accent-color: var(--accent); cursor: pointer; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; cursor: pointer; }

.choice { display: flex; align-items: center; gap: 9px; padding: 5px 0; cursor: pointer; }

#swatch {
  display: block;
  width: 100%; height: 8px;
  margin-top: 10px;
  border-radius: 4px;
  image-rendering: auto;
}
#swatch.hidden { visibility: hidden; }

.file-row { margin: 2px 0 6px 25px; min-width: 0; }
.file-name { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.volume { margin-top: 6px; }
.volume label { color: var(--muted); font-size: 12.5px; }
.volume input { margin: 0; }

#settings button:not(.icon) {
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--control);
  cursor: pointer;
  white-space: nowrap;
}
#settings button:not(.icon):hover { background: var(--control-hover); }
#settings button:disabled { opacity: 0.45; cursor: default; }
#listen.playing { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 55%, transparent); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px 0; border-bottom: 1px solid var(--line); }

details { border-bottom: 1px solid var(--line); }
summary {
  padding: 12px 0;
  cursor: pointer;
  font-size: 11px; font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
  list-style: none;
}
summary::-webkit-details-marker { display: none; }
summary::after { content: "+"; float: right; font-size: 14px; line-height: 1; }
details[open] summary::after { content: "\2212"; }
.keys { width: 100%; border-collapse: collapse; margin-bottom: 12px; font-size: 12.5px; }
.keys th { text-align: left; font-weight: 500; white-space: nowrap; padding: 3px 12px 3px 0; color: var(--text); vertical-align: top; }
.keys td { padding: 3px 0; color: var(--muted); }
.about { padding-bottom: 8px; font-size: 13px; color: var(--muted); }
.about p { margin: 0 0 10px; }
.about em { color: var(--text); }
.about a { color: var(--accent); }
.about .fine { font-size: 12px; opacity: 0.8; }

@media (max-width: 620px) {
  #panel {
    top: auto; left: 8px; right: 8px; bottom: calc(8px + var(--safe-b));
    width: auto; max-height: 72vh; max-height: 72dvh;
    animation-name: sheet-in;
  }
  @keyframes sheet-in { from { opacity: 0; transform: translateY(16px); } }
  #hud { font-size: 10.5px; }
  #hint { bottom: calc(80px + var(--safe-b)); }
  body.panel-open #toolbar { opacity: 0; pointer-events: none; }
}

@media (prefers-reduced-motion: reduce) {
  #panel, #toolbar, #hint, #toast { animation: none; transition: none; }
}

/* --------------------------------------------------------------- 404 */

body.not-found { overflow: auto; }
.not-found main { padding: 20px 15px; }
.not-found .status-line {
  margin: 0 0 18px;
  font: bold 14px/1.2 "Microsoft Sans Serif", "MS Sans Serif", Tahoma, Geneva, Arial, sans-serif;
  white-space: pre-wrap;
}
.not-found a { color: var(--accent); }
