:root {
  --bg: #0d0b1a;
  --bg2: #16132b;
  --card: #1d1a36;
  --accent: #ff5722;
  --accent2: #ffb300;
  --text: #f4f1ff;
  --muted: #a39fc4;
  --bot: #241f44;
  --user: #ff5722;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Mukta", "Catamaran", system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #2a1f4d 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  background: rgba(13, 11, 26, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid #2c2750;
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 30px; }
.topbar h1 { font-family: "Catamaran"; font-size: 22px; margin: 0; }
.tagline { margin: 0; font-size: 12px; color: var(--muted); }
.badge {
  font-size: 11px; padding: 4px 10px; border-radius: 20px;
  background: #2c2750; color: var(--accent2); border: 1px solid #3a3568;
}
.badge.tts { cursor: pointer; font-size: 14px; line-height: 1; padding: 5px 9px; }
.badge.tts:hover { background: var(--accent); border-color: var(--accent); }
.a-bubble.speakable { cursor: pointer; }
.a-bubble.speakable:hover { background: #2b2550; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.userbox { display: flex; align-items: center; gap: 8px; }
.userpic { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; border: 1px solid #3a3568; }
.username { font-size: 13px; color: var(--text); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout { background: #221d42; border: 1px solid #332d5c; color: var(--muted); border-radius: 16px; padding: 5px 12px; font-size: 12px; cursor: pointer; font-family: inherit; }
.logout:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---- login gate ---- */
.login-gate { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.login-gate[hidden] { display: none; }
.login-card {
  background: var(--card); border: 1px solid #2c2750; border-radius: 20px;
  padding: 40px 32px; max-width: 420px; text-align: center;
}
.login-logo { font-size: 48px; }
.login-card h2 { font-family: "Catamaran"; margin: 12px 0 8px; }
.login-card p { color: var(--muted); font-size: 14px; line-height: 1.6; margin: 0 0 22px; }
#gsiButton { display: flex; justify-content: center; }
.login-error { color: #ff7676 !important; margin-top: 14px !important; }

#app[hidden] { display: none; }

/* ---- newest-on-top feed ---- */
.feed {
  flex: 1; overflow-y: auto; padding: 8px 20px 30px;
  display: flex; flex-direction: column; gap: 22px;
  max-width: 920px; width: 100%; margin: 0 auto;
}
.welcome { background: var(--bot); border-radius: 16px; padding: 14px 16px; line-height: 1.6; font-size: 15px; }
.query-block { border-bottom: 1px solid #221d42; padding-bottom: 20px; display: flex; flex-direction: column; gap: 12px; }
.q-row { display: flex; justify-content: flex-end; }
.q-bubble { background: var(--user); color: #fff; padding: 10px 16px; border-radius: 16px; border-bottom-right-radius: 4px; font-size: 15px; max-width: 80%; }
.a-row { display: flex; flex-direction: column; gap: 10px; }
.a-bubble { background: var(--bot); padding: 12px 16px; border-radius: 16px; border-bottom-left-radius: 4px; font-size: 15px; line-height: 1.55; align-self: flex-start; max-width: 80%; }

.chat {
  flex: 1; overflow-y: auto; padding: 20px;
  display: flex; flex-direction: column; gap: 16px;
  max-width: 920px; width: 100%; margin: 0 auto;
}
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 80%; padding: 12px 16px; border-radius: 16px;
  line-height: 1.55; font-size: 15px;
}
.msg.bot .bubble { background: var(--bot); border-bottom-left-radius: 4px; }
.msg.user .bubble { background: var(--user); color: #fff; border-bottom-right-radius: 4px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; margin-top: 6px; width: 100%; }
.card {
  background: var(--card); border-radius: 14px; overflow: hidden;
  cursor: pointer; border: 1px solid #2c2750; transition: transform .15s, border-color .15s;
  display: flex; flex-direction: column;
}
.card:hover { transform: translateY(-4px); border-color: var(--accent); }
.poster { width: 100%; aspect-ratio: 2/3; object-fit: cover; background: #110f22; }
.poster.placeholder { display: flex; align-items: center; justify-content: center; font-size: 40px; color: #3a3568; }
.card-body { padding: 10px 12px; }
.card-title { font-weight: 700; font-size: 14px; line-height: 1.3; }
.card-meta { font-size: 12px; color: var(--muted); margin-top: 4px; display: flex; gap: 8px; flex-wrap: wrap; }
.rating { color: var(--accent2); font-weight: 700; }
.card-genres { font-size: 11px; color: var(--muted); margin-top: 6px; }
.play-pill {
  margin-top: 8px; font-size: 12px; font-weight: 700; color: var(--accent);
  display: inline-flex; align-items: center; gap: 4px;
}

.chips-row { display: flex; align-items: center; gap: 8px; padding: 0 20px 10px; max-width: 920px; margin: 0 auto; width: 100%; box-sizing: border-box; }
.chips { display: flex; gap: 8px; flex-wrap: nowrap; overflow-x: auto; flex: 1; min-width: 0; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  font-size: 13px; padding: 7px 14px; border-radius: 20px; cursor: pointer;
  background: #221d42; border: 1px solid #332d5c; color: var(--text);
  white-space: nowrap; flex: 0 0 auto; animation: chipIn .35s ease;
}
.chip:hover { background: var(--accent); border-color: var(--accent); }
.chip-refresh {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
  background: #221d42; border: 1px solid #332d5c; color: var(--text);
  font-size: 16px; line-height: 1; display: flex; align-items: center; justify-content: center;
}
.chip-refresh:hover { background: var(--accent); border-color: var(--accent); }
.chip-refresh:active { transform: rotate(180deg); transition: transform .3s ease; }
@keyframes chipIn { from { opacity: 0; transform: scale(.85); } to { opacity: 1; transform: scale(1); } }

.composer {
  display: flex; gap: 10px; padding: 14px 20px 20px;
  max-width: 920px; margin: 0 auto; width: 100%;
  position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%);
}
.composer.top {
  position: sticky; top: 0; bottom: auto; z-index: 9;
  padding: 16px 20px 12px;
  background: linear-gradient(var(--bg) 70%, transparent);
}
#input {
  flex: 1; padding: 14px 18px; border-radius: 30px; border: 1px solid #332d5c;
  background: var(--bg2); color: var(--text); font-size: 15px; font-family: inherit;
}
#input:focus { outline: none; border-color: var(--accent); }
#sendBtn {
  padding: 0 24px; border: none; border-radius: 30px; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 15px; font-family: inherit;
}
#sendBtn:disabled { opacity: .5; }

.mic {
  flex: 0 0 auto; width: 48px; height: 48px; border-radius: 50%;
  border: 1px solid #332d5c; background: var(--bg2); color: var(--text);
  font-size: 20px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s, transform .15s;
}
.mic:hover { background: #221d42; }
.mic.listening {
  background: var(--accent); border-color: var(--accent); color: #fff;
  animation: pulse 1.3s infinite;
}
.mic.hidden { display: none; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(255,87,34,.55); }
  70%  { box-shadow: 0 0 0 14px rgba(255,87,34,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,87,34,0); }
}
.mic-hint {
  max-width: 920px; margin: -6px auto 0; padding: 0 20px 8px; width: 100%;
  font-size: 13px; color: var(--accent2); text-align: center;
}

.thinking-box { border: 1px solid #332d5c; }
.thinking-text { margin-bottom: 8px; }
.thinking-meta { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.thinking-dots { display: inline-flex; gap: 4px; }
.latency-line { color: var(--accent2); font-size: 12px; font-weight: 700; }
.latency-line.final { margin-top: 8px; color: var(--muted); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.dot:nth-child(2){animation-delay:.2s} .dot:nth-child(3){animation-delay:.4s}
@keyframes blink { 0%,60%,100%{opacity:.2} 30%{opacity:1} }

.modal { position: fixed; inset: 0; background: rgba(5,4,12,.85); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal[hidden] { display: none; }
.modal-card { background: var(--card); border-radius: 16px; width: min(860px, 100%); padding: 20px; position: relative; }
.modal-card h3 { margin: 0 30px 14px 0; }
.close { position: absolute; top: 14px; right: 16px; background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; }
.preview-card { width: min(680px, 100%); }
.preview-meta { margin: -6px 0 12px; color: var(--accent2); font-size: 13px; }
.preview-narrative { color: var(--text); line-height: 1.65; margin: 0; font-size: 16px; }
.preview-actions { display: flex; gap: 8px; margin-top: 18px; justify-content: flex-end; flex-wrap: wrap; }
.player-wrap { position: relative; aspect-ratio: 16/9; border-radius: 10px; overflow: hidden; background: #000; }
.player-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.player-fallback {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; text-align: center;
  padding: 24px; color: var(--text); background: #11101f;
}
.player-fallback p { margin: 0; max-width: 32ch; color: var(--muted); }
.player-fallback[hidden] { display: none; }
.player-tabs { display: flex; gap: 8px; margin-top: 12px; align-items: center; }
.tab { padding: 8px 16px; border-radius: 8px; border: 1px solid #332d5c; background: #221d42; color: var(--text); cursor: pointer; font-size: 13px; font-family: inherit; text-decoration: none; }
.tab.active { background: var(--accent); border-color: var(--accent); }
.tab.link { margin-left: auto; color: var(--accent2); }
.disclaimer { font-size: 11px; color: var(--muted); margin: 12px 0 0; }

@media (max-width: 600px) {
  .cards { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .bubble { max-width: 90%; }
}
