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

:root {
  --bg: #f5f0e8;
  --text: #1a1816;
  --text-dim: #8a8278;
  --input-bg: rgba(245, 240, 232, 0.92);
  --accent: #1a1816;
}

html, body {
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Georgia', serif;
  font-size: 15px;
  overflow: hidden;
  transition: background-color 6s ease;
}

.hidden {
  display: none !important;
}

/* ── Invite gate ── */
#invite-gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 100;
}

#invite-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

#invite-box p {
  color: var(--text-dim);
  font-size: 13px;
  letter-spacing: 0.04em;
}

#invite-input {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--text-dim);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  text-align: center;
  outline: none;
  padding: 6px 4px;
  width: 200px;
  letter-spacing: 0.1em;
}

#invite-error {
  color: #8a4a4a;
  font-size: 12px;
  min-height: 16px;
}

/* ── Direction gate (myself only) ── */
#direction-gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 90;
  transition: opacity 0.6s ease;
}

#direction-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

#direction-prompt {
  color: var(--text-dim);
  font-size: 13px;
  letter-spacing: 0.06em;
  font-style: italic;
  margin-bottom: 28px;
}

.direction-btn {
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  letter-spacing: 0.05em;
  cursor: pointer;
  padding: 11px 0;
  opacity: 0.55;
  transition: opacity 0.2s ease;
}

.direction-btn:hover {
  opacity: 1;
}

/* ── Recipient gate ── */
#recipient-gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 90;
  transition: opacity 0.6s ease;
}

#recipient-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

#recipient-prompt {
  color: var(--text-dim);
  font-size: 13px;
  letter-spacing: 0.06em;
  font-style: italic;
  margin-bottom: 22px;
}

.recipient-btn {
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  letter-spacing: 0.05em;
  cursor: pointer;
  padding: 7px 0;
  opacity: 0.55;
  transition: opacity 0.2s ease;
}

.recipient-btn:hover {
  opacity: 1;
}

/* ═══════════════════════════════════════
   MAIN APP — four zones, flex column
   Never overlap at any screen size
   ═══════════════════════════════════════ */

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ── Zone 1: Transport bar ── */
#track-header {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 20px 10px;
  width: 100%;
}

#track-title {
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  text-transform: uppercase;
  opacity: 0;
  transition: opacity 1s ease;
  cursor: pointer;
  white-space: nowrap;
  text-align: center;
}

#track-title.visible {
  opacity: 1;
}

#transport {
  width: min(480px, 80vw);
  display: flex;
  flex-direction: column;
  gap: 8px;
  opacity: 0;
  transition: opacity 0.8s ease;
}

#transport.visible {
  opacity: 1;
}

#scrubber {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 1px;
  background: rgba(26, 24, 22, 0.18);
  outline: none;
  cursor: pointer;
  border-radius: 0;
}

#scrubber::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text);
  cursor: pointer;
  transition: transform 0.1s ease;
}

#scrubber::-webkit-slider-thumb:hover {
  transform: scale(1.4);
}

#scrubber::-moz-range-thumb {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text);
  border: none;
  cursor: pointer;
}

#transport-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

#play-pause-btn {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 11px;
  cursor: pointer;
  letter-spacing: 0.04em;
  padding: 0;
  line-height: 1;
  opacity: 0.8;
  transition: opacity 0.2s;
}

#play-pause-btn:hover {
  opacity: 1;
}

#time-display {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.06em;
  font-family: monospace;
}

/* ── Zone 2: Lyrics ── */
#lyrics-live {
  flex: 0 0 auto;
  align-self: center;
  width: min(400px, 76vw);
  height: 0;
  opacity: 0;
  overflow-y: auto;
  scrollbar-width: none;
  text-align: center;
  font-family: 'Georgia', serif;
  font-size: 13px;
  line-height: 2;
  color: var(--text-dim);
  letter-spacing: 0.03em;
  white-space: pre-wrap;
  transition: height 0.5s ease, opacity 0.6s ease;
}

#lyrics-live::-webkit-scrollbar {
  display: none;
}

#lyrics-live.visible {
  height: clamp(72px, 18vh, 160px);
  opacity: 1;
}

/* ── Zone 3: CC rings — grows to fill remaining space ── */
#rings-zone {
  flex: 1 1 auto;
  position: relative;
  min-height: 140px;
  overflow: hidden;
}

#rings {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ── Gen status — dead centre of the rings zone ── */
#gen-status {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  text-transform: uppercase;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.6s ease;
  white-space: nowrap;
  z-index: 2;
}

#gen-status.visible {
  opacity: 1;
}

/* ── Zone 4: Conversation + Input ── */
#bottom-zone {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding-bottom: 16px;
}

#conversation {
  width: min(560px, 90vw);
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 90px;
  overflow: hidden;
  padding: 6px 0 4px;
}

.conv-line {
  font-size: 13px;
  line-height: 1.5;
  opacity: 0;
  transition: opacity 0.6s ease;
  letter-spacing: 0.02em;
}

.conv-line.visible {
  opacity: 1;
}

.conv-line.user {
  text-align: right;
  color: var(--text);
}

.conv-line.ai {
  text-align: left;
  color: var(--text-dim);
  font-style: italic;
}

#input-area {
  width: min(560px, 90vw);
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--input-bg);
  border-bottom: 1px solid var(--text-dim);
  padding: 10px 0;
}

#user-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  resize: none;
  line-height: 1.5;
  caret-color: var(--accent);
  letter-spacing: 0.02em;
  overflow-y: auto;
  max-height: 40vh;
}

#user-input::placeholder {
  color: var(--text-dim);
}

#send-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px 2px;
  transition: color 0.2s ease;
  flex-shrink: 0;
}

#send-btn:hover {
  color: var(--text);
}

#send-btn:disabled {
  opacity: 0.2;
  cursor: default;
}

#prompt-toggle {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  cursor: pointer;
  margin-top: 6px;
  opacity: 0.6;
  transition: opacity 0.2s ease;
  font-style: italic;
}

#prompt-toggle:hover {
  opacity: 1;
}

#prompt-toggle.hidden-soft {
  opacity: 0;
  pointer-events: none;
}

.conv-line.crisis {
  text-align: left;
  color: var(--text);
  font-style: normal;
  font-size: 13px;
  line-height: 1.7;
  opacity: 0;
  transition: opacity 0.8s ease;
}

.conv-line.crisis.visible {
  opacity: 1;
}

#session-dots {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 8px;
  min-height: 12px;
}

.session-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-dim);
  opacity: 0.5;
}

/* ── Spotify button (floating) ── */
#spotify-btn {
  position: fixed;
  top: 24px;
  left: 28px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  z-index: 40;
  padding: 4px;
  transition: color 0.2s ease;
  letter-spacing: 0.04em;
}

#spotify-btn:hover { color: var(--text); }
#spotify-btn.connected { color: #1db954; }

/* ── History toggle (floating) ── */
#history-toggle {
  position: fixed;
  top: 24px;
  right: 28px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  z-index: 40;
  padding: 4px;
  transition: color 0.2s ease;
}

#history-toggle:hover {
  color: var(--text);
}

/* ── History panel (overlay) ── */
#history-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 340px;
  height: 100vh;
  background: rgba(245, 240, 232, 0.98);
  border-left: 1px solid rgba(26, 24, 22, 0.1);
  z-index: 60;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 24px 16px;
  border-bottom: 1px solid rgba(26, 24, 22, 0.08);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  flex-shrink: 0;
}

#history-close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}

#history-close:hover {
  color: var(--text);
}

#history-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0 40px;
}

.history-entry {
  padding: 20px 24px;
  border-bottom: 1px solid rgba(26, 24, 22, 0.06);
}

.history-song-title {
  font-size: 13px;
  color: var(--text);
  margin-bottom: 12px;
  letter-spacing: 0.04em;
}

.history-exchanges {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.history-line {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-dim);
}

.history-line.user {
  color: rgba(26, 24, 22, 0.8);
}

.history-download {
  display: inline-block;
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  border: 1px solid rgba(26, 24, 22, 0.2);
  padding: 5px 12px;
  cursor: pointer;
  background: transparent;
  transition: color 0.2s, border-color 0.2s;
  font-family: inherit;
}

.history-download:hover {
  color: var(--text);
  border-color: rgba(26, 24, 22, 0.6);
}

#history-empty {
  padding: 40px 24px;
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
}

/* ── Lyrics overlay (tap-to-read) ── */
#lyrics-overlay {
  position: fixed;
  inset: 0;
  background: rgba(245, 240, 232, 0.97);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 40px;
}

#lyrics-content {
  max-width: 480px;
  font-size: 14px;
  line-height: 2;
  color: var(--text);
  white-space: pre-wrap;
  letter-spacing: 0.03em;
  overflow-y: auto;
  max-height: 80vh;
}

#lyrics-close {
  position: absolute;
  top: 24px;
  right: 28px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 22px;
  cursor: pointer;
}

#lyrics-close:hover {
  color: var(--text);
}
