:root {
  color-scheme: dark;
  --blue-0: #030b2a;
  --blue-1: #07184f;
  --blue-2: #0c2a8a;
  --ink: #ecf4ff;
  --muted: #a8bce1;
  --line: rgb(188 220 255 / 20%);
  --line-strong: rgb(188 220 255 / 48%);
  --panel: rgb(5 17 57 / 96%);
  --focus: #f5fbff;
  --fog-opacity: .15;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  color: var(--ink);
  background: linear-gradient(180deg,
    #0b137b var(--scene-top, 0px),
    #0d21a9 var(--scene-middle, 50dvh),
    #1046dc var(--scene-bottom, 100dvh));
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
  background: rgb(255 255 255 / 4%);
  cursor: pointer;
}

button:hover { background: rgb(255 255 255 / 11%); }

.sky-fog {
  position: fixed;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  opacity: var(--fog-opacity);
  background:
    radial-gradient(ellipse 85% 28% at 16% 20%, rgb(236 248 255 / 62%), transparent 80%),
    radial-gradient(ellipse 82% 32% at 91% 66%, rgb(212 232 255 / 52%), transparent 78%),
    radial-gradient(ellipse 100% 38% at 42% 103%, rgb(226 240 255 / 60%), transparent 76%),
    linear-gradient(155deg, rgb(207 229 255 / 26%), rgb(239 249 255 / 12%) 48%, rgb(192 219 255 / 22%));
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.entry-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Discreet controls stay outside the composition and do not affect its size. */
.corner-control {
  position: fixed;
  z-index: 21;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border-color: transparent;
  color: rgb(226 239 255 / 62%);
  background: rgb(8 21 83 / 12%);
  font-size: 21px;
  line-height: 1;
  transition: color 250ms ease, background 250ms ease;
}
.corner-control:hover,
.corner-control:focus-visible { color: #f0f7ff; background: rgb(8 21 83 / 38%); }
#music-toggle {
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
}
#music-toggle[aria-pressed="true"] { color: #eef6ff; }
.music-note {
  display: inline-block;
  transform-origin: 50% 50%;
  animation: music-note-rotate 8s linear infinite;
  animation-play-state: paused;
}
#music-toggle[aria-pressed="true"] .music-note { animation-play-state: running; }
@keyframes music-note-rotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
#settings-toggle {
  right: max(8px, env(safe-area-inset-right));
  bottom: max(8px, env(safe-area-inset-bottom));
}
#settings-toggle.is-active { background: rgb(8 21 83 / 55%); color: #eef6ff; }
.panel-controls { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .75rem; }
.panel-controls button { font-size: .75rem; }

.stage-region {
  position: relative;
  flex: 1 0 auto;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 0;
}

#art-wrapper {
  position: relative;
  width: min(100vw, 75dvh);
  height: min(100dvh, 133.333333vw);
  min-height: 0;
  overflow: visible;
  border-radius: 0;
  isolation: isolate;
}

#art {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  overflow: visible;
  border-radius: inherit;
}

#art canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: inherit;
}

#moon-links {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

.moon-link {
  --moon-diameter: 0px;
  --moon-opacity: 1;
  --title-opacity: 0;
  --scene-scale: 1;
  position: absolute;
  display: block;
  pointer-events: auto;
  transform: translate(-50%, -50%);
  border: 0;
  border-radius: 50%;
  padding: 0;
  color: var(--ink);
  background: transparent;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.moon-link[hidden] { display: none; }
.moon-link:focus-visible { outline: none; }

.moon-link-label {
  position: absolute;
  top: 50%;
  left: var(--label-left);
  width: max-content;
  max-width: var(--label-width);
  display: flex;
  align-items: flex-start;
  gap: max(7px, calc(9px * var(--scene-scale)));
  padding: 8px 0;
  opacity: var(--title-opacity);
  transform: translate(calc((1 - var(--title-opacity)) * -7px), -50%);
  white-space: nowrap;
  text-align: left;
}

.moon-link-number {
  margin-top: max(5px, calc(5px * var(--scene-scale)));
  color: rgb(184 206 255 / 42%);
  font-family: Georgia, serif;
  font-size: max(9px, calc(9px * var(--scene-scale)));
  font-style: italic;
  font-weight: 400;
  letter-spacing: 0;
}

.moon-link-copy { display: grid; gap: max(4px, calc(7px * var(--scene-scale))); }
.moon-link-title {
  color: rgb(232 241 255 / 86%);
  font-family: 'Ma Shan Zheng', 'LXGW WenKai', serif;
  font-size: max(19px, calc(27px * var(--scene-scale)));
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: .09em;
  transition: color 350ms ease;
}
.moon-link-title.is-latin {
  font-family: 'LXGW WenKai', serif;
  font-size: max(17px, calc(23px * var(--scene-scale)));
  font-weight: 500;
  letter-spacing: .015em;
}
.moon-link-subtitle {
  color: rgb(183 208 255 / 58%);
  font-family: 'LXGW WenKai', serif;
  font-size: max(11px, calc(13px * var(--scene-scale)));
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: .22em;
}
.moon-link:is(:hover, :focus-visible, .is-active) .moon-link-title { color: #f5f9ff; }
.moon-link:focus-visible .moon-link-label {
  /* Keep the text focus indicator visible even during the entrance delay. */
  opacity: 1;
  transform: translate(0, -50%);
}
.moon-link:focus-visible .moon-link-title { text-decoration: underline; text-underline-offset: 5px; }

#panel {
  position: fixed;
  z-index: 20;
  bottom: calc(max(8px, env(safe-area-inset-bottom)) + 52px);
  right: max(8px, env(safe-area-inset-right));
  width: min(360px, calc(100vw - 2rem));
  max-height: calc(100dvh - 5rem - env(safe-area-inset-bottom));
  overflow: auto;
  padding: 1rem;
  border: 1px solid rgb(188 220 255 / 28%);
  border-radius: 1.2rem;
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 1.5rem 4rem rgb(0 0 0 / 48%);
  backdrop-filter: blur(18px);
}

#panel[hidden] { display: none; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.55rem 0.75rem;
}

.toolbar button { font-size: 0.75rem; }

.toolbar label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.75rem;
}

.hint {
  margin: 0.7rem 0 0;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.6;
}

.parameters {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.65rem;
  margin-top: 0.7rem;
  padding-top: 0.7rem;
  border-top: 1px solid rgb(188 220 255 / 12%);
}

.parameters label {
  display: grid;
  grid-template-columns: 6.1rem minmax(2.5rem, 1fr) 3rem;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
  color: #e1edff;
  font-size: 0.7rem;
}

.parameters .range-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.parameters .range-row > label {
  grid-template-columns: 6.1rem minmax(2.5rem, 1fr) 3rem;
}

.parameters .range-row > button { white-space: nowrap; }

.parameters input { width: 100%; min-width: 0; accent-color: #cde5ff; }

.parameters input[type="color"] {
  height: 1.8rem;
  padding: 0.1rem;
  border: 1px solid var(--line-strong);
  border-radius: 0.4rem;
  background: #14245a;
  cursor: pointer;
}

.parameters output {
  min-width: 0;
  overflow: hidden;
  color: #bdd3f3;
  font-size: 0.65rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.range-button { padding: 0.28rem 0.5rem; font-size: 0.66rem; }

details { margin-top: 0.7rem; border-top: 1px solid rgb(188 220 255 / 14%); }

summary {
  padding: 0.65rem 0 0.1rem;
  color: #dbeaff;
  cursor: pointer;
  font-size: 0.75rem;
}

details .parameters { margin-top: 0; border-top: 0; }

select {
  width: 100%;
  min-width: 0;
  padding: 0.3rem;
  border: 1px solid var(--line-strong);
  border-radius: 0.4rem;
  color: inherit;
  background: #14245a;
}

#range-editor {
  width: min(420px, calc(100vw - 2rem));
  padding: 0;
  border: 1px solid rgb(188 220 255 / 46%);
  border-radius: 1rem;
  color: var(--ink);
  background: #07143f;
  box-shadow: 0 1.5rem 4rem rgb(0 0 0 / 68%);
}

#range-editor::backdrop {
  background: rgb(1 5 20 / 78%);
  backdrop-filter: blur(4px);
}

#range-editor-form {
  display: grid;
  gap: 0.5rem;
  padding: 1.2rem;
}

#range-editor-title { margin: 0; font-size: 1.1rem; line-height: 1.3; }

#range-editor-hint {
  margin: 0 0 0.3rem;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.5;
}

#range-editor-form label { margin-top: 0.25rem; font-size: 0.75rem; }

#range-editor-form input[type="number"] {
  width: 100%;
  min-width: 0;
  padding: 0.5rem 0.6rem;
  border: 1px solid rgb(209 228 255 / 64%);
  border-radius: 0.45rem;
  color: #fff;
  background: #14245a;
  font-variant-numeric: tabular-nums;
}

#range-editor-error {
  min-height: 1.5em;
  margin: 0.1rem 0;
  color: #ffb8b8;
  font-size: 0.75rem;
}

#range-editor-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.35rem;
}

#range-editor-actions button[type="submit"] {
  color: #07143f;
  background: #d2e7ff;
  border-color: #d2e7ff;
}

@media (max-width: 640px) {
  #panel {
    width: min(360px, calc(100vw - 1rem));
    padding: 0.8rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after { transition-duration: 0.01ms !important; }
  .music-note { animation-play-state: paused !important; }
}
