:root {
  --bg: #040407;
  --fg: #f4efe7;
  --muted: rgba(244, 239, 231, 0.62);
  --dim: rgba(244, 239, 231, 0.2);
  --line: rgba(244, 239, 231, 0.14);
  --glass: rgba(255, 255, 255, 0.065);
  --glass-strong: rgba(255, 255, 255, 0.12);
  --border: rgba(255, 255, 255, 0.13);
  --red: #ff6545;
  --gold: #f4d56b;
  --blue: #6eb8ff;
  --green: #83efb1;
  --violet: #b89cff;
  --shadow: rgba(0, 0, 0, 0.52);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 13% 20%, rgba(255, 101, 69, 0.16), transparent 34%),
    radial-gradient(circle at 86% 70%, rgba(110, 184, 255, 0.12), transparent 38%),
    radial-gradient(circle at 50% 105%, rgba(244, 213, 107, 0.08), transparent 42%),
    var(--bg);
  color: var(--fg);
  font-family:
    "Malgun Gothic",
    "Apple SD Gothic Neo",
    "Noto Sans KR",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    sans-serif;
}

button {
  font: inherit;
}

#ambientCanvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  opacity: 0.52;
  pointer-events: none;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(circle at center, transparent 34%, rgba(0, 0, 0, 0.62)),
    linear-gradient(90deg, rgba(0, 0, 0, 0.78), transparent 28%, transparent 72%, rgba(0, 0, 0, 0.72));
}

/* Header */

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 40;
  height: 76px;
  display: grid;
  grid-template-columns: 1fr minmax(160px, 360px) 1fr;
  align-items: center;
  gap: 16px;
  padding: 15px clamp(16px, 4vw, 46px);
  pointer-events: none;
}

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

.brand span {
  display: block;
  color: var(--red);
  font-size: 0.68rem;
  font-weight: 1000;
  letter-spacing: 0.22em;
}

.brand strong {
  display: block;
  margin-top: 3px;
  color: var(--fg);
  font-size: 0.98rem;
  font-weight: 1000;
  letter-spacing: -0.04em;
}

.progress {
  text-align: center;
}

#sceneCode {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 1000;
  letter-spacing: 0.18em;
}

.progressLine {
  height: 3px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

#progressFill {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--red), var(--gold), var(--blue), var(--violet));
  transition: width 0.38s ease;
}

.soundBtn {
  justify-self: end;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 9px 14px;
  background: var(--glass);
  color: var(--fg);
  font-size: 0.7rem;
  font-weight: 1000;
  letter-spacing: 0.12em;
  cursor: pointer;
  backdrop-filter: blur(16px);
  transition:
    transform 0.18s ease,
    background 0.18s ease,
    border-color 0.18s ease;
}

.soundBtn:hover {
  transform: translateY(-2px);
  background: var(--glass-strong);
  border-color: rgba(244, 239, 231, 0.32);
}

/* Stage */

.stage {
  position: relative;
  z-index: 10;
  width: 100vw;
  height: 100vh;
  height: 100svh;
}

.artShell {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(1180px, calc(100vw - clamp(28px, 10vw, 190px)));
  height: min(660px, calc(100svh - 168px));
  min-height: 420px;
  transform: translate(-50%, -50%);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: clamp(28px, 4vw, 52px);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.105), rgba(255, 255, 255, 0.026)),
    rgba(0, 0, 0, 0.25);
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.14),
    inset 0 -1px rgba(255, 255, 255, 0.05),
    0 34px 100px rgba(0, 0, 0, 0.46);
  backdrop-filter: blur(22px);
}

.artShell::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background:
    radial-gradient(circle at center, transparent 36%, rgba(0, 0, 0, 0.34)),
    linear-gradient(transparent 0 96%, rgba(255, 255, 255, 0.055) 96% 100%);
  background-size: auto, 100% 31px;
  opacity: 0.58;
}

.artShell::after {
  content: "";
  position: absolute;
  left: 12%;
  right: 12%;
  bottom: 0;
  z-index: 4;
  height: 1px;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(244, 213, 107, 0.7), transparent);
  box-shadow:
    0 0 34px rgba(244, 213, 107, 0.38),
    0 -120px 160px rgba(244, 213, 107, 0.045);
}

#artCanvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
}

.sceneMeta {
  position: absolute;
  left: clamp(18px, 4vw, 42px);
  top: clamp(18px, 4vw, 38px);
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.sceneMeta span {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 10px;
  background: rgba(0, 0, 0, 0.28);
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 1000;
  letter-spacing: 0.08em;
  backdrop-filter: blur(14px);
}

.sceneMeta strong {
  color: var(--fg);
  font-size: clamp(1rem, 1.8vw, 1.4rem);
  font-weight: 1000;
  letter-spacing: -0.055em;
  text-shadow: 0 16px 42px var(--shadow);
  white-space: nowrap;
}

.caption {
  position: absolute;
  right: clamp(18px, 4vw, 42px);
  bottom: clamp(18px, 4vw, 42px);
  z-index: 8;
  max-width: min(390px, 58%);
  margin: 0;
  color: rgba(244, 239, 231, 0.56);
  font-size: clamp(0.78rem, 1.2vw, 0.98rem);
  font-weight: 900;
  line-height: 1.56;
  letter-spacing: -0.03em;
  text-align: right;
  word-break: keep-all;
  pointer-events: none;
}

.controlDock {
  position: absolute;
  left: 50%;
  bottom: 22px;
  z-index: 12;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  width: min(92%, 620px);
  transform: translateX(-50%);
}

.controlDock button,
.nav button {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.078);
  color: var(--fg);
  font-weight: 1000;
  cursor: pointer;
  backdrop-filter: blur(16px);
  transition:
    transform 0.18s ease,
    background 0.18s ease,
    border-color 0.18s ease,
    opacity 0.18s ease;
}

.controlDock button {
  min-height: 38px;
  padding: 8px 14px;
  font-size: 0.78rem;
}

.controlDock button:hover:not(.used) {
  transform: translateY(-3px);
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(244, 239, 231, 0.3);
}

.controlDock button.used {
  opacity: 0.42;
  text-decoration: line-through;
  cursor: default;
}

.controlDock .primary {
  min-width: 70px;
  background: rgba(244, 213, 107, 0.13);
  border-color: rgba(244, 213, 107, 0.22);
}

.controlDock .memoryCore {
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  color: var(--gold);
  font-size: 1.25rem;
  background: rgba(244, 213, 107, 0.14);
  box-shadow: 0 0 34px rgba(244, 213, 107, 0.14);
}

/* Nav */

.nav {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 38;
  display: flex;
  gap: 76px;
  transform: translateX(-50%);
  pointer-events: none;
}

.nav button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  font-size: 1rem;
  pointer-events: auto;
}

.nav button:hover:not(:disabled) {
  transform: translateY(-3px);
  background: rgba(255, 255, 255, 0.14);
}

.nav button:disabled {
  opacity: 0.24;
  cursor: default;
}

/* Mobile */

@media (max-width: 760px) {
  .topbar {
    height: 70px;
    grid-template-columns: 1fr auto;
    padding: 13px 15px;
  }

  .progress {
    display: none;
  }

  .brand span {
    font-size: 0.62rem;
  }

  .brand strong {
    font-size: 0.9rem;
  }

  .soundBtn {
    padding: 8px 12px;
    font-size: 0.66rem;
  }

  .artShell {
    width: calc(100vw - 28px);
    height: calc(100svh - 156px);
    min-height: 0;
    border-radius: 24px;
  }

  .sceneMeta {
    left: 16px;
    top: 16px;
    gap: 7px;
  }

  .sceneMeta span {
    min-height: 24px;
    padding: 4px 8px;
    font-size: 0.64rem;
  }

  .sceneMeta strong {
    font-size: 1rem;
  }

  .caption {
    right: 16px;
    bottom: 74px;
    max-width: 74%;
    font-size: 0.68rem;
  }

  .controlDock {
    bottom: 18px;
    gap: 6px;
    width: calc(100% - 26px);
  }

  .controlDock button {
    min-height: 36px;
    padding: 7px 11px;
    font-size: 0.72rem;
  }

  .controlDock .memoryCore {
    width: 40px;
    min-width: 40px;
    height: 40px;
  }

  .nav {
    bottom: 20px;
    gap: 62px;
  }

  .nav button {
    width: 40px;
    height: 40px;
  }
}

@media (max-height: 680px) and (min-width: 761px) {
  .topbar {
    height: 68px;
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .artShell {
    height: calc(100svh - 144px);
    min-height: 350px;
  }

  .caption {
    display: none;
  }

  .controlDock {
    bottom: 16px;
  }
}

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