/* ============================================================
   KARAOKE APP — ryOS-style UI port
   ============================================================ */

@import url("https://fonts.googleapis.com/css2?family=Quicksand:wght@700&display=swap");

/* macOS: transparent window with rounded corners */
body:not(.theme-winxp) #karaoke-window {
  background: transparent;
  border: none;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  border-radius: 12px;
  overflow: hidden;
}

body:not(.theme-winxp) #karaoke-window .window-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 80;
  background: transparent;
  border-bottom: none;
}

body:not(.theme-winxp) #karaoke-window .window-header .window-title {
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

/* macOS: fade title bar when mouse leaves the window */
body:not(.theme-winxp) #karaoke-window.karaoke-hover-out .window-header {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

body:not(.theme-winxp) #karaoke-window:not(.karaoke-hover-out) .window-header {
  opacity: 1;
  transition: opacity 0.3s ease;
}

#karaoke-window .window-content.karaoke-content {
  position: relative;
  height: 100%;
  padding: 0;
  overflow: hidden;
  background: #000;
  border-radius: inherit;
}

/* The stage is the @container — container queries drive lyric size */
.karaoke-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #000;
  border-radius: inherit;
  container-type: size;
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
  font-family: "Quicksand", "VAGRounded", "Kosugi Maru", "Hiragino Maru Gothic ProN",
    "Nanum Gothic", "Yuanti SC", ui-rounded, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  font-weight: normal;
  line-height: 1.1;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  font-smooth: always;
}

/* ---------- Video layer (YouTube iframe) ---------- */
/* Extends height by +400px and shifts up -200px so YT UI chrome is clipped
   off the top/bottom of the visible area — matches ryos.                    */

.karaoke-video-wrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 1;
}

.karaoke-video-wrap.hidden-visual {
  visibility: hidden;
  pointer-events: none;
}

.karaoke-video-clip {
  position: absolute;
  left: 0;
  right: 0;
  top: -200px;
  height: calc(100% + 400px);
  width: 100%;
}

#karaoke-yt-player,
#karaoke-yt-player iframe {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  border: 0;
  pointer-events: none;
}

/* ---------- Alt display layers (cover / gradient) ---------- */

.karaoke-display-bg {
  position: absolute;
  inset: 0;
  z-index: 15;
}

.karaoke-display-bg.hidden {
  display: none;
}

.karaoke-display-cover {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  filter: brightness(0.5);
  transition: background-image 0.3s ease, opacity 0.3s ease;
}

.karaoke-display-gradient {
  background: conic-gradient(
    from 0deg,
    var(--kg1, #5b21b6),
    var(--kg2, #db2777),
    var(--kg3, #f59e0b),
    var(--kg1, #5b21b6)
  );
  filter: brightness(0.55) saturate(1.4);
  animation: karaoke-gradient-spin 22s linear infinite;
  transform: scale(1.4);
}

@keyframes karaoke-gradient-spin {
  from { transform: scale(1.4) rotate(0deg); }
  to   { transform: scale(1.4) rotate(360deg); }
}

/* ---------- Dark overlay (between video and lyrics) ---------- */

.karaoke-dark-layer {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

/* ---------- Lyrics overlay ---------- */

.karaoke-lyrics-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

.karaoke-lyrics-container {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 1cqh;
  padding: 0 2cqw 8cqh 2cqw;
  overflow: hidden;
  z-index: 40;
  user-select: none;
  -webkit-user-select: none;
}

.karaoke-lyrics-container.compact-pad {
  padding-bottom: 5cqh;
}

.karaoke-lyric-line {
  display: none;
  width: 100%;
  max-width: 100%;
  padding: 0.4em 16px 0.2em 16px;
  text-align: center;
  color: #fff;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: clamp(16px, min(7cqw, 14cqh), 96px);
  font-weight: normal;
  line-height: 1.1;
  opacity: 0;
  transform: translateY(10px) scale(0.93);
  -webkit-text-stroke: 0.12em rgba(0, 0, 0, 0.7);
  paint-order: stroke fill;
  text-shadow: none;
  transition:
    opacity 0.2s ease,
    transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1),
    color 0.2s ease;
  backface-visibility: hidden;
  will-change: opacity, transform;
  -webkit-font-smoothing: antialiased;
  font-smooth: always;
}

.karaoke-lyric-line.active,
.karaoke-lyric-line.next {
  display: block;
}

/* Two-line display: current + next */
.karaoke-lyric-line.active {
  opacity: 1;
  transform: translateY(0) scale(1);
  -webkit-text-stroke: 0;
  text-shadow: none;
}

.karaoke-lyric-line.next {
  opacity: 0.6;
  transform: translateY(0) scale(1);
  color: #fff;
  -webkit-text-stroke: 0.12em rgba(0, 0, 0, 0.7);
}

/* Next line words don't need the two-layer system */
.karaoke-lyric-line.next .karaoke-word-highlight {
  display: none;
}

.karaoke-lyric-line.next .karaoke-word-base {
  opacity: 1;
}

/* Word-by-word sliding highlight (two-layer mask) */
.karaoke-word {
  display: inline-grid;
  vertical-align: baseline;
  white-space: pre-wrap;
  padding: 0.4em 4px 0.2em 4px;
  margin: -0.4em -4px -0.2em -4px;
  overflow: visible;
}

.karaoke-word-layer {
  grid-area: 1 / 1;
  overflow: visible;
}

/* Base layer: white text, black stroke, slightly dimmed */
.karaoke-word-base {
  color: #fff;
  -webkit-text-stroke: 0.12em rgba(0, 0, 0, 0.7);
  paint-order: stroke fill;
  opacity: 0.55;
}

/* Highlight layer: blue text, white stroke, masked */
.karaoke-word-highlight {
  color: #0066FF;
  -webkit-text-stroke: 0.12em #fff;
  paint-order: stroke fill;
  -webkit-mask-image: linear-gradient(to right,
    black calc(var(--mask-progress, 0) * 103% - 3%),
    transparent calc(var(--mask-progress, 0) * 103%));
  mask-image: linear-gradient(to right,
    black calc(var(--mask-progress, 0) * 103% - 3%),
    transparent calc(var(--mask-progress, 0) * 103%));
}

/* Plain (unsynced) mode: static bottom-aligned scrollable block */
.karaoke-lyrics-container.plain-mode {
  justify-content: flex-end;
  pointer-events: auto;
  overflow-y: auto;
  padding-bottom: 10cqh;
}

.karaoke-lyrics-container.plain-mode .karaoke-lyric-line {
  display: block;
  opacity: 0.9;
  font-size: clamp(12px, min(2.4cqw, 5cqh), 28px);
  font-weight: normal;
  transform: none;
  margin-bottom: 4px;
  -webkit-text-stroke: 0.08em rgba(0, 0, 0, 0.7);
  paint-order: stroke fill;
  text-shadow: none;
}

.karaoke-lyrics-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: rgba(255, 255, 255, 0.6);
  font-size: clamp(14px, 2.4cqmin, 22px);
  text-align: center;
  pointer-events: none;
}

.karaoke-lyrics-empty .ic {
  font-size: clamp(28px, 6cqmin, 56px);
  opacity: 0.55;
}

/* ---------- Status text (top-left, chicago-style outline) ---------- */

.karaoke-status {
  position: absolute;
  top: clamp(16px, 4cqmin, 32px);
  left: clamp(16px, 4cqmin, 32px);
  z-index: 40;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.karaoke-status.visible {
  opacity: 1;
}

.karaoke-status-text {
  font-size: clamp(18px, 5cqmin, 48px);
  font-family: "ChicagoFLF", "Chicago", Charter, "Times New Roman", serif;
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0.02em;
  color: #fff;
  text-shadow:
    -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000,
    -2px 0 0 #000, 2px 0 0 #000, 0 -2px 0 #000, 0 2px 0 #000,
    0 0 8px rgba(0, 0, 0, 0.6);
}

/* ---------- Top toolbar (add-song / library / mode badge) ---------- */

.karaoke-toolbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px 10px 16px;
  pointer-events: auto;
  transition: opacity 0.2s ease;
  background: linear-gradient(to bottom, rgba(0,0,0,0.55), rgba(0,0,0,0));
}

/* macOS: push toolbar below the transparent title bar */
body:not(.theme-winxp) #karaoke-window .karaoke-toolbar {
  top: 32px;
}

.karaoke-toolbar button {
  background: rgba(38, 38, 38, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.85);
  border-radius: 999px;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
  font-family: inherit;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.karaoke-toolbar button:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.karaoke-toolbar button:active {
  transform: scale(0.95);
}

#karaoke-add-input {
  flex: 1;
  min-width: 0;
  background: rgba(38, 38, 38, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 12px;
  outline: none;
  font-family: inherit;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

#karaoke-add-input::placeholder {
  color: rgba(255, 255, 255, 0.45);
}

#karaoke-add-input:focus {
  border-color: rgba(255, 255, 255, 0.35);
  background: rgba(60, 60, 60, 0.7);
}

.karaoke-mode-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(38, 38, 38, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

/* ---------- Bottom control toolbar (FullscreenPlayerControls style) ---------- */

.karaoke-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 0 16px 24px 16px;
  pointer-events: auto;
  transition: opacity 0.2s ease;
}

/* Control islands row */
.karaoke-controls-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.karaoke-controls-island {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: rgba(38, 38, 38, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.karaoke-controls-island button {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 15px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
  position: relative;
  padding: 0;
}

.karaoke-controls-island button:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.karaoke-controls-island button:active {
  transform: scale(0.92);
}

.karaoke-controls-island #karaoke-play {
  font-size: 16px;
  color: rgba(255, 255, 255, 0.9);
}

#karaoke-offset-value {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.8);
  min-width: 32px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-family: "Geneva-12", system-ui, sans-serif;
  padding: 0 2px;
}

/* Idle auto-hide (when playing or fullscreen) */
#karaoke-window.karaoke-idle .karaoke-toolbar,
#karaoke-window.karaoke-idle .karaoke-controls {
  opacity: 0;
  pointer-events: none;
}

body:not(.theme-winxp) #karaoke-window.karaoke-idle .window-header {
  opacity: 0;
  pointer-events: none;
}

#karaoke-window.karaoke-idle .karaoke-toolbar,
#karaoke-window.karaoke-idle .karaoke-controls,
body:not(.theme-winxp) #karaoke-window.karaoke-idle .window-header {
  transition: opacity 0.4s ease;
}

#karaoke-window .karaoke-toolbar,
#karaoke-window .karaoke-controls,
body:not(.theme-winxp) #karaoke-window .window-header {
  transition: opacity 0.4s ease;
}

/* ---------- Library drawer ---------- */

.karaoke-library-panel {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 300px;
  z-index: 70;
  background: rgba(12, 12, 14, 0.88);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.3s ease;
  font-family: "Geneva-12", system-ui, sans-serif;
}

.karaoke-library-panel.hidden {
  display: flex;
  transform: translateX(-100%);
}

.karaoke-library-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

#karaoke-library-close {
  background: transparent;
  border: 0;
  color: rgba(255, 255, 255, 0.75);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

#karaoke-library-close:hover {
  color: #f87171;
}

.karaoke-library-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.karaoke-library-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.15s ease;
  border-left: 3px solid transparent;
}

.karaoke-library-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.karaoke-library-item.active {
  background: rgba(255, 255, 255, 0.08);
  border-left-color: rgba(255, 255, 255, 0.85);
}

.karaoke-library-thumb {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  background: #222 center/cover no-repeat;
  flex-shrink: 0;
}

.karaoke-library-title {
  flex: 1;
  min-width: 0;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.karaoke-library-empty {
  padding: 24px 16px;
  text-align: center;
  color: rgba(255, 255, 255, 0.5);
  font-size: 11px;
}

/* ---------- Empty state (no songs) ---------- */

.karaoke-empty {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: rgba(255, 255, 255, 0.85);
  text-align: center;
  padding: 20px;
  background: linear-gradient(135deg, #0a0014 0%, #000 100%);
  font-family: "Geneva-12", system-ui, sans-serif;
}

.karaoke-empty.hidden {
  display: none;
}

.karaoke-empty-icon {
  font-size: clamp(48px, 9cqmin, 84px);
  opacity: 0.5;
}

.karaoke-empty-title {
  font-size: clamp(16px, 3cqmin, 22px);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.karaoke-empty-sub {
  font-size: clamp(11px, 1.6cqmin, 14px);
  color: rgba(255, 255, 255, 0.55);
  max-width: 320px;
}

/* ---------- Fullscreen mode ---------- */

#karaoke-window.karaoke-fullscreen {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 9999 !important;
  border-radius: 0 !important;
}

#karaoke-window.karaoke-fullscreen .window-header,
#karaoke-window.karaoke-fullscreen .resize-handle {
  display: none;
}

#karaoke-window.karaoke-fullscreen .karaoke-lyric-line {
  font-size: clamp(32px, min(10vw, 10vh), 120px);
}

/* ---------- WinXP theme override — keep macOS-style dark buttons ---------- */

body.theme-winxp #karaoke-window .karaoke-toolbar button {
  background: rgba(38, 38, 38, 0.6) !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  color: rgba(255, 255, 255, 0.85) !important;
  border-radius: 999px !important;
  font-family: inherit !important;
  font-size: 14px !important;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3) !important;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

body.theme-winxp #karaoke-window .karaoke-toolbar button:hover {
  background: rgba(255, 255, 255, 0.12) !important;
  color: #fff !important;
  border-color: rgba(255, 255, 255, 0.1) !important;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3) !important;
}

body.theme-winxp #karaoke-window .karaoke-toolbar button:active {
  background: rgba(255, 255, 255, 0.08) !important;
  box-shadow: none !important;
}

body.theme-winxp #karaoke-window .karaoke-controls-island button {
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  color: rgba(255, 255, 255, 0.72) !important;
  border-radius: 999px !important;
  font-family: inherit !important;
  font-size: 15px !important;
}

body.theme-winxp #karaoke-window .karaoke-controls-island button:hover {
  color: #fff !important;
  background: rgba(255, 255, 255, 0.1) !important;
  box-shadow: none !important;
}

body.theme-winxp #karaoke-window .karaoke-controls-island button:active {
  background: rgba(255, 255, 255, 0.08) !important;
  box-shadow: none !important;
}

body.theme-winxp #karaoke-window .karaoke-controls-island #karaoke-play {
  font-size: 16px !important;
  color: rgba(255, 255, 255, 0.9) !important;
}

body.theme-winxp #karaoke-window #karaoke-library-close {
  background: transparent !important;
  border: 0 !important;
  color: rgba(255, 255, 255, 0.75) !important;
  box-shadow: none !important;
  border-radius: 0 !important;
  font-size: 20px !important;
}

body.theme-winxp #karaoke-window #karaoke-add-input {
  background: rgba(38, 38, 38, 0.6) !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  color: #fff !important;
  border-radius: 999px !important;
  font-family: inherit !important;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3) !important;
}

body.theme-winxp #karaoke-window #karaoke-add-input:focus {
  border-color: rgba(255, 255, 255, 0.35) !important;
  background: rgba(60, 60, 60, 0.7) !important;
}

body.theme-winxp #karaoke-window .karaoke-mode-badge {
  background: rgba(38, 38, 38, 0.6) !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  color: rgba(255, 255, 255, 0.9) !important;
  border-radius: 999px !important;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3) !important;
}

/* Mobile tweaks */
@media (max-width: 768px) {
  .karaoke-library-panel {
    width: 82vw;
  }
  .karaoke-toolbar {
    flex-wrap: wrap;
  }
  #karaoke-add-input {
    order: 10;
    width: 100%;
    flex-basis: 100%;
  }
  .karaoke-track-info {
    width: 92%;
  }

  /* Title bar: truncate long titles */
  #karaoke-window .window-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: calc(100vw - 100px);
  }

  /* Bottom controls: stack islands vertically, enlarge touch targets */
  .karaoke-controls {
    padding: 0 10px 16px 10px;
  }
  .karaoke-controls-row {
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
  }
  .karaoke-controls-island {
    gap: 2px;
    padding: 3px;
  }
  .karaoke-controls-island button {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }
  .karaoke-controls-island #karaoke-play {
    font-size: 18px;
  }
  #karaoke-offset-value {
    font-size: 11px;
    min-width: 36px;
  }
}
