/* J-1005-TYPING-NOW-PLAYING
   Combat line under the helper keyboard, and the pause-screen music menu.
   Header picker styles stay in the music-picker hop. */

#screen-dungeon .stage-keyboard-bl { bottom: 2.65rem; }

/* J-1005-16: song name and note icons only. No pill, border, or fill.
   The dark halo keeps the cream type readable on the dungeon. */
#now-playing {
  position: absolute;
  left: 0.4rem;
  right: auto;
  bottom: 0.16rem;
  top: auto;
  z-index: 7;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: min(42vw, 16rem);
  margin: 0;
  padding: 0.16rem 0.55rem;
  border: 0;
  border-radius: 0;
  background: none;
  appearance: none;
  -webkit-appearance: none;
  color: #fff6d8;
  font: 700 0.74rem/1.2 Georgia, "Palatino Linotype", Palatino, serif;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: none;
  text-shadow:
    0 1px 1px rgba(0, 0, 0, 0.95),
    0 0 6px rgba(0, 0, 0, 0.92),
    0 0 1px #140e06,
    1px 0 0 #140e06,
    -1px 0 0 #140e06,
    0 1px 0 #140e06,
    0 -1px 0 #140e06;
}
#now-playing[hidden] { display: none !important; }
#now-playing.is-silent { opacity: 0.72; }
#now-playing:hover { filter: brightness(1.08); }
#now-playing:focus-visible {
  outline: 2px solid #f5c542;
  outline-offset: 2px;
}

#win-now-playing {
  display: inline-flex;
  margin: 0.35rem auto 0.2rem;
  padding: 0.2rem 0.7rem;
  border: 1px solid rgba(245, 197, 66, 0.72);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(74, 56, 28, 0.94), rgba(28, 20, 10, 0.94));
  color: #f8e7b8;
  font: 700 0.85rem/1.2 Georgia, "Palatino Linotype", Palatino, serif;
}
#win-now-playing[hidden] { display: none !important; }

.pause-audio .pause-toggle {
  grid-template-columns: 1fr auto;
}
#pause-music-picker.bgm-picker {
  display: block;
  position: relative;
  width: 100%;
  max-width: 24rem;
  margin: 0.15rem auto 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  white-space: normal;
  min-height: 0;
  z-index: 3;
}
#pause-music-picker .bgm-picker-kicker {
  display: block;
  margin: 0 0 0.28rem;
  color: var(--gold);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}
#pause-music-picker .bgm-picker-toggle {
  display: flex;
  width: 100%;
  min-height: 34px;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  padding: 0.28rem 0.6rem;
  border: 1px solid rgba(245, 197, 66, 0.55);
  border-radius: 0.45rem;
  background: rgba(5, 10, 22, 0.72);
  color: #f6e7b2;
  font: 700 0.8rem/1.2 Georgia, "Palatino Linotype", Palatino, serif;
  cursor: pointer;
  text-align: left;
}
#pause-music-picker .bgm-picker-toggle::after {
  content: "▾";
  color: var(--gold);
}
#pause-music-picker.is-open .bgm-picker-toggle::after { content: "▴"; }
#pause-music-picker .bgm-menu {
  position: absolute !important;
  left: 0 !important;
  right: 0 !important;
  top: calc(100% - 0.15rem) !important;
  width: auto !important;
  z-index: 6;
  max-height: min(46vh, 16rem) !important;
  overflow: auto;
  margin-top: 0.28rem;
  padding: 0.35rem;
  border: 1px solid rgba(245, 197, 66, 0.55);
  border-radius: 0.55rem;
  background: linear-gradient(180deg, rgba(36, 28, 16, 0.98), rgba(14, 12, 10, 0.98));
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.5);
  text-align: left;
}
#pause-music-picker .bgm-random,
#pause-music-picker .bgm-song {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  width: 100%;
  margin: 0;
  padding: 0.32rem 0.4rem;
  border: 0;
  border-radius: 0.35rem;
  background: transparent;
  color: #f3e6c4;
  font: 700 0.78rem/1.25 Georgia, "Palatino Linotype", Palatino, serif;
  text-align: left;
  cursor: pointer;
}
#pause-music-picker .bgm-random { color: var(--gold); }
#pause-music-picker .bgm-random[aria-checked="true"],
#pause-music-picker .bgm-song:has(input:checked) {
  background: rgba(245, 197, 66, 0.14);
}
#pause-music-picker .bgm-song input { accent-color: var(--gold); }

@media (max-height: 850px) {
  #screen-dungeon .stage-keyboard-bl { bottom: 2.45rem; }
  #now-playing { bottom: 0.1rem; max-width: min(36vw, 14rem); font-size: 0.68rem; }
}

/* Narrow combat, including 390: keep the helper keyboard, then the line under it,
   clear of the word box, the loot row, the hit line, and Exit Full Screen. */
@media (max-width: 600px) {
  #screen-dungeon .viewport {
    height: 508px;
    min-height: 508px;
  }
  #screen-dungeon .fighters { height: 118px; transform: none; }
  #screen-dungeon .current-fight-label { top: 108px; }
  #screen-dungeon .stage-bottom-cluster { top: 132px; }
  #screen-dungeon #type-input { height: 34px; min-height: 34px; }
  #screen-dungeon .stage-keyboard-bl {
    display: flex !important;
    flex-direction: column;
    /* J-1006-127: start under the word box (it ends at 237px), not on it. */
    top: 241px;
    bottom: auto;
    left: 0.4rem;
    right: 0.4rem;
    width: auto;
    max-width: none;
    z-index: 22;
    padding-top: 0.08rem;
    padding-bottom: 0.06rem;
  }
  #now-playing {
    top: 352px;
    height: 40px;
    min-height: 0;
    bottom: auto;
    left: 0.45rem;
    right: 0.45rem;
    max-width: none;
    width: auto;
    z-index: 23;
    padding: 0.1rem 0.45rem;
  }
  #screen-dungeon .stage-loot-col {
    top: 392px;
    min-height: 0;
    height: auto;
    padding: 0.16rem 0.35rem;
  }
}

.app.layout-combat:fullscreen #now-playing {
  z-index: 7;
}

/* J-1005-89: song progress. Painted as background layers on the line
   itself (no extra element, nothing over the text, clicks unchanged).
   JS sets --np-p 0..1 every 400 ms; the size slides between ticks.
   Layers: gold edge at the bottom, faint gold wash, dim full-width track. */
#now-playing.has-progress,
.app:has(> #screen-title.land.active) #landing-now-playing.has-progress:not([hidden]) {
  --np-p: 0;
  background-image:
    linear-gradient(rgba(245, 197, 66, 0.85), rgba(245, 197, 66, 0.85)),
    linear-gradient(90deg, rgba(245, 197, 66, 0.05), rgba(245, 197, 66, 0.2)),
    linear-gradient(rgba(255, 246, 216, 0.16), rgba(255, 246, 216, 0.16));
  background-size:
    calc(var(--np-p) * 100%) 2px,
    calc(var(--np-p) * 100%) 100%,
    100% 2px;
  background-position: left bottom, left top, left bottom;
  background-repeat: no-repeat;
  transition: background-size 0.45s linear;
}
/* The combat button is taller than its one text line (button min-height), so
   the wash and the edge hug the text instead of filling the whole box. */
#now-playing.has-progress {
  border-radius: 3px;
  background-size:
    calc(var(--np-p) * 100%) 2px,
    calc(var(--np-p) * 100%) 1.55em,
    100% 2px;
  background-position:
    left top calc(50% + 0.78em),
    left center,
    left top calc(50% + 0.78em);
}
#now-playing.np-jump,
#landing-now-playing.np-jump { transition: none; }
@media (prefers-reduced-motion: reduce) {
  #now-playing.has-progress,
  #landing-now-playing.has-progress { transition: none; }
}

/* J-1005-89: Music menu preview button. Sits between the checkbox and the
   song name. The row being previewed gets a thin bar along its bottom. */
.bgm-menu .bgm-song .bgm-preview {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 1.45rem;
  height: 1.45rem;
  min-width: 0;
  min-height: 0;
  margin: -0.05rem 0 0;
  padding: 0;
  border: 1px solid rgba(245, 197, 66, 0.45);
  border-radius: 50%;
  background: rgba(8, 8, 10, 0.45);
  color: #f5c542;
  font: 700 0.62rem/1 system-ui, -apple-system, "Segoe UI", sans-serif;
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 0.15s, background-color 0.15s, border-color 0.15s;
}
.bgm-song .bgm-preview:hover,
.bgm-song .bgm-preview:focus-visible { opacity: 1; background: rgba(245, 197, 66, 0.18); border-color: #f5c542; }
.bgm-song .bgm-preview:focus-visible { outline: 2px solid #f5c542; outline-offset: 2px; }
.bgm-song .bgm-preview.is-playing {
  opacity: 1;
  background: #f5c542;
  border-color: #f5c542;
  color: #1a1206;
}
/* !important: the checked-row rules use the background shorthand. */
.bgm-song.is-previewing {
  background-image: linear-gradient(rgba(245, 197, 66, 0.8), rgba(245, 197, 66, 0.8)) !important;
  background-size: calc(var(--bgm-preview-p, 0) * 100%) 2px !important;
  background-position: left bottom !important;
  background-repeat: no-repeat !important;
  transition: background-size 0.45s linear;
}
#pause-music-picker .bgm-song .bgm-preview { width: 1.3rem; height: 1.3rem; margin: 0; }

/* J-1018-13: song cover between the preview button and the name. */
.bgm-song { align-items: center; }
.bgm-song .bgm-art {
  flex: 0 0 auto;
  display: block;
  width: 2rem;
  height: 2rem;
  border: 1px solid rgba(245, 197, 66, 0.45);
  border-radius: 4px;
  object-fit: cover;
  background: rgba(8, 8, 10, 0.45);
}
#pause-music-picker .bgm-song .bgm-art { width: 1.6rem; height: 1.6rem; }
.bgm-song.is-loading .bgm-art { filter: grayscale(1); opacity: 0.5; }

/* Desk #82537: a song still downloading. Green fill behind the row grows
   with the bytes; checkbox and preview stay grey until it lands. */
.bgm-song.is-loading {
  cursor: default;
  background-image: linear-gradient(rgba(64, 196, 92, 0.42), rgba(64, 196, 92, 0.42)) !important;
  background-size: calc(var(--bgm-load-p, 0) * 100%) 100% !important;
  background-position: left center !important;
  background-repeat: no-repeat !important;
  transition: background-size 0.2s linear;
}
.bgm-song.is-loading input,
.bgm-song.is-loading .bgm-preview {
  filter: grayscale(1);
  opacity: 0.35 !important;
  cursor: default;
  pointer-events: none;
}
.bgm-song.is-loading span { opacity: 0.75; }
