/* =====================================================================
   SCAP home — listening room (see js/music-stage.js)
   Themes: pulse / glitch / prism / mosaic / liquid / tunnel
   ===================================================================== */

.home-deck .slide--music.has-room { padding: 0; border-top: 0; }

.m-stage {
  --m-a: #29c3ff;
  --m-b: #f5c44c;
  --beat: 0;
  --level: 0;
  --mx: 0;
  --my: 0;
  --paper: #f3efe6;
  position: relative;
  height: 100vh;
  min-height: 720px;
  overflow: hidden;
  isolation: isolate;
  background: #050608;
  color: var(--paper);
}
.m-stage .mono {
  font-family: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: .16em;
  text-transform: uppercase;
}

/* ---------------- background layers ---------------- */
.m-gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; z-index: -3; }
.m-bg {
  position: absolute;
  inset: -12%;
  z-index: -4;
  background: center / cover no-repeat;
  filter: blur(60px) saturate(1.5) brightness(.42);
  transform: scale(calc(1.05 + var(--beat) * .04));
  transition: background-image .8s ease;
}
.m-stage.has-gl .m-bg { display: none; }
.m-shade {
  position: absolute;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(5, 6, 8, .1) 0%, rgba(5, 6, 8, .2) 38%, rgba(5, 6, 8, .62) 62%, rgba(5, 6, 8, .72) 100%),
    linear-gradient(0deg, rgba(5, 6, 8, .85) 0%, rgba(5, 6, 8, 0) 30%),
    linear-gradient(180deg, rgba(5, 6, 8, .55) 0%, rgba(5, 6, 8, 0) 18%);
}
.m-stage.is-switching .m-shade { animation: m-flash .65s ease-out; }
@keyframes m-flash { 0% { background-color: rgba(255, 255, 255, .14); } 100% { background-color: transparent; } }

/* giant outlined title running behind everything */
.m-ghost {
  position: absolute;
  left: 0; right: 0;
  top: 11vh;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
  opacity: .55;
}
.m-ghost-run {
  display: flex;
  width: max-content;
  align-items: center;
  gap: .4em;
  font-size: 24vh;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
  color: transparent;
  -webkit-text-stroke: 1px rgba(255, 255, 255, .16);
  animation: m-ghost 60s linear infinite;
}
.m-ghost-run i { font-style: normal; font-size: .3em; -webkit-text-stroke: 0; color: var(--m-a); opacity: .5; }
@keyframes m-ghost { to { transform: translateX(-50%); } }
.theme-glitch .m-ghost-run { animation-duration: 26s; }
.theme-liquid .m-ghost-run { font-family: "Hiragino Mincho ProN", "Songti SC", serif; font-weight: 600; }
.theme-tunnel .m-ghost-run { font-size: 34vh; }

/* ---------------- main layout ---------------- */
.m-main {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 9vw;
  height: calc(100% - 23vh);
  padding: 12vh 6vw 0 8vw;
  box-sizing: border-box;
}

/* ---------------- cover + record ---------------- */
.m-art {
  --m-radius: 18px;
  --m-cover-tf: none;
  --m-img-tf: none;
  position: relative;
  width: min(50vh, 32vw);
  aspect-ratio: 1;
}
.m-disc {
  position: absolute;
  inset: 3%;
  z-index: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle, transparent 31%, rgba(255, 255, 255, .05) 31.5%, transparent 32.5%),
    repeating-radial-gradient(circle, #0c0d10 0 2px, #16171b 2px 3px),
    #0c0d10;
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, .8), inset 0 0 0 1px rgba(255, 255, 255, .06);
  transform: translateX(0);
  transition: transform 1.1s cubic-bezier(.16, 1, .3, 1);
}
.m-disc::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(from 30deg, transparent 0 20%, rgba(255, 255, 255, .09) 25%, transparent 32% 70%, rgba(255, 255, 255, .06) 75%, transparent 80%);
}
.m-disc i {
  position: absolute;
  inset: 33%;
  border-radius: 50%;
  background: center / cover no-repeat;
  box-shadow: 0 0 0 4px #0c0d10;
  animation: m-spin 2.8s linear infinite;
  animation-play-state: paused;
}
.m-disc i::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 10%; height: 10%;
  margin: -5% 0 0 -5%;
  border-radius: 50%;
  background: #050608;
}
.m-stage.is-playing .m-disc { transform: translateX(30%); }
.m-stage.is-playing .m-disc i { animation-play-state: running; }
@keyframes m-spin { to { transform: rotate(360deg); } }

.m-cover {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  border-radius: var(--m-radius);
  cursor: pointer;
  background: #111;
  transform:
    perspective(900px)
    rotateY(calc(var(--mx) * 16deg))
    rotateX(calc(var(--my) * -12deg))
    scale(calc(1 + var(--beat) * .045))
    var(--m-cover-tf);
  box-shadow:
    0 40px 90px -25px rgba(0, 0, 0, .85),
    0 0 calc(30px + var(--beat) * 90px) -10px var(--m-a);
  transition: border-radius .8s cubic-bezier(.16, 1, .3, 1), box-shadow .3s ease, opacity .25s ease, filter .25s ease;
}
.m-cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: var(--m-img-tf);
  transition: transform .8s cubic-bezier(.16, 1, .3, 1);
}
/* glossy sheen that follows the pointer */
.m-cover::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(70% 70% at calc(50% + var(--mx) * 120%) calc(30% + var(--my) * 120%), rgba(255, 255, 255, .22), transparent 60%);
  mix-blend-mode: overlay;
}
.m-cover.is-out { opacity: 0; filter: blur(10px) brightness(1.6); }
.m-cover.is-in { animation: m-cover-in .9s cubic-bezier(.16, 1, .3, 1); }
@keyframes m-cover-in {
  0% { opacity: 0; filter: blur(14px) brightness(1.8); clip-path: inset(48% 0 48% 0); }
  45% { opacity: 1; clip-path: inset(0 0 0 0); }
  100% { filter: none; clip-path: inset(0 0 0 0); }
}

/* cover shape per theme */
.theme-pulse .m-art { --m-radius: 18px; }
.theme-glitch .m-art { --m-radius: 0px; }
.theme-glitch .m-cover { animation: m-jitter 2.4s steps(1) infinite; }
@keyframes m-jitter {
  0%, 86%, 100% { filter: none; }
  88% { filter: drop-shadow(6px 0 rgba(255, 0, 90, .8)) drop-shadow(-6px 0 rgba(0, 220, 255, .8)); }
  90% { filter: drop-shadow(-10px 0 rgba(255, 0, 90, .8)) drop-shadow(10px 0 rgba(0, 220, 255, .8)) hue-rotate(40deg); }
  92% { filter: none; }
}
.theme-prism .m-art { --m-radius: 10px; --m-cover-tf: rotate(45deg) scale(.72); --m-img-tf: rotate(-45deg) scale(1.42); }
.theme-mosaic .m-art { --m-radius: 0px; }
.theme-mosaic .m-cover { outline: 1px solid var(--m-a); outline-offset: 12px; }
.theme-liquid .m-art { --m-radius: 50%; }
.theme-tunnel .m-art { --m-radius: 6px; --m-cover-tf: rotateY(-24deg) rotateX(6deg); }

/* ---------------- info column ---------------- */
.m-info { min-width: 0; max-width: 52vw; }
.m-kicker {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0 0 2vh;
  font-size: 11px;
  color: rgba(243, 239, 230, .6);
}
.m-no { color: var(--m-a); font-weight: 700; font-size: 13px; }
.m-theme {
  margin-left: 18px;
  padding: 4px 10px;
  border: 1px solid color-mix(in srgb, var(--m-a) 60%, transparent);
  border-radius: 999px;
  color: var(--m-a);
  font-size: 10px;
}

.m-title {
  margin: 0;
  font-family: "Helvetica Neue", "PingFang SC", "Hiragino Sans", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-weight: 900;
  line-height: 1.12;
  letter-spacing: -.02em;
  color: var(--paper);
  overflow-wrap: anywhere;
}
/* per-glyph slot: padded (and pulled back) so no font ever gets shaved */
.m-title .cm {
  display: inline-block;
  vertical-align: top;
  padding: .3em .12em;
  margin: -.3em -.12em;
  overflow: hidden;
}
.m-title .c { position: relative; display: inline-block; }

/* RISE (pulse) */
.m-title.type-rise .c { transform: translate3d(0, calc(100% + .7em), 0); }
.m-title.type-rise.is-in .c { animation: m-rise 1s cubic-bezier(.16, 1, .3, 1) both; animation-delay: calc(var(--i) * 45ms); }
@keyframes m-rise { from { transform: translate3d(0, calc(100% + .7em), 0); } to { transform: none; } }

/* FLIP (prism) */
.m-title.type-flip .cm { overflow: visible; }
.m-title.type-flip .c { opacity: 0; transform-origin: 50% 85%; }
.m-title.type-flip.is-in .c { animation: m-flip 1.1s cubic-bezier(.2, .9, .25, 1.15) both; animation-delay: calc(var(--i) * 60ms); }
@keyframes m-flip {
  from { opacity: 0; transform: perspective(500px) rotateX(-100deg) translateZ(.2em); }
  30% { opacity: 1; }
  to { opacity: 1; transform: perspective(500px) rotateX(0); }
}

/* BLUR (liquid) */
.m-title.type-blur .cm { overflow: visible; }
.m-title.type-blur .c { opacity: 0; }
.m-title.type-blur.is-in .c { animation: m-blur 1.4s cubic-bezier(.16, 1, .3, 1) both; animation-delay: calc(var(--i) * 55ms); }
@keyframes m-blur {
  /* glyphs start spread out from the centre and drift together; transform only, so the line never reflows */
  from { opacity: 0; filter: blur(22px); transform: translate3d(calc((var(--i) - var(--mid, 0)) * .45em), -.15em, 0) scale(1.5); }
  to { opacity: 1; filter: blur(0); transform: none; }
}

/* SLICE (tunnel): each glyph opens from a thin horizontal slit */
.m-title.type-slice .cm { overflow: visible; }
.m-title.type-slice .c { clip-path: inset(50% 0 50% 0); }
.m-title.type-slice.is-in .c { animation: m-slice .85s cubic-bezier(.7, 0, .2, 1) both; animation-delay: calc(var(--i) * 40ms); }
@keyframes m-slice {
  0% { clip-path: inset(50% 0 50% 0); transform: scaleX(1.6); }
  55% { clip-path: inset(46% -20% 46% -20%); transform: scaleX(1.05); }
  100% { clip-path: inset(-30% -20% -30% -20%); transform: none; }
}

/* SCRAMBLE (glitch): JS swaps random glyphs in a layer over the real one */
.m-title.type-scramble .cm { overflow: visible; }
.m-title .c.hid { color: transparent; -webkit-text-stroke: 0 !important; text-shadow: none !important; }
.m-title .c .r {
  position: absolute;
  left: 0; right: 0; top: 0;
  text-align: center;
  font-weight: inherit;
  color: var(--m-a);
}
.m-title .c.hit { animation: m-hit .5s ease-out; }
@keyframes m-hit { from { color: var(--m-a); text-shadow: 0 0 20px var(--m-a); } }

/* TYPER (mosaic) */
.m-title.type-typer .cm { overflow: visible; }
.m-title .c.cur::after {
  content: "";
  position: absolute;
  right: -.12em;
  top: .08em;
  bottom: .08em;
  width: .1em;
  background: var(--m-a);
  animation: m-blink .7s steps(1) infinite;
}
@keyframes m-blink { 50% { opacity: 0; } }
.m-title.type-typer .c.hid { opacity: 0; }

/* typography per theme */
.theme-glitch .m-title {
  font-family: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, "PingFang SC", monospace;
  font-weight: 800;
  letter-spacing: -.01em;
  text-transform: uppercase;
  text-shadow:
    calc(2px + var(--beat) * 8px) 0 rgba(255, 0, 90, .75),
    calc(-2px - var(--beat) * 8px) 0 rgba(0, 220, 255, .75);
}
.theme-prism .m-title .c:not(.hid) {
  color: transparent;
  -webkit-text-stroke: 1.5px var(--m-a);
  text-shadow: 0 0 calc(18px + var(--beat) * 30px) color-mix(in srgb, var(--m-a) 70%, transparent);
}
.theme-mosaic .m-title {
  font-family: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, "PingFang SC", monospace;
  font-weight: 700;
  letter-spacing: .02em;
}
.theme-liquid .m-title {
  font-family: "Hiragino Mincho ProN", "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", serif;
  font-weight: 600;
  letter-spacing: .02em;
}
.theme-tunnel .m-title {
  font-family: "Helvetica Neue", "Arial Narrow", "PingFang SC", sans-serif;
  font-stretch: condensed;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: -.035em;
}

.m-desc {
  margin: 2.4vh 0 0;
  font-size: 14px;
  letter-spacing: .06em;
  color: rgba(243, 239, 230, .68);
}
.m-desc.is-in { animation: m-fade 1s ease .5s both; }
@keyframes m-fade { from { opacity: 0; transform: translateY(10px); } }

.m-viz { display: block; width: min(420px, 100%); height: 46px; margin: 4vh 0 2.6vh; }

/* ---------------- controls ---------------- */
.m-controls { display: flex; align-items: center; gap: 14px; }
.m-btn {
  all: unset;
  box-sizing: border-box;
  display: grid;
  place-items: center;
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .22);
  cursor: pointer;
  transition: border-color .3s ease, background .3s ease, transform .3s cubic-bezier(.16, 1, .3, 1);
}
.m-btn svg { width: 16px; height: 16px; fill: currentColor; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; }
.m-btn:hover, .m-btn:focus-visible { border-color: var(--m-a); transform: scale(1.08); }
.m-play {
  width: 64px; height: 64px;
  border: 0;
  background: var(--paper);
  color: #050608;
  box-shadow: 0 0 0 calc(var(--beat) * 14px) color-mix(in srgb, var(--m-a) 35%, transparent);
}
.m-play svg { width: 22px; height: 22px; stroke: none; }
.m-play .i-pause { display: none; }
.m-play.is-on .i-play { display: none; }
.m-play.is-on .i-pause { display: block; }
.m-play:hover, .m-play:focus-visible { background: var(--m-a); }
.m-progress {
  position: relative;
  flex: 1;
  max-width: 260px;
  height: 18px;
  margin-left: 10px;
  cursor: pointer;
}
.m-progress::before, .m-progress i {
  content: "";
  position: absolute;
  left: 0; right: 0;
  top: 50%;
  height: 2px;
  margin-top: -1px;
}
.m-progress::before { background: rgba(255, 255, 255, .18); }
.m-progress i {
  background: linear-gradient(90deg, var(--m-a), var(--m-b));
  transform-origin: left;
  transform: scaleX(0);
}
.m-time { font-size: 11px; color: rgba(243, 239, 230, .6); min-width: 9.5em; }
.m-hint { margin: 3vh 0 0; font-size: 10px; color: rgba(243, 239, 230, .35); }

/* ---------------- track rail ---------------- */
.m-rail {
  position: absolute;
  left: 0; right: 0;
  bottom: 0;
  z-index: 1;
  height: 23vh;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 6vw, #000 calc(100% - 6vw), transparent);
  mask-image: linear-gradient(90deg, transparent, #000 6vw, #000 calc(100% - 6vw), transparent);
}
.m-rail::-webkit-scrollbar { display: none; }
.m-rail-track {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  width: max-content;
  height: 100%;
  padding: 0 8vw 4.5vh;
  box-sizing: border-box;
}
.m-item {
  all: unset;
  position: relative;
  flex: none;
  width: 12.5vh;
  cursor: pointer;
  transition: transform .45s cubic-bezier(.16, 1, .3, 1), opacity .3s ease;
  opacity: .55;
}
.m-item img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  filter: saturate(.7);
  transition: filter .3s ease, box-shadow .3s ease;
}
.m-item-no {
  position: absolute;
  left: 7px; top: 6px;
  font-size: 9px;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .8);
}
.m-item-title {
  display: block;
  margin-top: 8px;
  font-size: 11px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: rgba(243, 239, 230, .75);
}
.m-item:hover, .m-item:focus-visible { opacity: 1; transform: translateY(-8px); }
.m-item:hover img, .m-item:focus-visible img { filter: none; }
.m-item.is-sel { opacity: 1; transform: translateY(-14px) scale(1.06); }
.m-item.is-sel img { filter: none; box-shadow: 0 0 0 2px var(--m-a), 0 14px 30px -10px var(--m-a); }
.m-item.playing .m-item-no::after { content: " ♪"; color: var(--m-a); }

/* the floating mini player is redundant while the room is on screen */
.music-view .music-player { opacity: 0 !important; pointer-events: none !important; }

/* ---------------- phones & tablets: stacked, no WebGL ---------------- */
@media (max-width: 1023px), (hover: none), (pointer: coarse) {
  .m-stage { height: auto; min-height: 100vh; padding-bottom: 2vh; }
  .m-main {
    grid-template-columns: 1fr;
    gap: 5vh;
    height: auto;
    padding: 14vh 7vw 4vh;
    justify-items: center;
  }
  .m-art { width: min(68vw, 340px); }
  .m-disc { display: none; }
  .m-info { max-width: 100%; width: 100%; }
  .m-ghost { top: 6vh; }
  .m-ghost-run { font-size: 16vh; }
  .m-hint { display: none; }
  .m-rail { position: relative; height: auto; }
  .m-rail-track { padding: 18px 7vw 18px; }
  .m-item { width: 92px; }
  /* progress gets its own full-width row on narrow screens */
  .m-controls { flex-wrap: wrap; row-gap: 10px; }
  .m-progress { order: 5; flex: 1 1 100%; max-width: none; margin: 4px 0 0; height: 24px; }
  .m-time { min-width: 0; margin-left: auto; }
  .m-shade { background: linear-gradient(180deg, rgba(5, 6, 8, .4), rgba(5, 6, 8, .75)); }
}

@media (prefers-reduced-motion: reduce) {
  .m-ghost-run, .m-disc i, .theme-glitch .m-cover { animation: none !important; }
  .m-title .c { animation: none !important; transform: none !important; opacity: 1 !important; clip-path: none !important; filter: none !important; }
}
