/* ===========================================================================
   ON / BEAT — selection screen (sub-agent D)

   Visual baseline: refs/04/ui-reference.png (2752 x 1536).
   All positions below are transcribed from that frame as percentages of the
   viewport; all sizes use clamp()/vmin so different landscape aspect ratios
   keep the same composition. This is a replica, not a reinterpretation:
   warm dark listening room, centred serif headline, one perfectly frontal
   square cover, two CSS-3D-tilted side covers, vinyl peeking behind the right
   edge of the centre card, arrows, dots, song info and a white pill button.

   Integration: link this file from index.html AFTER styles/main.css.
   The main agent must call SelectionScreen#show() / #hide().
   =========================================================================== */

/* ---- Fonts (OFL, shipped in assets/fonts/) -------------------------------- */
@font-face {
  font-family: 'Instrument Serif';
  src: url('../assets/fonts/InstrumentSerif-Regular.ttf') format('truetype');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Instrument Serif';
  src: url('../assets/fonts/InstrumentSerif-Italic.ttf') format('truetype');
  font-weight: 400; font-style: italic; font-display: swap;
}
@font-face {
  font-family: 'Instrument Sans';
  src: url('../assets/fonts/InstrumentSans-Regular.ttf') format('truetype');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Crimson Pro';
  src: url('../assets/fonts/CrimsonPro-Italic.ttf') format('truetype');
  font-weight: 400; font-style: italic; font-display: swap;
}

/* ---- Screen shell --------------------------------------------------------- */
.ob-selection {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow: hidden;
  background: #2a1b15;
  color: #f6eee4;
  font-family: 'Instrument Serif', Georgia, 'Times New Roman', serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
  -webkit-user-select: none;
}
.ob-selection[hidden] { display: none; }

/* ---- Background: still poster + ambient video ---------------------------- */
.ob-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: #2a1b15;
}
.ob-bg-still,
.ob-bg-video {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;          /* 2048x1143 / 1920x1080 cover any landscape */
  border: 0;
}
.ob-bg-video {
  opacity: 0;                 /* shown only once `playing` fires */
  transition: opacity 700ms ease;
  pointer-events: none;
}
.ob-bg-video.is-live { opacity: 1; }
/* The video is NEVER transformed by drag input: no dolly, no shake. */

.ob-scrim {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(180deg,
      rgba(26, 16, 12, 0.30) 0%,
      rgba(26, 16, 12, 0.04) 22%,
      rgba(26, 16, 12, 0.06) 58%,
      rgba(18, 11, 9, 0.38) 100%),
    radial-gradient(ellipse 68% 58% at 50% 44%,
      rgba(20, 12, 9, 0.20), transparent 78%);
}

/* ---- Top bar: ON / BEAT + Upload Music / Calibration / EN / 中文 ---------- */
.ob-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 2vmin;
  padding-top: max(clamp(20px, 3.6vh, 56px), env(safe-area-inset-top));
  padding-left: max(clamp(20px, 2.3vw, 64px), env(safe-area-inset-left));
  padding-right: max(clamp(20px, 2.3vw, 64px), env(safe-area-inset-right));
}
.ob-brand {
  font-family: 'Instrument Sans', 'Helvetica Neue', Arial, sans-serif;
  font-size: clamp(18px, 2.5vmin, 38px);
  font-weight: 400;
  letter-spacing: 0.24em;
  line-height: 1;
  color: #f6eee4;
  white-space: nowrap;
}
.ob-brand-slash {
  display: inline-block;
  margin: 0 0.1em;
  font-weight: 300;
  transform: scaleY(1.3);
  opacity: 0.85;
}
.ob-nav {
  display: flex;
  align-items: baseline;
  gap: clamp(10px, 2.8vmin, 42px);
  font-family: 'Instrument Serif', Georgia, serif;
  font-size: clamp(14px, 2.3vmin, 35px);
  font-weight: 400;
  letter-spacing: 0.04em;
  color: #f6eee4;
  white-space: nowrap;
}
.ob-nav-link,
.ob-locale {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  cursor: pointer;
  opacity: 0.88;
  transition: opacity 160ms ease;
}
.ob-nav-link:hover,
.ob-locale:hover { opacity: 1; }
.ob-nav button:disabled { opacity: 0.4; cursor: not-allowed; }
.ob-nav-sep {
  display: inline-block;
  width: 1px;
  height: 1.05em;
  margin: 0 0.15em;
  background: rgba(246, 238, 228, 0.5);
  transform: translateY(0.14em);
}
.ob-locale-slash { opacity: 0.55; margin: 0 -0.1em; }
.ob-locale.is-active { position: relative; opacity: 1; }
.ob-locale.is-active::after {
  content: '';
  position: absolute;
  left: -0.08em;
  right: -0.08em;
  bottom: -0.42em;
  height: 1px;
  background: currentColor;
}

/* ---- Centred serif headline ---------------------------------------------- */
.ob-headline {
  position: absolute;
  left: 50%;
  top: 11.9%;
  z-index: 3;
  margin: 0;
  transform: translate(-50%, -50%);
  font-family: 'Instrument Serif', Georgia, 'Times New Roman', serif;
  font-weight: 400;
  font-style: normal;
  font-size: clamp(22px, 4.2vmin, 64px);
  letter-spacing: 0.065em;
  line-height: 1.15;
  color: #f5ede3;
  white-space: nowrap;
  pointer-events: none;
  text-shadow: 0 1px 18px rgba(20, 10, 6, 0.22);
}

/* ---- Coverflow ----------------------------------------------------------- */
.ob-coverflow {
  --card-size: clamp(220px, 43vmin, 660px);
  --cover-perspective: clamp(620px, 120vmin, 1848px);
  --arrow-offset: 30vw;      /* all three vars are overwritten in px by JS */
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}
.ob-coverflow:focus { outline: none; }
.ob-coverflow:focus-visible { outline: 1px solid rgba(246, 238, 228, 0.35); outline-offset: -6px; }

/* Generous, invisible drag band. `touch-action: none` prevents page scroll /
   pinch while swiping; it never touches the top bar or the Start button. */
.ob-drag-surface {
  position: absolute;
  left: 0;
  right: 0;
  top: 14%;
  bottom: 20%;
  z-index: 1;
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.ob-coverflow.is-busy .ob-drag-surface { pointer-events: none; }

.ob-stage {
  position: absolute;
  left: 50%;
  top: 42.7%;
  z-index: 2;
  width: var(--card-size);
  height: var(--card-size);
  transform: translate(-50%, -50%);
  pointer-events: none;
  transform-style: flat;
}

/* Each card owns its vinyl, so the disc follows whichever item is centred.
   The wrapper carries ONLY 2D translate/scale -> the vinyl stays a circle.
   The face carries perspective()+rotateY() -> only the cover is projected. */
.ob-card {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--card-size);
  height: var(--card-size);
  transform-origin: 50% 50%;
  pointer-events: auto;
  touch-action: none;
  will-change: transform, opacity, filter;
}
.ob-card-face {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  background: #241a16;
  transform-origin: 50% 50%;
  backface-visibility: hidden;
  box-shadow:
    inset 0 0 0 1px rgba(255, 246, 232, 0.17),
    0 2.4vmin 6vmin rgba(12, 7, 5, 0.55),
    0 0.4vmin 1.2vmin rgba(0, 0, 0, 0.35);
}
.ob-card-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;          /* 1:1 source into a 1:1 box => no crop, no stretch */
  user-select: none;
  -webkit-user-drag: none;
}
.ob-card--empty .ob-card-img { display: none; }
.ob-card--empty .ob-card-face {
  background: linear-gradient(150deg, #4a332a, #2a1c17 60%, #1d1410);
}

/* Black vinyl: ~0.94 card diameter, shifted right so a crescent peeks out
   from behind the centre card's right edge. Grooves + rim highlight are pure
   CSS; no extra image asset. */
.ob-vinyl {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 1;
  width: 94%;
  height: 94%;
  border-radius: 50%;
  /* Reference: roughly a third of the disc peeks out behind the right edge
     of the perfectly frontal centre card. */
  transform: translate(-50%, -50%) translateX(32%);
  background:
    radial-gradient(circle at 38% 30%, rgba(255, 255, 255, 0.10), transparent 44%),
    repeating-radial-gradient(circle at 50% 50%,
      #0b0c0e 0 2px, #1a1b1e 2px 3px, #090a0c 3px 5px),
    #08090a;
  box-shadow:
    0 2vmin 5vmin rgba(0, 0, 0, 0.62),
    inset 0 0 0 1px rgba(255, 246, 232, 0.20),
    inset 0 0 3vmin rgba(0, 0, 0, 0.8);
}
.ob-vinyl-label {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 29%;
  height: 29%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 40% 35%, #4a3024, #26170f 72%);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.55);
}
.ob-vinyl-label::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 12%;
  height: 12%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: #0b0b0c;
}

/* ---- Arrows -------------------------------------------------------------- */
.ob-arrow {
  position: absolute;
  top: 42.7%;
  z-index: 4;
  display: grid;
  place-items: center;
  width: clamp(30px, 4.2vmin, 64px);
  height: clamp(30px, 4.2vmin, 64px);
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: rgba(246, 238, 228, 0.88);
  font-size: clamp(26px, 3.4vmin, 52px);
  cursor: pointer;
  pointer-events: auto;
  touch-action: none;
  transform: translate(-50%, -50%);
  transition: color 160ms ease, opacity 160ms ease;
}
.ob-arrow:hover { color: #fff; }
.ob-arrow--prev { left: calc(50% - var(--arrow-offset)); }
.ob-arrow--next { left: calc(50% + var(--arrow-offset)); }
.ob-chevron {
  display: block;
  width: 0.38em;
  height: 0.38em;
  border-left: 0.055em solid currentColor;
  border-bottom: 0.055em solid currentColor;
  transform: rotate(45deg);
}
.ob-arrow--next .ob-chevron { transform: rotate(-135deg); }

/* ---- Pagination dots ----------------------------------------------------- */
.ob-dots {
  position: absolute;
  left: 50%;
  top: 66%;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: clamp(8px, 0.85vmin, 13px);
  transform: translate(-50%, -50%);
  pointer-events: auto;
}
.ob-dot {
  width: clamp(7px, 0.8vmin, 12px);
  height: clamp(7px, 0.8vmin, 12px);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(235, 225, 215, 0.34);
  cursor: pointer;
  transition: background 180ms ease, transform 180ms ease;
}
.ob-dot.is-active {
  background: #ffffff;
  transform: scale(1.14);
}
.ob-dot:hover { background: rgba(255, 255, 255, 0.72); }

/* ---- Song title + BPM / duration ----------------------------------------- */
.ob-info {
  position: absolute;
  left: 50%;
  top: 69.2%;
  z-index: 3;
  width: min(80vw, 1040px);
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
  color: #f6eee4;
}
.ob-track-title {
  font-family: 'Instrument Serif', Georgia, serif;
  font-size: clamp(30px, 5.6vmin, 86px);
  font-weight: 400;
  line-height: 1.0;
  letter-spacing: 0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 20px rgba(20, 10, 6, 0.25);
}
.ob-track-meta {
  margin-top: clamp(3px, 0.6vmin, 9px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 1.8vmin, 26px);
  font-family: 'Instrument Serif', Georgia, serif;
  font-size: clamp(12px, 2vmin, 31px);
  letter-spacing: 0.24em;
  color: rgba(246, 238, 228, 0.9);
}

/* Difficulty lives INLINE with the BPM line. An extra full-width row overlapped
   the song title (Andy: "前端显示过于拥挤"). Click cycles EASY → NORMAL → HARD. */
.ob-difficulty-chip {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border: 1px solid rgba(246, 238, 228, 0.34);
  border-radius: 999px;
  background: rgba(20, 10, 6, 0.24);
  color: #f6eee4;
  font: 10px/1 'Instrument Sans', Arial, sans-serif;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
  white-space: nowrap;
  transition: background 180ms ease, border-color 180ms ease, transform 160ms ease;
}
.ob-difficulty-chip:hover { background: rgba(20, 10, 6, 0.46); border-color: rgba(246, 238, 228, 0.62); }
.ob-difficulty-chip:active { transform: scale(0.97); }
.ob-difficulty-chip:focus-visible { outline: 2px solid rgba(246, 238, 228, 0.8); outline-offset: 3px; }
.ob-difficulty-label { opacity: 0.58; font-size: 9px; letter-spacing: 0.2em; }
.ob-difficulty-value { font-weight: 600; letter-spacing: 0.14em; }
.ob-difficulty-arrow { opacity: 0.7; font-size: 9px; }
.ob-demo-hint {
  margin-top: clamp(4px, 0.8vmin, 12px);
  font-family: 'Instrument Sans', 'Helvetica Neue', Arial, sans-serif;
  font-size: clamp(9px, 1.1vmin, 17px);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(246, 238, 228, 0.48);
}
.ob-demo-hint[hidden] { display: none; }

/* ---- White pill Start Playing button ------------------------------------- */
.ob-start {
  position: absolute;
  left: 50%;
  top: 82.3%;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 1.9vmin, 30px);
  width: clamp(220px, 36vmin, 560px);
  height: clamp(46px, 6.6vmin, 102px);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: #fbf8f4;
  color: #241c18;
  transform: translate(-50%, -50%);
  font-family: 'Instrument Serif', Georgia, serif;
  font-size: clamp(16px, 2.7vmin, 42px);
  font-weight: 400;
  letter-spacing: 0.01em;
  white-space: nowrap;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: 0 1.4vmin 4vmin rgba(20, 10, 6, 0.28);
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
.ob-start:hover {
  transform: translate(-50%, -50%) scale(1.025);
  box-shadow: 0 1.8vmin 5vmin rgba(20, 10, 6, 0.34);
}
.ob-start:active { transform: translate(-50%, -50%) scale(0.99); }
.ob-start:disabled { cursor: progress; }
.ob-start-icon {
  flex: none;
  width: 0;
  height: 0;
  margin-left: 0.1em;
  border-top: 0.30em solid transparent;
  border-bottom: 0.30em solid transparent;
  border-left: 0.50em solid #241c18;
}
.ob-start-label { display: inline-block; }

/* Busy: replace the play triangle with a restrained spinner. */
.ob-selection.is-busy .ob-start-icon {
  width: 0.85em;
  height: 0.85em;
  border: 0.12em solid rgba(36, 28, 24, 0.22);
  border-top-color: #241c18;
  border-radius: 50%;
  animation: ob-spin 900ms linear infinite;
}
@keyframes ob-spin { to { transform: rotate(360deg); } }

/* ---- Portrait rotation hint (no 9:16 UI) --------------------------------- */
.ob-rotate-hint {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2.4vmin;
  padding: 8vmin;
  text-align: center;
  background: rgba(22, 14, 11, 0.96);
}
.ob-rotate-icon {
  width: 10vmin;
  height: 16vmin;
  border: 0.45vmin solid #f6eee4;
  border-radius: 1.6vmin;
  animation: ob-rotate-nudge 2.6s ease-in-out infinite;
}
.ob-rotate-icon::after {
  content: '';
  display: block;
  width: 34%;
  height: 0.4vmin;
  margin: 1vmin auto 0;
  border-radius: 1vmin;
  background: rgba(246, 238, 228, 0.6);
}
@keyframes ob-rotate-nudge {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-90deg); }
}
.ob-rotate-title {
  font-family: 'Instrument Serif', Georgia, serif;
  font-size: clamp(22px, 3.4vmin, 52px);
}
.ob-rotate-sub {
  font-family: 'Instrument Sans', 'Helvetica Neue', Arial, sans-serif;
  font-size: clamp(12px, 1.6vmin, 24px);
  letter-spacing: 0.1em;
  color: rgba(246, 238, 228, 0.68);
}
@media (orientation: portrait) {
  .ob-rotate-hint { display: flex; }
}

/* ---- Tight / unusual aspect ratios -------------------------------------- */
@media (max-height: 560px) {
  .ob-headline { top: 9.5%; }
  .ob-stage { top: 41.8%; }
  .ob-arrow { top: 41.8%; }
  .ob-dots { top: 64.5%; }
  .ob-info { top: 67.8%; }
  .ob-start { top: 84%; }
}

/* ---- Reduced motion ------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  .ob-bg-video,
  .ob-dot,
  .ob-start,
  .ob-nav-link,
  .ob-locale { transition: none; }
  .ob-rotate-icon,
  .ob-selection.is-busy .ob-start-icon { animation: none; }
}
