/* KTV — a quiet dark screen: one typeface, one accent colour, the video does the talking. */

@font-face {
  font-family: "Geist";
  src: url("/fonts/geist.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #09090b;
  --surface: #101012;
  --raised: #18181b;
  --raised-2: #26262b;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #f4f4f5;
  --text-2: #a1a1aa;
  --text-3: #8a8a93;
  --accent: #ff5a4a;
  --accent-soft: rgba(255, 90, 74, 0.14);

  --font: "Geist", system-ui, -apple-system, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  --panel-w: clamp(340px, 34vw, 420px);
  --deck-min: 230px;
  --pad: clamp(16px, 2.2vw, 32px);
  --radius: 12px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

::selection { background: var(--accent); color: var(--bg); }

p, h1, h2, ul { margin: 0; }
ul { padding: 0; list-style: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

/* One language on screen at a time. Both are in the page; the button at the top of the panel picks one. */
html[data-lang="fr"] .zh, html[data-lang="zh"] .fr { display: none; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-solid { fill: currentColor; }

/* ---------- Layout ---------- */

#app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--panel-w);
  height: 100vh;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

#screen {
  position: relative;
  flex: none;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: calc(100vh - var(--deck-min));
  max-height: calc(100dvh - var(--deck-min));
  background: #000;
  overflow: hidden;
}

#player-slot, #player-slot iframe, #player { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
#screen.is-covered #player-slot { visibility: hidden; }

/* ---------- Covers shown while no video is loaded ---------- */

.cover {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  gap: clamp(8px, 1.6vh, 16px);
  padding: clamp(24px, 6%, 80px);
  background: var(--bg);
}

#idle h1 {
  font-weight: 600; font-size: clamp(30px, 4.6vw, 56px); line-height: 1.05;
  letter-spacing: -0.035em;
  text-wrap: balance;
}
.idle-help { max-width: 36ch; color: var(--text-2); font-size: clamp(15px, 1.5vw, 18px); }

.inter-lead { font-weight: 500; font-size: clamp(18px, 2.2vw, 24px); line-height: 1.2; color: var(--text-2); }
.inter-lead:empty { display: none; }
.inter-name {
  max-width: 100%;
  font-weight: 600; font-size: clamp(52px, 9.5vw, 124px); line-height: 0.98;
  letter-spacing: -0.04em;
  overflow-wrap: anywhere;
  /* The karaoke wipe: grey lettering that fills with white, left to right, over the countdown. */
  color: transparent;
  background: linear-gradient(90deg, var(--text) 50%, rgba(255, 255, 255, 0.26) 50%) 100% 0 / 200% 100% no-repeat;
  -webkit-background-clip: text; background-clip: text;
  padding-bottom: 0.06em;
}
.inter-name.is-wiping { animation: wipe var(--wipe, 5s) linear forwards; }
@keyframes wipe { to { background-position: 0 0; } }
.inter-title { max-width: 44ch; font-size: clamp(15px, 1.8vw, 20px); color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
#inter-start { margin-top: clamp(8px, 1.8vh, 20px); height: 52px; padding: 0 26px; border-radius: 26px; font-size: 16px; }
.count { margin-left: 12px; padding-left: 12px; border-left: 1px solid rgba(9, 9, 11, 0.25); font-variant-numeric: tabular-nums; }
.count:empty { display: none; }

/* ---------- Deck: progress, who sings, controls ---------- */

#deck {
  position: relative;
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  padding: 0 var(--pad) clamp(16px, 2.6vh, 28px);
  background: var(--bg);
}

#progress { flex: none; height: 20px; margin: 0 calc(-1 * var(--pad)); cursor: pointer; }
#progress::before { content: ""; display: block; height: 3px; background: var(--raised-2); }
#progress-fill { height: 3px; margin-top: -3px; width: 0; background: var(--accent); transition: width 0.5s linear; }

#blocked-hint {
  align-self: flex-start;
  display: inline-flex; align-items: center; gap: 8px;
  margin-bottom: 10px; padding: 10px 14px;
  background: var(--accent); color: var(--bg); border-radius: var(--radius);
  font-weight: 600; font-size: 15px; line-height: 1.2;
  animation: nudge 1.1s var(--ease-out) infinite alternate;
}
@keyframes nudge { from { transform: translateY(0); } to { transform: translateY(-3px); } }

#now { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.now-main { min-width: 0; flex: 1; }
#now-singer {
  font-weight: 600; font-size: clamp(30px, 5vh, 46px); line-height: 1.08;
  letter-spacing: -0.035em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#now-singer:empty { display: none; }
#now-title { margin-top: 6px; font-size: 16px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#now-singer:empty + #now-title { margin-top: 0; font-size: clamp(19px, 2.8vh, 26px); font-weight: 500; letter-spacing: -0.02em; color: var(--text); white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.now-side { flex: none; max-width: 40%; text-align: right; }
#now-time { font-size: 14px; font-weight: 500; color: var(--text-2); font-variant-numeric: tabular-nums; }
#next-line { margin-top: 6px; font-size: 14px; color: var(--text-3); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
#next-line strong { color: var(--text); font-weight: 500; }

#controls { flex: none; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; }
#voice { justify-self: start; }
#btn-full { justify-self: end; }
.transport { display: flex; align-items: center; gap: 14px; }

.ctl {
  display: grid; place-items: center;
  width: 48px; height: 48px;
  background: transparent; color: var(--text);
  border: 0; border-radius: 50%;
  transition: background-color 0.15s, transform 0.12s var(--ease-out), opacity 0.15s;
}
.ctl .icon { width: 22px; height: 22px; }
.ctl:active:not(:disabled) { background: var(--raised-2); transform: scale(0.94); }
.ctl-main { width: 64px; height: 64px; background: var(--text); color: var(--bg); }
.ctl-main .icon { width: 26px; height: 26px; }
.ctl-main:active:not(:disabled) { background: #d4d4d8; }
.ctl:disabled { opacity: 0.3; }

/* One segmented control for the voice switch and the panel tabs. */
.segmented, .tabs {
  display: inline-flex; gap: 2px; padding: 3px;
  background: var(--raised); border: 1px solid var(--line); border-radius: var(--radius);
}
.segmented button, .tabs button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px;
  background: transparent; color: var(--text-2);
  border: 0; border-radius: 9px;
  font-weight: 500; font-size: 14.5px; white-space: nowrap;
  transition: background-color 0.15s, color 0.15s, opacity 0.15s;
}
.segmented button[aria-pressed="true"], .tabs button[aria-selected="true"] { background: var(--raised-2); color: var(--text); }
.segmented button:disabled { opacity: 0.4; }
.segmented button.is-busy { animation: pulse 0.8s ease-in-out infinite alternate; }
@keyframes pulse { to { background: var(--raised-2); } }

#toast {
  position: absolute; left: var(--pad); right: var(--pad); top: 26px; z-index: 5;
  padding: 12px 16px;
  background: var(--raised-2); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  font-size: 14.5px; font-weight: 500;
  pointer-events: none;
  animation: rise 0.3s var(--ease-out);
}
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Panel ---------- */

#panel {
  position: relative;
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  background: var(--surface);
  border-left: 1px solid var(--line);
}

.panel-head { flex: none; display: flex; gap: 8px; margin: 14px 16px 6px; }
.tabs { flex: 1; min-width: 0; display: flex; }
.tabs button { flex: 1; }
.lang-switch {
  flex: none; min-width: 64px; padding: 0 14px;
  background: var(--raised); color: var(--text-2);
  border: 1px solid var(--line); border-radius: var(--radius);
  font-weight: 500; font-size: 14.5px; white-space: nowrap;
  transition: background-color 0.15s, color 0.15s;
}
.lang-switch:active { background: var(--raised-2); color: var(--text); }
.count-pill {
  min-width: 20px; padding: 1px 6px; border-radius: 10px;
  background: var(--accent); color: var(--bg);
  font-size: 12px; font-weight: 600; line-height: 1.5; font-variant-numeric: tabular-nums;
}

#tab-search, #tab-queue { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 4px 16px 28px; scrollbar-width: thin; scrollbar-color: var(--raised-2) transparent; }

#search-form { flex: none; display: flex; gap: 8px; padding: 8px 16px 10px; }
.field { position: relative; flex: 1; min-width: 0; }
#search-input, #singer-input {
  width: 100%; height: 48px; padding: 0 14px;
  background: var(--raised); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 16px;
  caret-color: var(--accent);
  transition: border-color 0.15s;
}
#search-input { padding-right: 46px; }
#search-input::placeholder, #singer-input::placeholder { color: var(--text-3); }
#search-input:focus, #singer-input:focus,
#search-input:focus-visible, #singer-input:focus-visible { outline: none; border-color: rgba(255, 255, 255, 0.5); }
#search-clear { position: absolute; right: 2px; top: 2px; }

.icon-btn { display: grid; place-items: center; width: 44px; height: 44px; background: none; color: var(--text-2); border: 0; border-radius: 10px; }
.icon-btn:active { background: var(--raised-2); }

.btn-primary {
  display: inline-flex; align-items: center; justify-content: center;
  height: 48px; padding: 0 20px;
  background: var(--text); color: var(--bg);
  border: 0; border-radius: var(--radius);
  font-weight: 600; font-size: 15px;
  transition: transform 0.12s var(--ease-out), background-color 0.15s;
}
.btn-primary:active { transform: scale(0.97); background: #d4d4d8; }
.btn-square { width: 48px; padding: 0; flex: none; }
.btn-square.is-loading .icon { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.btn-quiet {
  height: 44px; padding: 0 12px;
  background: none; color: var(--text-2);
  border: 0; border-radius: var(--radius);
  font-weight: 500; font-size: 14.5px;
}
.btn-quiet:active { background: var(--raised-2); }

.filters { flex: none; display: flex; gap: 6px; padding: 0 16px 8px; }
.filters button, .chip {
  height: 40px; padding: 0 14px;
  background: var(--raised); color: var(--text);
  border: 1px solid var(--line); border-radius: 20px;
  font-size: 14.5px; white-space: nowrap;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}
.filters button { height: 36px; color: var(--text-2); }
.filters button[aria-pressed="true"], .chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip:active { background: var(--raised-2); }

/* Suggestions */
.suggest { margin-top: 22px; }
.suggest:first-child { margin-top: 10px; }
.suggest h2, .queue-head { margin-bottom: 10px; font-size: 13px; font-weight: 500; color: var(--text-3); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.note { margin-top: 26px; font-size: 12.5px; color: var(--text-3); }
.message { margin-top: 28px; font-size: 15px; color: var(--text-2); text-wrap: pretty; }
.message strong { display: block; margin-bottom: 6px; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; color: var(--text); }

/* Song rows (results, history) */
.songs > li + li { border-top: 1px solid var(--line); }
.song {
  width: 100%; display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 12px; align-items: center;
  padding: 10px 0; text-align: left;
  background: none; border: 0; border-radius: 8px;
}
button.song:active { background: var(--raised); }
.thumb { width: 104px; height: 58px; object-fit: cover; border-radius: 8px; background: var(--raised); }
.song-title { font-size: 14.5px; font-weight: 500; line-height: 1.35; color: var(--text); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.song-meta { margin-top: 5px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.song-meta .who { color: var(--text); font-weight: 500; }
.badge { padding: 1px 8px; border-radius: 10px; font-size: 11.5px; font-weight: 500; line-height: 1.6; white-space: nowrap; }
.badge-sans { color: var(--accent); background: var(--accent-soft); }
.badge-avec { color: var(--text-2); background: var(--raised-2); }

.more { width: 100%; height: 44px; margin-top: 14px; background: none; color: var(--text); border: 1px solid var(--line-strong); border-radius: var(--radius); font-size: 14.5px; font-weight: 500; }
.more:disabled { color: var(--text-3); }

.skeleton li { display: grid; grid-template-columns: 104px 1fr; gap: 12px; padding: 10px 0; }
.skeleton i { display: block; height: 58px; border-radius: 8px; background: var(--raised); animation: breathe 1s ease-in-out infinite alternate; }
.skeleton b { display: block; align-self: center; height: 14px; width: 78%; border-radius: 4px; background: var(--raised); animation: breathe 1s ease-in-out infinite alternate; }
@keyframes breathe { to { opacity: 0.45; } }

/* Queue */
.queue-head { margin: 18px 0 2px; }
.queue-row { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 0; }
.queue-row .pos { display: grid; place-items: center; font-size: 13px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.queue-row.is-current .pos { color: var(--accent); }
.queue-row .pos .icon { width: 18px; height: 18px; }
.queue-actions { display: flex; gap: 2px; margin-right: -8px; }

/* Add sheet */
.sheet { position: absolute; inset: 0; z-index: 10; display: flex; align-items: flex-start; background: rgba(0, 0, 0, 0.62); }
.sheet-card {
  position: relative; width: 100%; max-height: 100%; overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px;
  padding: 20px 16px 14px;
  background: var(--raised);
  border-bottom: 1px solid var(--line-strong);
  border-radius: 0 0 20px 20px;
  animation: sheet-in 0.3s var(--ease-out);
}
@keyframes sheet-in { from { transform: translateY(-28px); opacity: 0.4; } }
#sheet-close { position: absolute; top: 8px; right: 8px; }
.sheet-song { padding-right: 44px; font-size: 16px; font-weight: 600; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.sheet-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.sheet-q { margin-top: 10px; font-size: 20px; font-weight: 600; letter-spacing: -0.02em; }
.sheet .chip { background: var(--raised-2); }
#singer-input { background: var(--bg); border-color: var(--line-strong); }
#sheet-add { margin-top: 6px; }

/* ---------- Compact deck: one line under the video (portrait, short screens, full screen) ---------- */

@media (orientation: portrait) {
  #app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  #panel { border-left: 0; border-top: 1px solid var(--line); }
  #screen { max-height: 46vh; max-height: 46dvh; }
}
@media (orientation: landscape) and (max-height: 599px) {
  :root { --deck-min: 80px; }
}

body.immersive { --deck-min: 80px; }
body.immersive #app { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
body.immersive #panel { display: none; }
/* Full screen: the controls sit at the bottom, the video takes everything above them. */
body.immersive #screen { flex: 1; aspect-ratio: auto; max-height: none; }

@media (orientation: portrait), (max-height: 599px) {
  #deck { flex: none; display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 16px; align-items: center; padding-bottom: 12px; }
  #progress { grid-column: 1 / -1; grid-row: 1; height: 14px; }
  #now, #blocked-hint { grid-column: 1; grid-row: 2; }
  #controls { grid-column: 2; grid-row: 2; display: flex; gap: 10px; }
  #blocked-hint { justify-self: start; margin: 0; padding: 8px 12px; font-size: 14px; }
  #blocked-hint:not([hidden]) + #now { display: none; }
  #now { flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px; min-width: 0; }
  .now-main { display: flex; align-items: baseline; gap: 8px; max-width: 100%; }
  #now-singer { flex: none; max-width: 55%; font-size: 17px; line-height: 1.3; letter-spacing: -0.02em; }
  #now-title, #now-singer:empty + #now-title { margin-top: 0; font-size: 14px; font-weight: 400; letter-spacing: 0; color: var(--text-2); display: block; white-space: nowrap; }
  .now-side { max-width: 100%; text-align: left; }
  #now-time { display: none; }
  #next-line { margin-top: 0; font-size: 12.5px; -webkit-line-clamp: 1; }
  .transport { gap: 4px; }
  .ctl { width: 44px; height: 44px; }
  .ctl-main { width: 48px; height: 48px; }
  .ctl-main .icon { width: 22px; height: 22px; }
  #voice button { height: 36px; padding: 0 12px; font-size: 13.5px; }
  #toast { top: 16px; right: auto; max-width: 60%; padding: 9px 14px; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}
body.immersive #deck { flex: none; display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 16px; align-items: center; padding-bottom: 12px; }
body.immersive #progress { grid-column: 1 / -1; grid-row: 1; height: 14px; }
body.immersive #now, body.immersive #blocked-hint { grid-column: 1; grid-row: 2; }
body.immersive #controls { grid-column: 2; grid-row: 2; display: flex; gap: 10px; }
body.immersive #blocked-hint { justify-self: start; margin: 0; padding: 8px 12px; font-size: 14px; }
body.immersive #blocked-hint:not([hidden]) + #now { display: none; }
body.immersive #now { flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px; min-width: 0; }
body.immersive .now-main { display: flex; align-items: baseline; gap: 8px; max-width: 100%; }
body.immersive #now-singer { flex: none; max-width: 55%; font-size: 17px; line-height: 1.3; letter-spacing: -0.02em; }
body.immersive #now-title { margin-top: 0; font-size: 14px; font-weight: 400; letter-spacing: 0; color: var(--text-2); display: block; white-space: nowrap; }
body.immersive .now-side { max-width: 100%; text-align: left; }
body.immersive #now-time { display: none; }
body.immersive #next-line { margin-top: 0; font-size: 12.5px; -webkit-line-clamp: 1; }
body.immersive .transport { gap: 4px; }
body.immersive .ctl { width: 44px; height: 44px; }
body.immersive .ctl-main { width: 48px; height: 48px; }
body.immersive .ctl-main .icon { width: 22px; height: 22px; }
body.immersive #voice button { height: 36px; padding: 0 12px; font-size: 13.5px; }
body.immersive #toast { top: 16px; right: auto; max-width: 60%; padding: 9px 14px; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* A phone held upright: who sings on one line, the controls on the next. */
@media (max-width: 640px) {
  #deck { grid-template-columns: minmax(0, 1fr); row-gap: 8px; }
  #controls { grid-column: 1; grid-row: 3; justify-content: space-between; gap: 6px; }
  .ctl { width: 40px; height: 40px; }
  .ctl-main { width: 44px; height: 44px; }
  #voice button { padding: 0 10px; }
  #toast { max-width: calc(100% - 2 * var(--pad)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  .inter-name.is-wiping { animation: none; background-position: 0 0; }
}
