/* ============================================================
   Live Transcript — Spotify-lyrics look: bold sans on a solid,
   user-picked color. Words go from dark to white as they're
   finalized. Light colors flip the text to black (data-tone).
   ============================================================ */

:root {
  color-scheme: dark;
  --ease: cubic-bezier(0.2, 0.75, 0.15, 1);
  --font: 'Figtree', 'Helvetica Neue', Arial, sans-serif;
  --level: 0;
  --bg: var(--lyr-bg, #58999b);
  --bg-raise: rgba(0, 0, 0, 0.2);
  --ink: #ffffff;
  --ink-soft: color-mix(in srgb, #000 78%, var(--bg));
  --muted: rgba(255, 255, 255, 0.72);
  --rule: rgba(255, 255, 255, 0.28);
  --accent: #ffffff;
  --accent-ink: #000000;
  --glow: rgba(255, 255, 255, 0.35);
  --pop: #ffffff;      /* mic button + toast */
  --pop-ink: #000000;
  --pop-error: #b3261e;
  --menu: #181818;     /* color picker popover */
}

/* Light background colors: black lyrics instead of white */
:root[data-tone='light'] {
  color-scheme: light;
  --bg-raise: rgba(0, 0, 0, 0.1);
  --ink: #000000;
  --ink-soft: color-mix(in srgb, #000 32%, var(--bg));
  --muted: rgba(0, 0, 0, 0.62);
  --rule: rgba(0, 0, 0, 0.24);
  --accent: #000000;
  --accent-ink: #ffffff;
  --glow: rgba(0, 0, 0, 0.25);
  --pop: #000000;
  --pop-ink: #ffffff;
  --pop-error: #ff8a80;
}

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

html { background: var(--bg); transition: background-color 0.6s var(--ease); }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  transition: background-color 0.6s var(--ease), color 0.6s var(--ease);
}

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

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

button, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* Fades so text dissolves under the header and dock */
body::before,
body::after {
  content: '';
  position: fixed;
  left: 0;
  right: 0;
  z-index: 20;
  pointer-events: none;
}
body::before { top: 0; height: 150px; background: linear-gradient(var(--bg) 72%, transparent); }
body::after { bottom: 0; height: 200px; background: linear-gradient(transparent, var(--bg) 70%); }

/* ---------- Now-playing header ---------- */

.lyr-head {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 36;
  display: flex;
  align-items: center;
  gap: 14px;
  width: min(44rem, 100% - 32px);
  margin: 0 auto;
  padding: 28px 0 0;
}
.lyr-cover {
  flex: none;
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  background:
    radial-gradient(circle at 30% 25%, color-mix(in srgb, var(--bg) 70%, #fff) 0%, transparent 60%),
    linear-gradient(145deg, color-mix(in srgb, var(--bg) 45%, #000), #0d0d0d);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s var(--ease), background 0.6s;
}
.lyr-cover:hover { transform: scale(1.05); }
.eq { display: flex; align-items: flex-end; gap: 3px; height: 22px; }
.eq i {
  width: 4px;
  height: 25%;
  border-radius: 1px;
  background: #fff;
  opacity: 0.9;
  transition: height 0.08s linear;
}
body.is-live .eq i:nth-child(1) { height: calc(20% + var(--level) * 80%); }
body.is-live .eq i:nth-child(2) { height: calc(35% + var(--level) * 65%); }
body.is-live .eq i:nth-child(3) { height: calc(15% + var(--level) * 85%); }
body.is-live .eq i:nth-child(4) { height: calc(28% + var(--level) * 55%); }
.lyr-meta { min-width: 0; }
.lyr-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lyr-sub {
  margin-top: 4px;
  font-weight: 500;
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lyr-sub [data-timer] { font-variant-numeric: tabular-nums; }

/* Account: minutes used + log out */
.lyr-account {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  flex: none;
}
.usage {
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  cursor: default;
}
.usage.over { color: var(--ink); text-decoration: underline wavy; text-underline-offset: 4px; }

/* ---------- Transcript ---------- */

.transcript {
  position: relative;
  z-index: 10;
  width: min(46rem, 100% - 32px);
  margin: 0 auto;
  padding: 150px 0 42vh;
  font-size: clamp(1.55rem, 1.05rem + 1.9vw, 2.5rem);
  font-weight: 700;
  line-height: 1.32;
  letter-spacing: -0.012em;
}

.para { margin: 0 0 0.45em; }

.w {
  display: inline-block;
  margin-right: 0.26em;
  color: var(--ink-soft);
  transition: color 0.45s ease;
}
.w.final { color: var(--ink); }

.w.enter {
  animation-name: lift;
  animation-duration: 0.45s;
  animation-timing-function: var(--ease);
  animation-fill-mode: both;
  animation-delay: calc(var(--i, 0) * 38ms);
}
@keyframes lift {
  from { opacity: 0; transform: translateY(0.3em); }
  to { opacity: 1; transform: none; }
}

.caret {
  display: none;
  width: 3px;
  height: 0.85em;
  margin-left: 0.05em;
  vertical-align: -0.08em;
  border-radius: 2px;
  background: var(--ink);
  animation: blink 1.05s steps(1) infinite;
}
body.is-live .caret { display: inline-block; }
@keyframes blink { 50% { opacity: 0; } }

/* Empty state */
.empty { color: var(--ink-soft); transition: opacity 0.5s var(--ease); }
.empty.gone { opacity: 0; pointer-events: none; position: absolute; }
.empty p { margin: 0; }

/* ---------- Dock ---------- */

.dock {
  position: fixed;
  left: 50%;
  bottom: 30px;
  z-index: 45;
  transform: translateX(-50%);
  width: min(540px, 100% - 32px);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-raise);
  border-radius: 999px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.22);
  transition: background-color 0.6s var(--ease);
}

.dock-side { display: flex; align-items: center; gap: 6px; }
.dock-right { justify-content: flex-end; }

.lang { position: relative; display: inline-flex; }
.lang::after {
  content: '';
  position: absolute;
  right: 12px;
  top: 50%;
  width: 5px;
  height: 5px;
  border-right: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
  opacity: 0.6;
}
.lang select {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 9px 30px 9px 14px;
  font: 700 12px/1 var(--font);
  letter-spacing: 0.02em;
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.2s, opacity 0.2s;
}
.lang select:hover { border-color: var(--accent); }
.lang select:disabled { opacity: 0.4; cursor: not-allowed; }
.lang select option { background: var(--bg); color: var(--ink); }

/* Live / Eco mode toggle */
.mode-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  font: 700 12px/1 var(--font);
  letter-spacing: 0.02em;
  color: var(--ink);
  transition: border-color 0.2s, opacity 0.2s, background-color 0.2s;
}
.mode-btn:hover { border-color: var(--accent); }
.mode-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.mode-btn svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.mode-btn[data-mode='live'] .icon-eco,
.mode-btn[data-mode='eco'] .icon-live { display: none; }
.mode-btn[data-mode='eco'] { background: rgba(0, 0, 0, 0.18); }

/* Eco mode: pulsing dots while hearing a phrase / waiting for its transcript */
.pending {
  display: flex;
  gap: 0.28em;
  height: 1.2em;
  align-items: center;
  margin: 0 0 0.45em;
}
.pending i {
  width: 0.28em;
  height: 0.28em;
  border-radius: 50%;
  background: var(--ink-soft);
  animation: dot 1.1s var(--ease) infinite;
}
.pending i:nth-child(2) { animation-delay: 0.15s; }
.pending i:nth-child(3) { animation-delay: 0.3s; }
.pending.hearing i { background: var(--accent); }
@keyframes dot {
  0%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-0.18em); }
}
body.is-eco .caret { display: none; }

.icon-btn,
.color-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: var(--muted);
  transition: color 0.2s, background-color 0.2s;
}
.icon-btn:hover,
.color-btn:hover,
.color-btn[aria-expanded='true'] { color: var(--ink); background: color-mix(in srgb, var(--ink) 8%, transparent); }
.icon-btn svg,
.mic svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn.flash { color: var(--accent); }

/* Background color picker */
.color-pick { position: relative; margin-left: 2px; }
.color-btn .dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: 0 0 0 2px var(--ink);
  transition: background-color 0.6s var(--ease);
}
.color-pop {
  position: absolute;
  right: -8px;
  bottom: calc(100% + 22px);
  display: grid;
  grid-template-columns: repeat(6, 28px);
  gap: 10px;
  padding: 14px;
  background: var(--menu);
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
  animation: pop-in 0.2s var(--ease);
}
.color-pop[hidden] { display: none; }
@keyframes pop-in { from { opacity: 0; transform: translateY(6px) scale(0.98); } }
.color-pop :focus-visible { outline-color: #fff; }
.color-pop button,
.color-custom {
  position: relative;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  transition: transform 0.15s var(--ease), box-shadow 0.15s;
}
.color-pop button { background: var(--c); }
.color-pop button:hover,
.color-custom:hover { transform: scale(1.12); }
.color-pop button[aria-pressed='true'],
.color-custom.is-current { box-shadow: 0 0 0 2px var(--menu), 0 0 0 4px #fff; }
.color-custom {
  display: block;
  cursor: pointer;
  background: conic-gradient(#e5484d, #f5a623, #f5e663, #46a758, #3e8ed0, #8e4ec6, #e5484d);
}
.color-custom:has(input:focus-visible) { outline: 2px solid #fff; outline-offset: 3px; }
.color-custom input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  cursor: pointer;
}
/* A custom color shows as a dot inside the rainbow ring */
.color-custom.is-current::after {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: 0 0 0 2px var(--menu);
  pointer-events: none;
}

/* Mic button */
.mic {
  position: relative;
  width: 72px;
  height: 72px;
  margin: -24px 6px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  isolation: isolate;
  color: var(--pop-ink);
  background: var(--pop);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  transition: transform 0.25s var(--ease), background-color 0.4s, color 0.4s, box-shadow 0.4s;
}
.mic svg { width: 26px; height: 26px; grid-area: 1 / 1; transition: opacity 0.25s, transform 0.35s var(--ease); }
.mic .icon-stop { opacity: 0; transform: scale(0.4); fill: currentColor; stroke: none; }
.mic:hover { transform: scale(1.06); }
.mic:active { transform: scale(0.96); }

.mic-ring,
.mic-halo {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  z-index: -1;
}
.mic-ring {
  inset: -7px;
  border: 1.5px solid var(--accent);
  opacity: 0;
  transform: scale(calc(1 + var(--level) * 0.55));
  transition: opacity 0.3s, transform 0.08s linear;
}
.mic-halo {
  inset: -14px;
  background: radial-gradient(circle, var(--glow), transparent 68%);
  opacity: 0;
  transform: scale(calc(1 + var(--level) * 1.1));
  transition: opacity 0.3s, transform 0.08s linear;
}

.mic[data-state='live'] .icon-mic { opacity: 0; transform: scale(0.4); }
.mic[data-state='live'] .icon-stop { opacity: 1; transform: none; }
.mic[data-state='live'] .mic-ring { opacity: calc(0.35 + var(--level) * 1.3); }
.mic[data-state='live'] .mic-halo { opacity: calc(0.15 + var(--level) * 2); }

.mic[data-state='connecting'] .mic-ring { opacity: 1; animation: pulse 1.1s var(--ease) infinite; }
@keyframes pulse {
  0% { transform: scale(0.95); opacity: 0.9; }
  100% { transform: scale(1.45); opacity: 0; }
}

.mic[data-state='finalizing'] .mic-ring {
  opacity: 1;
  border-color: transparent;
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.mic[data-state='error'] { animation: shake 0.45s var(--ease); }
@keyframes shake {
  20%, 60% { translate: -5px 0; }
  40%, 80% { translate: 5px 0; }
}

/* Toast */
.notice {
  position: fixed;
  left: 50%;
  bottom: 118px;
  z-index: 46;
  transform: translate(-50%, 8px);
  max-width: min(480px, 100% - 32px);
  padding: 10px 16px;
  font: 700 12px/1.4 var(--font);
  letter-spacing: 0.04em;
  text-align: center;
  color: var(--pop-ink);
  background: var(--pop);
  border-radius: 8px;
  opacity: 0;
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
}
.notice.show { opacity: 1; transform: translate(-50%, 0); }
.notice.error { color: var(--pop-error); }

/* ---------- Responsive ---------- */

@media (max-width: 560px) {
  .lyr-head { padding-top: 20px; }
  .lyr-cover { width: 48px; height: 48px; }
  .dock { bottom: 18px; gap: 6px; padding: 8px 10px; }
  .mic { width: 62px; height: 62px; margin: -20px 2px; }
  .icon-btn,
  .color-btn { width: 32px; height: 32px; }
  .lang select { padding: 8px 24px 8px 10px; }
  .lang::after { right: 9px; }
  .mode-btn { padding: 8px 9px; }
  .mode-btn .mode-label { display: none; }
  .notice { bottom: 100px; }
}

@media (prefers-reduced-motion: reduce) {
  .w.enter { animation-name: fade !important; animation-duration: 0.3s; animation-delay: 0s; }
  .color-pop { animation: none; }
  .mic[data-state='connecting'] .mic-ring,
  .mic[data-state='finalizing'] .mic-ring { animation-duration: 2s; }
}
@keyframes fade { from { opacity: 0; } }
