/* ── DESIGN TOKENS ─────────────────────────────────────────────────────────── */
:root {
  --brand:        #4f46e5;
  --brand-hover:  #4338ca;
  --brand-alpha:  rgba(79, 70, 229, 0.1);
  --brand-alpha2: rgba(79, 70, 229, 0.06);

  --text:         #0f172a;
  --text-muted:   #64748b;
  --text-subtle:  #94a3b8;

  --border:       #e2e8f0;
  --bg:           #ffffff;
  --bg-subtle:    #f8fafc;
  --bg-hover:     #f1f5f9;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 24px 64px rgba(15,23,42,0.18), 0 8px 24px rgba(15,23,42,0.08);

  --r-sm:   8px;
  --r-md:   12px;
  --r-lg:   18px;
  --r-full: 9999px;
}

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

/* ── PAGE ─────────────────────────────────────────────────────────────────── */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  max-width: 740px;
  margin: 64px auto;
  padding: 0 28px;
  background: #f9fafb;
  color: var(--text);
  line-height: 1.8;
  font-size: 16px;
}

h1 {
  font-size: 2rem;
  font-weight: 750;
  letter-spacing: -0.03em;
  line-height: 1.2;
  margin-bottom: 16px;
  color: var(--text);
}
h2 {
  font-size: 1.2rem;
  font-weight: 650;
  margin-top: 48px;
  margin-bottom: 10px;
  letter-spacing: -0.01em;
  color: var(--text);
}
p  { margin-bottom: 20px; color: #1e293b; }
li { margin-bottom: 10px; color: #1e293b; }

blockquote {
  border-left: 3px solid var(--brand);
  margin: 32px 0;
  padding: 14px 24px;
  color: #475569;
  font-style: italic;
  background: var(--brand-alpha2);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
}

/* Highlighted block while reading */
.hvsr-active {
  background: var(--brand-alpha2);
  border-radius: var(--r-sm);
  outline: 2px solid rgba(79, 70, 229, 0.22);
  outline-offset: 5px;
  transition: background 0.25s ease, outline-color 0.25s ease;
}

/* ── HINT CHIP ── */
#hint {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--text);
  color: #fff;
  font-family: inherit;
  font-size: 12px;
  padding: 8px 14px;
  border-radius: var(--r-full);
  opacity: 0.75;
  box-shadow: var(--shadow-sm);
  user-select: none;
  pointer-events: none;
}

/* ── OVERLAY ─────────────────────────────────────────────────────────────── */
#popup-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 9999;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 16px;
}
#popup-overlay.open { display: flex; }

/* ── PANEL ─────────────────────────────────────────────────────────────────  */
#popup {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  width: 316px;
  background: var(--bg);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: panel-in 0.28s cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes panel-in {
  from { opacity: 0; transform: translateY(-10px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0)     scale(1);    }
}

/* ── HEADER ── */
#popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}
#popup-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}
#popup-brand-icon {
  width: 30px;
  height: 30px;
  background: var(--brand);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 14px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(79,70,229,0.35);
}
#btn-close {
  width: 28px;
  height: 28px;
  border-radius: var(--r-full);
  border: none;
  background: var(--bg-subtle);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
#btn-close:hover { background: var(--bg-hover); color: var(--text); }

/* ── GENRE ── */
#genre-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
#genre-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 5px;
}
#genre-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: var(--r-full);
  background: var(--brand-alpha);
  color: var(--brand);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
#ai-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: var(--r-full);
  background: #f0fdf4;
  color: #16a34a;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
#genre-reden {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ── CONTROLS ── */
#controls-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.control-row {
  display: grid;
  grid-template-columns: 90px 1fr;
  align-items: center;
  gap: 10px;
}
.control-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
#popup select {
  width: 100%;
  padding: 7px 28px 7px 10px;
  border-radius: var(--r-sm);
  border: 1.5px solid var(--border);
  font-size: 12.5px;
  font-family: inherit;
  color: var(--text);
  background-color: var(--bg);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2394a3b8' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#popup select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-alpha);
}
#popup select:hover { border-color: #c4c4d8; }

/* ── PROGRESS ── */
#progress-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
#progress-bar-track {
  height: 5px;
  background: var(--border);
  border-radius: var(--r-full);
  overflow: hidden;
  margin-bottom: 7px;
}
#progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--brand) 0%, #818cf8 100%);
  border-radius: var(--r-full);
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
#progress-label {
  font-size: 11px;
  color: var(--text-subtle);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ── PLAYBACK ── */
#playback-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#btn-play {
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--r-md);
  border: none;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  background: var(--text);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  letter-spacing: -0.01em;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}
#btn-play:hover:not(:disabled) { background: #1e293b; }
#btn-play:active:not(:disabled) { transform: scale(0.98); }
#btn-play:disabled { opacity: 0.4; cursor: not-allowed; }

.secondary-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
#btn-pause,
#btn-stop {
  padding: 10px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s, transform 0.1s, opacity 0.15s;
}
#btn-pause {
  background: var(--bg-subtle);
  color: var(--text);
  border: 1.5px solid var(--border);
}
#btn-pause:hover:not(:disabled) { background: var(--bg-hover); }
#btn-stop {
  background: #fef2f2;
  color: #dc2626;
  border: 1.5px solid #fecaca;
}
#btn-stop:hover:not(:disabled)  { background: #fee2e2; }
#btn-pause:active:not(:disabled),
#btn-stop:active:not(:disabled) { transform: scale(0.97); }
#btn-pause:disabled,
#btn-stop:disabled  { opacity: 0.35; cursor: not-allowed; }

/* ── FEEDBACK: waveform + status ── */
#feedback-section {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  min-height: 50px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
#waveform {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 22px;
  opacity: 0;
  transition: opacity 0.3s ease;
}
#waveform.active { opacity: 1; }
#waveform span {
  display: block;
  width: 3px;
  background: var(--brand);
  border-radius: 2px;
  animation: wave 1.1s ease-in-out infinite;
}
#waveform span:nth-child(1) { height: 7px;  animation-delay: 0s;    }
#waveform span:nth-child(2) { height: 14px; animation-delay: 0.15s; }
#waveform span:nth-child(3) { height: 20px; animation-delay: 0.30s; }
#waveform span:nth-child(4) { height: 14px; animation-delay: 0.45s; }
#waveform span:nth-child(5) { height: 7px;  animation-delay: 0.60s; }
@keyframes wave {
  0%, 100% { transform: scaleY(0.4); opacity: 0.5; }
  50%       { transform: scaleY(1);   opacity: 1;   }
}
#status {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.5;
}

/* ── SUMMARY ── */
#btn-summary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: calc(100% - 32px);
  margin: 12px 16px 0;
  padding: 10px;
  border-radius: var(--r-sm);
  border: 1.5px dashed var(--border);
  font-size: 12.5px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  background: transparent;
  color: var(--text-muted);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
#btn-summary:hover:not(:disabled) {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-alpha);
}
#btn-summary:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── FOOTER ── */
#popup-footer {
  padding: 12px 16px 14px;
}
#shortcuts-hint {
  font-size: 10.5px;
  color: var(--text-subtle);
  text-align: center;
  line-height: 2;
  margin-bottom: 10px;
}
#shortcuts-hint kbd {
  font-family: inherit;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
}
#link-options {
  display: block;
  width: 100%;
  text-align: center;
  font-size: 11.5px;
  color: var(--text-subtle);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  font-family: inherit;
  transition: color 0.15s;
}
#link-options:hover { color: var(--text-muted); }

/* ── OPTIONS PANEL ── */
#options-panel {
  display: none;
  margin: 0 16px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 14px;
  background: var(--bg-subtle);
}
#options-panel label {
  font-size: 10.5px;
  font-weight: 700;
  display: block;
  margin-bottom: 5px;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
#options-panel input {
  width: 100%;
  padding: 8px 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 12px;
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  margin-bottom: 12px;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
#options-panel input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-alpha);
}
#btn-save-keys {
  width: 100%;
  padding: 9px;
  background: var(--text);
  color: #fff;
  border: none;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}
#btn-save-keys:hover { background: #1e293b; }
#save-msg {
  font-size: 12px;
  color: #16a34a;
  font-weight: 600;
  margin-top: 8px;
  text-align: center;
}

/* ── FOCUS STYLES (WCAG 2.1 AA) ── */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 3px;
  border-radius: 4px;
}
