/* ==========================================================================
   CATLOGIC v3 — Clean, Minimal, Modern, Bold & Typographic
   Fonts: Space Grotesk / Plus Jakarta Sans / JetBrains Mono
   Palette: #FAFAF8 bone, #0F0F0F ink, #FF3B1D vermillion
   ========================================================================== */

:root {
  /* Golden-ratio type scale, based on 14px: 8.65 → 14 → 22.65 → 36.65 */
  --phi: 1.618;
  --type-xs: 0.5406rem;
  --type-base: 0.875rem;
  --type-lg: 1.4158rem;
  --type-xl: 2.2907rem;
  --type-hero: 3.7064rem;
  --bg: #FAFAF8;
  --bg-card: #FFFFFF;
  --bg-muted: #F2F0EB;
  --ink: #0F0F0F;
  --ink2: #5A5852;
  --ink3: #8E8B82;
  --border: #E2E0D8;
  --border-strong: #0F0F0F;
  --red: #FF3B1D;
  --green: #10B981;
  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Plus Jakarta Sans', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --r-xs: 3px; --r-sm: 5px; --r-md: 8px; --r-lg: 13px; --r-pill: 9999px;
  --shadow-b: 0 12px 36px rgba(15, 15, 15, 0.07);
  --shadow-b-sm: 0 5px 18px rgba(15, 15, 15, 0.055);
  --ease: 0.2s cubic-bezier(.16,1,.3,1);
}

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

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--type-base);
  line-height: 1.618;
  height: 100vh; width: 100vw;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ── Top Bar ── */
.app-shell { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  height: 64px; padding: 0 1.618rem;
  background: rgba(250, 250, 248, 0.94);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(18px);
}

.topbar-brand { display: flex; align-items: center; gap: 0.618rem; }
.logo-text {
  font-family: var(--font-display);
  font-size: 1.25rem; font-weight: 800; line-height: 1;
  letter-spacing: -0.055em; text-transform: uppercase;
}
.logo-sep { font-family: var(--font-mono); font-size: var(--type-base); color: var(--red); }
.logo-tagline {
  font-family: var(--font-mono);
  font-size: var(--type-xs); font-weight: 700;
  letter-spacing: 0.14em; color: var(--ink2);
  text-transform: uppercase;
}

.topbar-menu-btn {
  display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  background: transparent; border: 1px solid var(--border);
  border-radius: var(--r-pill); cursor: pointer;
  box-shadow: none; transition: all var(--ease);
}
.topbar-menu-btn:hover { background: var(--ink); color: white; border-color: var(--ink); transform: rotate(8deg); }
.topbar-menu-btn i { width: 16px; height: 16px; }

/* ── 2-Panel Layout ── */
.panels {
  display: grid; grid-template-columns: 38.2fr 61.8fr;
  height: calc(100vh - 64px); overflow: hidden;
}

/* ── Ask Panel (Left) ── */
.ask-panel {
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg);
}

.chat-area {
  flex: 1; overflow-y: auto;
  padding: 2.618rem 1.618rem 1.618rem; display: flex; flex-direction: column; gap: 1rem;
}

.welcome-card {
  padding: 0; background: transparent;
  border: none; border-radius: 0; box-shadow: none;
  max-width: 31rem;
}
.welcome-card.is-leaving {
  pointer-events: none;
  animation: welcomeExit 160ms cubic-bezier(.4, 0, .2, 1) forwards;
}
@keyframes welcomeExit {
  to { opacity: 0; transform: translateY(-6px); }
}
.welcome-card::before {
  content: "01 / PROMPT";
  display: block;
  margin-bottom: 1rem;
  color: var(--red);
  font-family: var(--font-mono);
  font-size: var(--type-xs);
  font-weight: 800;
  letter-spacing: 0.16em;
}
.welcome-title {
  font-family: var(--font-display);
  font-size: clamp(var(--type-lg), 3.2vw, var(--type-xl)); font-weight: 800;
  letter-spacing: -0.065em; line-height: 1;
}
.welcome-sub { font-size: var(--type-base); color: var(--ink2); margin-top: 0.875rem; max-width: 28rem; }
.welcome-sub kbd {
  font-family: var(--font-mono); font-size: 0.72rem;
  padding: 1px 5px; background: var(--bg-muted);
  border: 1px solid var(--border); border-radius: var(--r-xs);
}

/* Chat bubbles */
.chat-msg { display: flex; gap: 0.6rem; max-width: 90%; animation: fadeUp .15s ease-out; }
.chat-msg.user { align-self: flex-end; flex-direction: row-reverse; }
.chat-msg.ai { align-self: flex-start; }

.msg-avatar {
  width: 28px; height: 28px; border-radius: var(--r-sm);
  border: 1.5px solid var(--border-strong);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; box-shadow: var(--shadow-b-sm);
}
.chat-msg.user .msg-avatar { background: var(--ink); color: #fff; }
.chat-msg.ai .msg-avatar { background: var(--red); color: #fff; }
.msg-avatar i { width: 14px; height: 14px; }

.msg-bubble {
  background: var(--bg-card); border: 1.5px solid var(--border-strong);
  border-radius: var(--r-md); padding: 0.7rem 0.9rem;
  box-shadow: var(--shadow-b-sm);
  font-size: 0.82rem; line-height: 1.45;
}

@keyframes fadeUp { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:translateY(0); } }

/* Composer */
.composer {
  padding: 1rem 1.618rem 1.618rem;
  border-top: none;
  background: linear-gradient(to top, var(--bg) 72%, transparent);
}
.composer-inner {
  background: var(--bg-card); border: 1px solid var(--ink);
  border-radius: var(--r-lg); padding: 0.875rem;
  box-shadow: var(--shadow-b); display: flex; flex-direction: column; gap: 0.618rem;
}
.composer-inner textarea {
  width: 100%; background: transparent; border: none; outline: none;
  font-family: var(--font-display); font-size: var(--type-base); font-weight: 600;
  color: var(--ink); resize: none; min-height: 58px; max-height: 160px; line-height: 1.5;
}

.composer-actions {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 0.3rem; border-top: 1px solid var(--border);
}
.composer-left-tools { display: flex; align-items: center; gap: 0.35rem; }

.chip-btn {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--bg-muted); cursor: pointer; transition: all var(--ease);
}
.chip-btn:hover { border-color: var(--border-strong); background: var(--bg-card); }
.chip-btn i { width: 14px; height: 14px; }

.toggle-chip { cursor: pointer; }
.toggle-chip input { display: none; }
.toggle-label {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--bg-muted); color: var(--ink3); transition: all var(--ease);
}
.toggle-label i { width: 14px; height: 14px; }
.toggle-chip input:checked + .toggle-label {
  background: var(--ink); color: #fff; border-color: var(--ink);
}

.send-btn {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-family: var(--font-display); font-size: var(--type-base); font-weight: 800;
  padding: 0.55rem 1.25rem; border-radius: var(--r-pill);
  background: var(--ink); color: #fff; border: 1.5px solid var(--ink);
  box-shadow: none; cursor: pointer; transition: all var(--ease);
}
.send-btn:hover { background: var(--red); border-color: var(--red); transform: translateY(-1px); }
.send-btn i { width: 14px; height: 14px; }

/* Image preview chip */
.img-chip {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 3px 8px; background: var(--bg-muted);
  border: 1px solid var(--border); border-radius: var(--r-xs);
}
.img-chip img { width: 22px; height: 22px; object-fit: cover; border-radius: 2px; }
.img-chip-name { font-family: var(--font-mono); font-size: 0.68rem; font-weight: 600; }
.img-chip-x {
  background: none; border: none; cursor: pointer; padding: 0;
  display: flex; align-items: center;
}
.img-chip-x i { width: 12px; height: 12px; }

/* ── Cinema Panel (Right) ── */
.cinema-panel {
  display: flex; flex-direction: column;
  padding: 1.618rem; gap: 0.875rem; overflow-y: auto;
  background: var(--bg);
}

.player-frame {
  position: relative; width: 100%; aspect-ratio: 16/9;
  background: #EDEAE2; border: 1px solid var(--ink);
  border-radius: var(--r-lg); box-shadow: var(--shadow-b);
  overflow: hidden; display: flex; align-items: center; justify-content: center;
}

.vid { width: 100%; height: 100%; object-fit: contain; background: #EDEAE2; }

.placeholder {
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
  text-align: center; color: #888;
}
.ph-icon {
  width: 42px; height: 42px; border-radius: 50%;
  background: #1a1a1a; border: 1px solid #333;
  display: flex; align-items: center; justify-content: center;
  color: var(--red);
}
.ph-icon i { width: 18px; height: 18px; }
.ph-text { font-size: 0.78rem; color: #666; }

/* Loading Overlay (coherent typographic) */
.loading-overlay {
  position: absolute; inset: 0;
  background: rgba(10,10,10,0.92); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; z-index: 10;
}
.loader-box {
  background: var(--ink); color: #fff;
  border: 1.5px solid #333; border-radius: var(--r-md);
  padding: 1.5rem 2rem; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
  max-width: 280px; width: 85%;
}
.loader-spinner {
  width: 24px; height: 24px;
  border: 2.5px solid #333; border-top-color: var(--red);
  border-radius: 50%; animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-title {
  font-family: var(--font-display); font-size: 0.9rem; font-weight: 800;
  letter-spacing: -0.02em;
}
.loader-sub { font-size: 0.72rem; color: #999; }
.loader-track {
  width: 100%; height: 4px; background: #333;
  border-radius: var(--r-pill); overflow: hidden; margin-top: 0.15rem;
}
.loader-fill { height: 100%; width: 0%; background: var(--red); transition: width 0.2s ease; }
.loader-pct { font-family: var(--font-mono); font-size: 0.68rem; font-weight: 800; color: #aaa; }

/* Transport controls */
.transport {
  display: flex; align-items: center; gap: 0.4rem;
  background: transparent; border: none;
  border-radius: 0; padding: 0.35rem 0;
  box-shadow: none;
}

.t-btn {
  background: transparent; border: none; color: var(--ink); cursor: pointer;
  padding: 3px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-xs);
}
.t-btn:hover { background: var(--bg-muted); }
.t-btn.active { color: var(--red); }
.t-btn i { width: 15px; height: 15px; }

.scrubber-wrap { flex: 1; display: flex; align-items: center; }
.scrubber-wrap input[type="range"] {
  width: 100%; accent-color: var(--red); cursor: pointer;
}

.timecode { font-family: var(--font-mono); font-size: 0.68rem; font-weight: 700; }

.speed-grp {
  display: flex; background: var(--bg-muted);
  border-radius: var(--r-xs); padding: 1px;
}
.spd {
  background: transparent; border: none;
  font-family: var(--font-mono); font-size: 0.62rem; font-weight: 700;
  padding: 1px 4px; cursor: pointer;
}
.spd.active { background: var(--ink); color: #fff; border-radius: 2px; }

/* Download row */
.dl-row { display: flex; align-items: center; gap: 0.4rem; }

.dl-btn {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-family: var(--font-display); font-size: var(--type-base); font-weight: 800;
  padding: 0.55rem 1rem; border-radius: var(--r-pill);
  background: var(--ink); color: #fff; border: 1.5px solid var(--ink);
  box-shadow: var(--shadow-b-sm); cursor: pointer; transition: all var(--ease);
}
.dl-btn:disabled { opacity: 0.35; cursor: not-allowed; box-shadow: none; }
.dl-btn:hover:not(:disabled) { transform: translate(-1px,-1px); box-shadow: var(--shadow-b); }
.dl-btn i { width: 14px; height: 14px; }

.more-wrap { position: relative; }
.more-btn {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: var(--r-pill);
  cursor: pointer; box-shadow: none; transition: all var(--ease);
}
.more-btn:hover { transform: translate(-1px,-1px); box-shadow: var(--shadow-b); }
.more-btn i { width: 14px; height: 14px; }

.more-menu {
  position: absolute; bottom: calc(100% + 6px); left: 0;
  background: var(--bg-card); border: 1.5px solid var(--border-strong);
  border-radius: var(--r-md); box-shadow: 0 8px 24px rgba(0,0,0,0.1);
  min-width: 170px; z-index: 50; overflow: hidden;
}
.menu-item {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 0.75rem; background: transparent; border: none;
  border-bottom: 1px solid var(--border); color: var(--ink);
  font-family: var(--font-body); font-size: 0.75rem; font-weight: 700;
  text-align: left; cursor: pointer; width: 100%; transition: background var(--ease);
}
.menu-item:last-child { border-bottom: none; }
.menu-item:hover:not(:disabled) { background: var(--bg-muted); }
.menu-item:disabled { opacity: 0.35; cursor: not-allowed; }
.menu-item i { width: 13px; height: 13px; }

.status-badge-wrap {
  display: flex; align-items: center; gap: 0.3rem;
  margin-left: auto;
}
.status-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--ink3);
}
.status-dot.rendering { background: var(--red); animation: pulse 1s infinite; }
.status-dot.completed { background: var(--green); }
.status-dot.error { background: var(--red); }
.status-label {
  font-family: var(--font-mono); font-size: var(--type-xs); font-weight: 800;
  text-transform: uppercase; color: var(--ink2);
}

@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:0.3; } }

/* Narration card */
.narration-box {
  background: var(--bg-card); border: 1.5px solid var(--border-strong);
  border-radius: var(--r-md); padding: 0.75rem;
  box-shadow: var(--shadow-b-sm);
}
.narr-header { display: flex; justify-content: space-between; align-items: center; }
.narr-title { font-family: var(--font-display); font-size: 0.75rem; font-weight: 800; text-transform: uppercase; }
.narr-voice {
  font-family: var(--font-mono); font-size: 0.62rem; font-weight: 700;
  background: var(--bg-muted); padding: 1px 5px; border-radius: var(--r-xs);
}
.narr-body { font-size: 0.78rem; line-height: 1.4; color: var(--ink2); max-height: 100px; overflow-y: auto; margin-top: 0.3rem; }

/* Self-heal card */
.heal-box {
  display: flex; align-items: flex-start; gap: 0.5rem;
  padding: 0.6rem 0.75rem; background: #ECFDF5;
  border: 1.5px solid #059669; border-radius: var(--r-sm);
  font-size: 0.78rem;
}
.heal-ico { color: #059669; width: 16px; height: 16px; flex-shrink: 0; margin-top: 2px; }
.heal-desc { font-size: 0.72rem; color: #047857; margin-top: 2px; }

/* ── Settings Modal ── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15,15,15,0.55); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-card {
  background: var(--bg-card); border: 1px solid var(--ink);
  border-radius: var(--r-lg); box-shadow: 0 24px 80px rgba(0,0,0,0.16);
  width: 90%; max-width: 520px; max-height: 85vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.9rem 1.2rem; border-bottom: 1.5px solid var(--border-strong);
}
.modal-title { font-family: var(--font-display); font-size: var(--type-lg); font-weight: 800; letter-spacing: -0.045em; }
.modal-x {
  background: transparent; border: none; cursor: pointer;
  padding: 4px; border-radius: var(--r-xs); color: var(--ink2);
}
.modal-x:hover { color: var(--ink); background: var(--bg-muted); }

.modal-tabs {
  display: flex; background: var(--bg-muted);
  padding: 0 1rem; border-bottom: 1px solid var(--border); gap: 0.3rem;
}
.mtab {
  background: transparent; border: none;
  border-bottom: 2px solid transparent;
  font-family: var(--font-body); font-size: 0.75rem; font-weight: 700;
  color: var(--ink3); padding: 0.5rem 0.65rem; cursor: pointer;
}
.mtab.active { color: var(--ink); border-bottom-color: var(--ink); background: var(--bg-card); }

.modal-pane {
  display: none; padding: 1rem 1.2rem;
  flex-direction: column; gap: 0.75rem; overflow-y: auto;
}
.modal-pane.active { display: flex; }

.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field label {
  font-family: var(--font-mono); font-size: var(--type-xs); font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink2);
}
.sel {
  width: 100%; padding: 0.72rem 0.75rem;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-family: var(--font-body); font-size: var(--type-base); font-weight: 700;
  color: var(--ink); outline: none; cursor: pointer;
}

.divider { border: none; border-top: 1px solid var(--border); margin: 0.3rem 0; }

.key-header { display: flex; align-items: center; justify-content: space-between; }
.key-status { font-family: var(--font-mono); font-size: 0.65rem; font-weight: 700; color: var(--red); }

.key-row { display: flex; gap: 0.35rem; }
.key-row input {
  flex: 1; padding: 0.42rem 0.6rem;
  border: 1.5px solid var(--border-strong); border-radius: var(--r-sm);
  font-family: var(--font-mono); font-size: 0.76rem; outline: none;
}
.save-key-btn {
  font-family: var(--font-body); font-size: 0.75rem; font-weight: 700;
  padding: 0.4rem 0.7rem; background: var(--ink); color: #fff;
  border: 1.5px solid var(--ink); border-radius: var(--r-sm); cursor: pointer;
}

.refresh-btn {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-size: 0.72rem; font-weight: 700;
  padding: 0.3rem 0.6rem; background: var(--bg-muted);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  cursor: pointer; align-self: flex-start;
}
.refresh-btn i { width: 12px; height: 12px; }
.refresh-btn:disabled { cursor: wait; opacity: 0.58; }
.refresh-btn.loading i { animation: historySpin 0.8s linear infinite; }
@keyframes historySpin { to { transform: rotate(360deg); } }

.gemini-intro {
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-muted);
}
.gemini-mark {
  font-family: var(--font-display);
  font-size: var(--type-md);
  font-weight: 800;
  letter-spacing: -0.035em;
}
.gemini-intro p {
  margin-top: 0.25rem;
  color: var(--ink2);
  font-size: 0.76rem;
  line-height: 1.5;
}
.history-error {
  padding: 1rem;
  color: var(--red);
  font-size: 0.75rem;
  text-align: center;
}

/* Preset / History cards */
.card-stack { display: flex; flex-direction: column; gap: 0.5rem; }

.preset-card, .history-card {
  background: var(--bg-card); border: 1.5px solid var(--border-strong);
  border-radius: var(--r-md); padding: 0.7rem 0.85rem;
  box-shadow: var(--shadow-b-sm); cursor: pointer;
  transition: all var(--ease); display: flex; flex-direction: column; gap: 0.2rem;
}
.preset-card:hover, .history-card:hover {
  transform: translate(-1px,-1px); box-shadow: var(--shadow-b);
}
.card-title { font-family: var(--font-display); font-size: 0.82rem; font-weight: 800; }
.card-desc { font-size: 0.72rem; color: var(--ink2); }
.card-tags { display: flex; flex-wrap: wrap; gap: 0.2rem; margin-top: 0.15rem; }
.tag-badge {
  background: var(--bg-muted); color: var(--ink);
  font-family: var(--font-mono); font-size: 0.6rem; font-weight: 700;
  padding: 1px 4px; border-radius: 2px; border: 1px solid var(--border-strong);
}

/* Toast */
.toasts {
  position: fixed; bottom: 1.2rem; right: 1.2rem;
  display: flex; flex-direction: column; gap: 0.4rem; z-index: 1100;
}
.toast {
  background: var(--bg-card); border: 1.5px solid var(--border-strong);
  border-radius: var(--r-sm); padding: 0.5rem 0.85rem;
  box-shadow: var(--shadow-b); font-size: 0.78rem; font-weight: 700;
  display: flex; align-items: center; gap: 0.4rem;
  transition: opacity 0.2s ease;
}
.toast i { width: 14px; height: 14px; flex-shrink: 0; }
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--ink); }

/* ── Editorial interaction and responsive polish ── */
button:focus-visible, textarea:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 3px;
}

::selection { background: var(--red); color: white; }

@media (max-width: 980px) {
  body { overflow: auto; }
  .app-shell { min-height: 100vh; height: auto; }
  .panels {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(520px, 61.8vh) auto;
    height: auto;
    overflow: visible;
  }
  .ask-panel { border-right: none; border-bottom: 1px solid var(--border); }
  .cinema-panel { min-height: 520px; }
}

@media (max-width: 620px) {
  .topbar { height: 56px; padding: 0 1rem; }
  .logo-tagline, .logo-sep { display: none; }
  .panels { grid-template-rows: minmax(470px, 66vh) auto; }
  .chat-area { padding: 1.618rem 1rem 1rem; }
  .composer { padding: 0.875rem 1rem 1rem; }
  .cinema-panel { padding: 1rem; }
  .transport { flex-wrap: wrap; }
  .scrubber-wrap { order: 3; flex-basis: 100%; }
  .speed-grp { margin-left: auto; }
  .modal-card { width: calc(100% - 1.25rem); max-height: 92vh; }
}

/* CodeMirror hidden */
.CodeMirror { height: 0 !important; display: none !important; }

/* ==========================================================================
   CATLOGIC v6 — Unlumen-inspired restrained dark editorial system
   Adapted principles: layered near-black surfaces, hairline borders,
   square-grid texture, pill controls, spacious typography, subtle motion.
   ========================================================================== */

:root {
  --bg: #09090A;
  --bg-card: #101011;
  --bg-muted: #171719;
  --ink: #F5F5F2;
  --ink2: #A4A4A0;
  --ink3: #6D6D69;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --red: #FF4A2F;
  --green: #4ADE80;
  --shadow-b: 0 24px 80px rgba(0, 0, 0, 0.34);
  --shadow-b-sm: 0 12px 36px rgba(0, 0, 0, 0.22);
}

body {
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(255,255,255,0.024) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.024) 1px, transparent 1px);
  background-size: 48px 48px;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 76% 8%, rgba(255, 74, 47, 0.075), transparent 28rem),
    linear-gradient(to bottom, transparent 70%, rgba(0,0,0,0.26));
  z-index: -1;
}

.topbar {
  height: 72px;
  margin: 0;
  padding: 0 1.618rem;
  background: rgba(9, 9, 10, 0.82);
  border-bottom-color: var(--border);
  backdrop-filter: blur(24px) saturate(135%);
}

.logo-text { color: var(--ink); letter-spacing: -0.065em; }
.logo-sep { color: var(--red); }
.logo-tagline { color: var(--ink3); }

.topbar-menu-btn {
  background: rgba(255,255,255,0.025);
  color: var(--ink2);
  border-color: var(--border-strong);
}
.topbar-menu-btn:hover {
  background: var(--ink);
  border-color: var(--ink);
  color: #09090A;
}

.panels {
  height: calc(100vh - 72px);
  grid-template-columns: minmax(360px, 0.76fr) minmax(0, 1.24fr);
  gap: 1px;
  background: var(--border);
}

.ask-panel,
.cinema-panel {
  background: rgba(9, 9, 10, 0.9);
  border: none;
}

.chat-area { padding: clamp(1.618rem, 4vw, 4.236rem) clamp(1.25rem, 3vw, 2.618rem); }

.welcome-card {
  max-width: 34rem;
  padding-top: 1rem;
}
.welcome-card::before {
  content: "CATLOGIC / 01";
  color: var(--ink3);
  letter-spacing: 0.2em;
}
.welcome-title {
  max-width: 9ch;
  color: var(--ink);
  font-size: clamp(var(--type-xl), 4.3vw, var(--type-hero));
  line-height: 0.94;
  letter-spacing: -0.075em;
}
.welcome-title::after { content: ""; color: var(--red); }
.welcome-sub { color: var(--ink2); max-width: 25rem; }
.welcome-sub kbd {
  color: var(--ink);
  background: rgba(255,255,255,0.045);
  border-color: var(--border-strong);
}

.chat-msg { max-width: 92%; }
.msg-avatar {
  border-color: var(--border-strong);
  box-shadow: none;
  background: var(--bg-muted);
}
.chat-msg.user .msg-avatar { background: var(--ink); color: #09090A; }
.chat-msg.ai .msg-avatar { background: var(--red); color: white; }
.msg-bubble {
  color: var(--ink);
  background: rgba(16,16,17,0.92);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: none;
}

.composer {
  padding: 1rem clamp(1rem, 2.5vw, 2.618rem) 1.618rem;
  background: linear-gradient(to top, var(--bg) 76%, transparent);
}
.composer-inner {
  background: rgba(16,16,17,0.92);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  box-shadow: var(--shadow-b-sm), inset 0 1px 0 rgba(255,255,255,0.025);
  backdrop-filter: blur(18px);
}
.composer-inner:focus-within {
  border-color: rgba(255, 74, 47, 0.62);
  box-shadow: 0 0 0 3px rgba(255,74,47,0.08), var(--shadow-b-sm);
}
.composer-inner textarea { color: var(--ink); }
.composer-inner textarea::placeholder { color: var(--ink3); }
.composer-actions { border-color: var(--border); }

.chip-btn,
.toggle-label {
  background: rgba(255,255,255,0.035);
  border-color: var(--border);
  color: var(--ink2);
  border-radius: 9px;
}
.chip-btn:hover { background: rgba(255,255,255,0.08); border-color: var(--border-strong); }
.toggle-chip input:checked + .toggle-label {
  background: var(--ink);
  border-color: var(--ink);
  color: #09090A;
}
.send-btn {
  background: var(--ink);
  color: #09090A;
  border-color: var(--ink);
  min-width: 92px;
  justify-content: center;
}
.send-btn:hover {
  background: var(--red);
  color: white;
  border-color: var(--red);
  box-shadow: 0 10px 32px rgba(255,74,47,0.18);
}

.img-chip { background: var(--bg-muted); border-color: var(--border); color: var(--ink); }
.img-chip-x { color: var(--ink2); }

.cinema-panel { padding: clamp(1rem, 2.4vw, 2.618rem); gap: 1rem; }
.player-frame {
  background: #050506;
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  box-shadow: var(--shadow-b), inset 0 1px 0 rgba(255,255,255,0.03);
}
.vid { background: #050506; }
.placeholder { color: var(--ink3); }
.ph-icon {
  width: 52px;
  height: 52px;
  background: rgba(255,255,255,0.035);
  border-color: var(--border);
  color: var(--ink2);
}
.ph-text { color: var(--ink3); }

.loading-overlay { background: rgba(5,5,6,0.9); }
.loader-box {
  background: rgba(16,16,17,0.96);
  border-color: var(--border-strong);
  border-radius: 16px;
  box-shadow: var(--shadow-b);
}
.loader-track { background: rgba(255,255,255,0.08); }

.transport {
  color: var(--ink);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0 0.875rem;
}
.t-btn { color: var(--ink2); }
.t-btn:hover { color: var(--ink); background: rgba(255,255,255,0.055); }
.t-btn.active { color: var(--red); }
.speed-grp { background: rgba(255,255,255,0.045); }
.spd { color: var(--ink2); }
.spd.active { background: var(--ink); color: #09090A; }
.timecode { color: var(--ink3); }

.dl-btn {
  background: var(--ink);
  color: #09090A;
  border-color: var(--ink);
  box-shadow: none;
}
.dl-btn:hover:not(:disabled) { background: var(--red); color: white; border-color: var(--red); box-shadow: none; }
.more-btn {
  background: rgba(255,255,255,0.035);
  color: var(--ink2);
  border-color: var(--border-strong);
}
.more-btn:hover { background: rgba(255,255,255,0.08); color: var(--ink); box-shadow: none; }
.more-menu {
  background: rgba(16,16,17,0.98);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-b);
  backdrop-filter: blur(20px);
}
.menu-item { color: var(--ink); border-color: var(--border); }
.menu-item:hover:not(:disabled) { background: rgba(255,255,255,0.055); }
.status-label { color: var(--ink3); }

.narration-box {
  background: rgba(16,16,17,0.86);
  border: 1px solid var(--border);
  box-shadow: none;
}
.narr-title { color: var(--ink); }
.narr-voice { background: rgba(255,255,255,0.045); color: var(--ink2); }
.narr-body { color: var(--ink2); }

.heal-box {
  background: rgba(74,222,128,0.07);
  border-color: rgba(74,222,128,0.35);
  color: #BBF7D0;
}
.heal-desc, .heal-ico { color: #86EFAC; }

.modal-backdrop {
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(12px);
}
.modal-card {
  background: rgba(16,16,17,0.98);
  border-color: var(--border-strong);
  box-shadow: 0 36px 120px rgba(0,0,0,0.62);
}
.modal-top { border-color: var(--border); }
.modal-title { color: var(--ink); }
.modal-x { color: var(--ink2); }
.modal-x:hover { color: var(--ink); background: rgba(255,255,255,0.06); }
.modal-tabs { background: rgba(255,255,255,0.025); border-color: var(--border); }
.mtab { color: var(--ink3); }
.mtab.active { color: var(--ink); border-bottom-color: var(--red); background: transparent; }
.field label { color: var(--ink3); }
.sel,
.key-row input {
  color: var(--ink);
  background: rgba(255,255,255,0.035);
  border-color: var(--border);
}
.sel option { color: var(--ink); background: #151516; }
.divider { border-color: var(--border); }
.save-key-btn { background: var(--ink); color: #09090A; border-color: var(--ink); }
.refresh-btn { color: var(--ink); background: rgba(255,255,255,0.04); border-color: var(--border); }

.preset-card,
.history-card {
  background: rgba(255,255,255,0.025);
  border: 1px solid var(--border);
  box-shadow: none;
}
.preset-card:hover,
.history-card:hover { background: rgba(255,255,255,0.055); border-color: var(--border-strong); box-shadow: none; }
.card-title { color: var(--ink); }
.card-desc { color: var(--ink2); }
.tag-badge { background: rgba(255,255,255,0.045); color: var(--ink2); border-color: var(--border); }

.toast {
  color: var(--ink);
  background: rgba(16,16,17,0.96);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-b-sm);
  backdrop-filter: blur(16px);
}

button:focus-visible, textarea:focus-visible, select:focus-visible, input:focus-visible {
  outline-color: var(--red);
}

@media (max-width: 980px) {
  .panels { background: var(--border); }
  .ask-panel { border-bottom-color: var(--border); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ==========================================================================
   CATLOGIC v7 — Unlumen-inspired light theme
   ========================================================================== */

:root {
  color-scheme: light;
  --bg: #F8F8F5;
  --bg-card: #FFFFFF;
  --bg-muted: #F0F0EB;
  --ink: #111112;
  --ink2: #62625E;
  --ink3: #92928C;
  --border: rgba(17, 17, 18, 0.09);
  --border-strong: rgba(17, 17, 18, 0.18);
  --red: #F0442B;
  --green: #159A62;
  --shadow-b: 0 24px 80px rgba(17, 17, 18, 0.09);
  --shadow-b-sm: 0 12px 36px rgba(17, 17, 18, 0.07);
}

body {
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(17,17,18,0.026) 1px, transparent 1px),
    linear-gradient(90deg, rgba(17,17,18,0.026) 1px, transparent 1px);
}
body::before {
  background:
    radial-gradient(circle at 76% 8%, rgba(240,68,43,0.07), transparent 28rem),
    linear-gradient(to bottom, transparent 74%, rgba(17,17,18,0.025));
}

.topbar {
  background: rgba(248,248,245,0.84);
  border-bottom-color: var(--border);
}
.topbar-menu-btn { background: rgba(255,255,255,0.62); color: var(--ink2); }
.topbar-menu-btn:hover { background: var(--ink); border-color: var(--ink); color: white; }

.panels { background: var(--border); }
.ask-panel,
.cinema-panel { background: rgba(248,248,245,0.9); }

.welcome-sub kbd,
.chip-btn,
.toggle-label,
.more-btn,
.refresh-btn { background: rgba(255,255,255,0.7); }
.welcome-sub kbd { color: var(--ink); }

.msg-avatar { background: var(--bg-card); }
.chat-msg.user .msg-avatar { background: var(--ink); color: white; }
.msg-bubble {
  background: rgba(255,255,255,0.88);
  border-color: var(--border);
}

.answer-message { width: min(100%, 38rem); max-width: 100%; }
.answer-bubble { width: 100%; padding: 1rem; }
.answer-eyebrow,
.answer-solution-label {
  display: block;
  color: var(--red);
  font-family: var(--font-mono);
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}
.answer-final {
  margin-top: 0.38rem;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: var(--type-md);
  font-weight: 750;
  letter-spacing: -0.025em;
  line-height: 1.32;
  white-space: pre-wrap;
}
.answer-figure {
  margin: 0.9rem 0 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-muted);
}
.answer-figure img { display: block; width: 100%; height: auto; }
.answer-figure figcaption {
  padding: 0.45rem 0.65rem;
  border-top: 1px solid var(--border);
  color: var(--ink3);
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.answer-solution {
  margin-top: 0.9rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--border);
}
.answer-solution-label { color: var(--ink3); }
.answer-solution p {
  margin-top: 0.45rem;
  color: var(--ink2);
  font-size: 0.78rem;
  line-height: 1.62;
  white-space: pre-wrap;
}

/* The composer itself carries the focus state; avoid a second box inside it. */
.composer-inner textarea:focus,
.composer-inner textarea:focus-visible {
  outline: none;
}

/* ========================================================================== 
   CATLOGIC v11 — Chat-style navigation sidebar
   ========================================================================== */

body { overflow: hidden; }

.app-shell {
  display: flex;
  flex-direction: row;
  width: 100%;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.workspace-shell {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  background: var(--bg);
}

.app-sidebar {
  position: relative;
  z-index: 30;
  display: flex;
  flex: 0 0 264px;
  flex-direction: column;
  width: 264px;
  min-width: 264px;
  height: 100vh;
  padding: 0.75rem;
  overflow: hidden;
  color: var(--ink);
  background: #F0F0EB;
  border-right: 1px solid var(--border);
  transition: width 180ms ease, min-width 180ms ease, flex-basis 180ms ease, transform 180ms ease;
}

.sidebar-head,
.sidebar-section-head,
.sidebar-settings-btn,
.new-chat-btn {
  display: flex;
  align-items: center;
}

.sidebar-head { justify-content: space-between; min-height: 38px; }
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: -0.025em;
}
.sidebar-logo {
  display: grid;
  width: 27px;
  height: 27px;
  place-items: center;
  color: white;
  background: var(--ink);
  border-radius: 8px;
  font-size: 0.72rem;
}

.sidebar-icon-btn {
  display: grid;
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  place-items: center;
  color: var(--ink2);
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
.sidebar-icon-btn:hover { color: var(--ink); background: rgba(17,17,18,0.065); }
.sidebar-icon-btn i { width: 15px; height: 15px; }

.new-chat-btn {
  width: 100%;
  gap: 0.62rem;
  margin-top: 0.75rem;
  padding: 0.68rem 0.72rem;
  color: var(--ink);
  background: rgba(255,255,255,0.72);
  border: 1px solid var(--border);
  border-radius: 11px;
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}
.new-chat-btn:hover { background: white; border-color: var(--border-strong); }
.new-chat-btn i { width: 15px; height: 15px; }

.sidebar-history {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  margin-top: 1.15rem;
}
.sidebar-section-head { justify-content: space-between; padding: 0 0.32rem 0.42rem; }
.sidebar-section-head h2 {
  color: var(--ink3);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.history-head-actions { display: flex; align-items: center; gap: 0.18rem; }
.delete-all-history-btn {
  padding: 0;
  color: var(--ink3);
  background: transparent;
  border: 0;
}
.delete-all-history-btn:hover { color: var(--red); background: rgba(255,59,29,0.08); }
.delete-all-history-btn:disabled { cursor: not-allowed; opacity: 0.3; }
.sidebar-history-list {
  min-height: 0;
  padding-right: 0.15rem;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.sidebar-history-list .history-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 28px;
  align-items: center;
  gap: 0.35rem;
  padding: 0.58rem 0.64rem;
  background: transparent;
  border: 0;
  border-radius: 9px;
  box-shadow: none;
}
.history-card-copy { min-width: 0; }
.history-delete-btn {
  display: inline-flex;
  width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  color: var(--ink3);
  background: transparent;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
}
.history-delete-btn:hover,
.history-delete-btn:focus-visible { color: var(--red); background: rgba(255,59,29,0.09); }
.history-delete-btn i { width: 13px; height: 13px; }
.history-grasp {
  color: var(--red);
  font: 800 0.6rem/1 var(--font-mono);
  white-space: nowrap;
}
.sidebar-history-list .history-card:hover { background: rgba(17,17,18,0.06); border: 0; box-shadow: none; }
.sidebar-history-list .card-title {
  overflow: hidden;
  font-size: 0.75rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-history-list .card-desc {
  overflow: hidden;
  color: var(--ink3);
  font-size: 0.66rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-footer {
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
}
.sidebar-settings-panel {
  margin-bottom: 0.55rem;
  padding: 0.7rem;
  background: rgba(255,255,255,0.76);
  border: 1px solid var(--border);
  border-radius: 11px;
  box-shadow: var(--shadow-b-sm);
}
.sidebar-settings-panel .gemini-intro { padding: 0; background: transparent; border: 0; border-radius: 0; }
.sidebar-settings-panel .gemini-mark { font-size: 0.95rem; }
.sidebar-settings-panel .gemini-intro p { font-size: 0.68rem; }
.sidebar-settings-panel .field { margin-top: 0.7rem; }
.sidebar-settings-panel .key-row { flex-direction: column; }
.sidebar-settings-panel .key-row input { width: 100%; min-width: 0; padding: 0.55rem; }
.sidebar-settings-panel .save-key-btn { width: 100%; padding: 0.5rem; }
.sidebar-settings-btn {
  width: 100%;
  gap: 0.6rem;
  padding: 0.62rem;
  color: var(--ink2);
  background: transparent;
  border: 0;
  border-radius: 9px;
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}
.sidebar-settings-btn:hover,
.sidebar-settings-btn[aria-expanded="true"] { color: var(--ink); background: rgba(17,17,18,0.06); }
.sidebar-settings-btn i { width: 15px; height: 15px; }
.sidebar-key-indicator {
  width: 7px;
  height: 7px;
  margin-left: auto;
  background: var(--red);
  border-radius: 50%;
}
.has-api-key .sidebar-key-indicator { background: var(--green); }

.refresh-btn {
  align-self: auto;
  padding: 0;
  color: var(--ink3);
  background: transparent;
  border: 0;
}
.refresh-btn:hover { background: rgba(17,17,18,0.065); }

.topbar {
  display: grid;
  grid-template-columns: 38px 1fr 38px;
  height: 64px;
  min-height: 64px;
  padding: 0 1rem;
}
.topbar-brand { justify-self: center; }
.topbar-menu-btn { justify-self: start; }
.topbar-spacer { width: 38px; height: 38px; }
.panels { height: calc(100vh - 64px); }

.sidebar-scrim { display: none; }

@media (min-width: 1121px) {
  .app-shell.sidebar-collapsed .app-sidebar {
    width: 0;
    min-width: 0;
    flex-basis: 0;
    padding-right: 0;
    padding-left: 0;
    border-right: 0;
  }
  .app-shell.sidebar-collapsed .app-sidebar > * { opacity: 0; pointer-events: none; }
}

@media (max-width: 1120px) {
  .app-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(284px, 86vw);
    min-width: min(284px, 86vw);
    transform: translateX(-102%);
    box-shadow: 22px 0 60px rgba(17,17,18,0.12);
  }
  .app-shell.sidebar-open .app-sidebar { transform: translateX(0); }
  .sidebar-scrim:not(.hidden) {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: block;
    background: rgba(17,17,18,0.28);
    border: 0;
    backdrop-filter: blur(3px);
  }
}

@media (max-width: 980px) {
  body { overflow: auto; }
  .app-shell { height: auto; min-height: 100vh; overflow: visible; }
  .workspace-shell { height: auto; min-height: 100vh; overflow: visible; }
  .panels { height: auto; }
}

@media (max-width: 620px) {
  .topbar { height: 56px; min-height: 56px; }
  .panels { height: auto; }
}

/* One control owns both sidebar states. */
.sidebar-head { justify-content: flex-start; padding-left: 2.65rem; }
.topbar-brand { grid-column: 2; }
.topbar-spacer { grid-column: 3; }
.topbar-profile-link {
  grid-column: 3;
  justify-self: end;
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  overflow: hidden;
  color: var(--ink);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 50%;
}
.topbar-profile-link:hover { border-color: var(--ink); }
.topbar-profile-link img { width: 100%; height: 100%; object-fit: cover; }
.topbar-profile-link svg { width: 16px; height: 16px; }
.topbar-profile-link:has(img:not(.hidden)) svg { display: none; }
.topbar-menu-btn {
  position: fixed;
  top: 13px;
  left: 12px;
  z-index: 45;
  justify-self: auto;
  background: rgba(255,255,255,0.76);
  backdrop-filter: blur(10px);
  transition:
    background-color 120ms ease,
    border-color 120ms ease,
    color 120ms ease;
}
.topbar-menu-btn:hover { transform: none; }

@media (max-width: 1120px) {
  .topbar-menu-btn { left: 12px; }
  .app-sidebar {
    transition: transform 160ms cubic-bezier(0.22, 1, 0.36, 1);
  }
}

@media (max-width: 620px) {
  .topbar-menu-btn { top: 9px; }
}

/* Light, quiet loading state with one playful thought at a time. */
.loading-overlay {
  background: rgba(248,248,245,0.94);
  backdrop-filter: blur(3px);
}
.loader-box {
  width: min(82%, 360px);
  max-width: 360px;
  padding: 1rem;
  gap: 0.85rem;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
.loader-dots { display: flex; align-items: center; gap: 0.34rem; }
.loader-dots span {
  width: 6px;
  height: 6px;
  background: var(--red);
  border-radius: 50%;
  animation: loaderBreathe 1.2s ease-in-out infinite;
}
.loader-dots span:nth-child(2) { animation-delay: 120ms; }
.loader-dots span:nth-child(3) { animation-delay: 240ms; }
.loader-title {
  color: var(--ink);
  font-family: var(--font-display);
  font-size: var(--type-md);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.035em;
}
.loader-title.metaphor-enter { animation: metaphorIn 220ms ease-out; }
.loader-track {
  width: min(100%, 220px);
  height: 2px;
  margin-top: 0.1rem;
  background: var(--border-strong);
  border-radius: var(--r-pill);
}
.loader-fill { background: var(--red); transition: width 260ms ease; }
@keyframes loaderBreathe {
  0%, 100% { opacity: 0.24; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-2px); }
}
@keyframes metaphorIn {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: translateY(0); }
}

/* CATLOGIC identity mark */
.sidebar-logo {
  display: block;
  width: 27px;
  height: 27px;
  object-fit: contain;
  background: transparent;
  border-radius: 0;
}
.topbar-logo-mark {
  display: block;
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  object-fit: contain;
  opacity: 1;
  transition: width 160ms ease, opacity 120ms ease;
}

.app-shell.sidebar-visible .topbar-logo-mark {
  width: 0;
  opacity: 0;
}

/* ── Three-question Logic Grasp test ── */
.test-now-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  margin-top: 1rem;
  padding: 0.72rem 1rem;
  color: #fff;
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: var(--r-pill);
  font: 700 0.875rem/1 var(--font-body);
  cursor: pointer;
  transition: transform var(--ease), background var(--ease), color var(--ease);
}
.test-now-btn:hover { transform: translateY(-2px); background: var(--red); border-color: var(--red); }
.test-now-btn:focus-visible { outline: 3px solid rgba(255,59,29,0.25); outline-offset: 3px; }
.test-now-btn svg { width: 16px; height: 16px; }

body.quiz-open { overflow: hidden; }
.quiz-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: grid;
  place-items: stretch;
  background: var(--bg);
  animation: quizReveal 180ms cubic-bezier(.16,1,.3,1);
}
.quiz-shell { display: grid; grid-template-rows: 64px 1fr; min-width: 0; min-height: 0; }
.quiz-topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  padding: 0 1.618rem;
  border-bottom: 1px solid var(--border);
  background: rgba(250,250,248,0.96);
}
.quiz-progress { display: flex; align-items: center; gap: 0.75rem; color: var(--ink3); font-size: 0.78rem; }
.quiz-level {
  padding: 0.28rem 0.58rem;
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  font-weight: 800;
}
.quiz-stopwatch {
  min-width: 5ch;
  color: var(--ink);
  font: 700 1rem/1 var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  text-align: center;
}
.quiz-exit-btn {
  justify-self: end;
  padding: 0.58rem 0.88rem;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  font-weight: 700;
  cursor: pointer;
}
.quiz-exit-btn:hover { border-color: var(--ink); }
.quiz-stage {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: clamp(1.25rem, 4vw, 4rem);
  overflow: auto;
}
.quiz-card { width: min(100%, 760px); }
.quiz-kicker {
  margin-bottom: 0.75rem;
  color: var(--red);
  font: 800 var(--type-xs)/1 var(--font-mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.quiz-card h2 {
  color: var(--ink);
  font: 700 clamp(1.75rem, 4vw, 2.8rem)/1.12 var(--font-display);
  letter-spacing: -0.045em;
}
.quiz-options { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin-top: 2rem; }
.quiz-option {
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: center;
  gap: 0.8rem;
  min-height: 68px;
  padding: 0.8rem 1rem;
  color: var(--ink);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  font: 600 0.95rem/1.45 var(--font-body);
  text-align: left;
  cursor: pointer;
  box-shadow: 0 8px 30px rgba(17,17,18,0.035);
  transition: border-color var(--ease), transform var(--ease), background var(--ease);
}
.quiz-option:hover:not(:disabled) { border-color: var(--ink); transform: translateY(-2px); }
.quiz-option:focus-visible { outline: 3px solid rgba(255,59,29,0.2); outline-offset: 2px; }
.quiz-option-letter {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  font: 800 0.75rem/1 var(--font-mono);
}
.quiz-option.is-correct { border-color: #15965e; background: #effbf5; }
.quiz-option.is-correct .quiz-option-letter { color: #fff; background: #15965e; border-color: #15965e; }
.quiz-option.is-wrong { border-color: var(--red); background: #fff3ef; }
.quiz-option.is-wrong .quiz-option-letter { color: #fff; background: var(--red); border-color: var(--red); }
.quiz-feedback {
  display: grid;
  gap: 0.3rem;
  margin-top: 1.2rem;
  padding: 1rem 1.1rem;
  border-left: 3px solid var(--ink);
  background: var(--bg-card);
  font-size: 0.88rem;
}
.quiz-feedback.is-correct { border-left-color: #15965e; }
.quiz-feedback.is-wrong { border-left-color: var(--red); }
.quiz-feedback strong { font-family: var(--font-display); font-size: 1rem; }
.quiz-feedback small { color: var(--ink3); }
.quiz-next-btn,
.quiz-error button {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
  padding: 0.72rem 1rem;
  color: #fff;
  background: var(--ink);
  border: 0;
  border-radius: var(--r-pill);
  font-weight: 800;
  cursor: pointer;
}
.quiz-next-btn svg { width: 16px; height: 16px; }
.quiz-loading,
.quiz-error { display: grid; justify-items: center; gap: 0.8rem; color: var(--ink2); text-align: center; }
.quiz-result {
  width: min(100%, 760px);
  text-align: center;
}
.quiz-result-score {
  display: block;
  color: var(--red);
  font: 700 clamp(5rem, 14vw, 9rem)/0.9 var(--font-display);
  letter-spacing: -0.08em;
}
.quiz-result h2 {
  margin: 0.9rem 0 0;
  color: var(--ink);
  font: 700 clamp(1.7rem, 4vw, 2.8rem)/1 var(--font-display);
  letter-spacing: -0.05em;
}
.quiz-result > p:not(.quiz-kicker) { margin: 0.8rem auto 0; max-width: 560px; color: var(--ink2); }
.quiz-result-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 2.2rem 0 1rem;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.quiz-result-metrics > div { padding: 1rem; }
.quiz-result-metrics > div + div { border-left: 1px solid var(--border); }
.quiz-result-metrics span { display: block; color: var(--ink3); font: 800 .6rem/1 var(--font-mono); letter-spacing: .1em; text-transform: uppercase; }
.quiz-result-metrics strong { display: block; margin-top: .55rem; font: 700 1.5rem/1 var(--font-display); }
.quiz-dots { display: flex; gap: 5px; }
.quiz-dots i { width: 6px; height: 6px; background: var(--ink); border-radius: 50%; animation: quizDot 900ms ease-in-out infinite; }
.quiz-dots i:nth-child(2) { animation-delay: 120ms; }
.quiz-dots i:nth-child(3) { animation-delay: 240ms; }

@keyframes quizReveal { from { opacity: 0; transform: scale(0.995); } to { opacity: 1; transform: scale(1); } }
@keyframes quizDot { 0%, 70%, 100% { opacity: 0.25; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-4px); } }

@media (max-width: 680px) {
  .quiz-topbar { grid-template-columns: 1fr auto; padding: 0 1rem; }
  .quiz-progress { gap: 0.4rem; }
  .quiz-progress > span:last-child { display: none; }
  .quiz-stopwatch { grid-column: 1 / -1; grid-row: 1; justify-self: center; }
  .quiz-exit-btn { grid-column: 2; grid-row: 1; }
  .quiz-options { grid-template-columns: 1fr; margin-top: 1.25rem; }
  .quiz-stage { place-items: start center; padding-top: 2rem; }
  .quiz-card h2 { font-size: 1.65rem; }
}
/* ========================================================================== 
   CATLOGIC v16 — One seamless chat with inline video replies
   ========================================================================== */

.workspace-shell { overflow: hidden; }
.panels {
  display: block;
  height: calc(100vh - 64px);
  overflow: hidden;
  background: var(--bg);
}
.ask-panel {
  width: 100%;
  height: 100%;
  border: 0;
}
.chat-area {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: clamp(1.5rem, 4vw, 3.5rem) clamp(1rem, 4vw, 2.5rem) 1.25rem;
  container-name: chat-viewport;
  container-type: size;
}
.composer {
  width: 100%;
  max-width: none;
  margin: 0;
  padding-right: clamp(1rem, 4vw, 2.5rem);
  padding-left: clamp(1rem, 4vw, 2.5rem);
}

.video-message,
.loading-message {
  width: 100%;
  max-width: 100%;
}
.video-bubble {
  width: 100%;
  max-width: none;
  padding: 0;
  overflow: hidden;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
.video-headline {
  margin: 0 0 0.85rem;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 2.6vw, 2.15rem);
  font-weight: 800;
  line-height: 1.12;
  letter-spacing: -0.05em;
}
.inline-chat-video {
  display: block;
  width: min(100%, 64rem);
  max-width: 100%;
  height: auto;
  max-height: clamp(12rem, 52vh, 36rem);
  margin-inline: auto;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  background: #F0F0EC;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-b-sm);
}

@supports (height: 1cqh) {
  .inline-chat-video {
    width: min(100%, 113.778cqh);
    max-height: 64cqh;
  }
}

.loading-bubble {
  display: flex;
  width: auto;
  align-items: center;
  gap: 0.8rem;
  padding: 0.72rem 0.9rem;
  color: var(--ink2);
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}
.loading-bubble .loader-dots { flex: 0 0 auto; }
.loading-phrase {
  font-family: var(--font-display);
  font-size: 0.88rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.loading-phrase.metaphor-enter { animation: metaphorIn 220ms ease-out; }

@media (max-width: 980px) {
  .workspace-shell { height: 100vh; min-height: 0; overflow: hidden; }
  .app-shell { height: 100vh; min-height: 0; overflow: hidden; }
  .panels { height: calc(100vh - 64px); overflow: hidden; }
}

@media (max-width: 620px) {
  .panels { height: calc(100vh - 56px); }
  .video-headline { font-size: 1.35rem; }
  .inline-chat-video { border-radius: 12px; }
}

.composer { background: linear-gradient(to top, var(--bg) 76%, transparent); }
.composer-inner {
  background: rgba(255,255,255,0.92);
  box-shadow: var(--shadow-b-sm), inset 0 1px 0 rgba(255,255,255,0.7);
}
.chip-btn:hover,
.more-btn:hover { background: var(--bg-card); }
.toggle-chip input:checked + .toggle-label {
  background: var(--ink);
  border-color: var(--ink);
  color: white;
}
.send-btn,
.dl-btn,
.save-key-btn {
  background: var(--ink);
  border-color: var(--ink);
  color: white;
}
.img-chip { background: var(--bg-muted); }

.api-key-locked {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.8rem;
  color: var(--ink);
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.api-key-locked i { width: 18px; height: 18px; flex: 0 0 auto; }
.api-key-locked div { display: grid; gap: 0.16rem; }
.api-key-locked strong { font-size: 0.75rem; }
.api-key-locked span { color: var(--ink3); font-size: 0.66rem; line-height: 1.35; }
.api-key-locked.hidden { display: none; }
.key-status { color: var(--red); }
.key-status.is-locked { color: var(--green); }
.hidden-upload { display: none; }
.history-empty {
  padding: 1rem;
  color: var(--ink3);
  font-size: 0.75rem;
  text-align: center;
}
.attached-chat-image {
  max-width: 160px;
  max-height: 100px;
  margin-top: 4px;
  border: 1px solid var(--ink);
  border-radius: 4px;
}
.toast.is-leaving { opacity: 0; }

.player-frame {
  background: #F0F0EC;
  box-shadow: var(--shadow-b), inset 0 1px 0 rgba(255,255,255,0.8);
}
.vid { background: #F0F0EC; }
.ph-icon { background: rgba(255,255,255,0.7); }

.transport { color: var(--ink); }
.t-btn:hover { color: var(--ink); background: rgba(17,17,18,0.055); }
.speed-grp { background: rgba(17,17,18,0.055); }
.spd.active { background: var(--ink); color: white; }

.more-menu {
  background: rgba(255,255,255,0.98);
  box-shadow: var(--shadow-b);
}
.menu-item:hover:not(:disabled) { background: var(--bg-muted); }

.narration-box {
  background: rgba(255,255,255,0.82);
  border-color: var(--border);
}
.narr-voice { background: var(--bg-muted); }
.heal-box {
  background: rgba(21,154,98,0.07);
  border-color: rgba(21,154,98,0.28);
  color: #0F6F49;
}
.heal-desc, .heal-ico { color: #168458; }

.modal-backdrop {
  background: rgba(17,17,18,0.38);
  backdrop-filter: blur(12px);
}
.modal-card {
  background: rgba(255,255,255,0.98);
  box-shadow: 0 36px 120px rgba(17,17,18,0.2);
}
.modal-x:hover { color: var(--ink); background: var(--bg-muted); }
.modal-tabs { background: rgba(17,17,18,0.025); }
.sel,
.key-row input {
  color: var(--ink);
  background: var(--bg);
}
.sel option { color: var(--ink); background: white; }

.preset-card,
.history-card { background: rgba(17,17,18,0.018); }
.preset-card:hover,
.history-card:hover { background: rgba(17,17,18,0.045); }
.tag-badge { background: var(--bg-muted); }

.toast {
  color: var(--ink);
  background: rgba(255,255,255,0.97);
  box-shadow: var(--shadow-b-sm);
}
