/* AI&I World Desk — engine (home page) */
:root {
  --font-head: "Space Grotesk", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-body: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --indigo: #6366f1;
  --purple: #a855f7;
  --indigo-soft: #818cf8;
  --purple-soft: #c084fc;
  --pink: #f472b6;
  --radius: 1rem;
  --gap: 0.75rem;
}

/* Dark is the engine default */
:root,
:root[data-theme="dark"] {
  --bg: #090919;
  --panel: #15152e;
  --panel-glass: rgba(21, 21, 46, 0.72);
  --panel-2: #1d1d3d;
  --text: #f1f2ff;
  --muted: #b9bde0;
  --line: rgba(129, 140, 248, 0.28);
  --accent: #a5b4fc;
  --accent-strong: #818cf8;
  --on-accent: #0b0b1f;
  --user-bubble: #312e81;
  --user-text: #f5f5ff;
  --bot-bubble: #1f1f42;
  --coral: #ff9b8f;
  --focus: #f9a8d4;
  --tile-text: #ffffff;
  --glow-1: rgba(99, 102, 241, 0.55);
  --glow-2: rgba(168, 85, 247, 0.45);
  --glow-3: rgba(244, 114, 182, 0.35);
  --link: #c7d2fe;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f4f4ff;
  --panel: #ffffff;
  --panel-glass: rgba(255, 255, 255, 0.82);
  --panel-2: #eef0ff;
  --text: #16163a;
  --muted: #4a4e78;
  --line: rgba(79, 70, 229, 0.22);
  --accent: #4338ca;
  --accent-strong: #4f46e5;
  --on-accent: #ffffff;
  --user-bubble: #4338ca;
  --user-text: #ffffff;
  --bot-bubble: #f1f1fd;
  --coral: #b9382c;
  --focus: #be185d;
  --tile-text: #ffffff;
  --glow-1: rgba(99, 102, 241, 0.32);
  --glow-2: rgba(168, 85, 247, 0.26);
  --glow-3: rgba(244, 114, 182, 0.22);
  --link: #4338ca;
  color-scheme: light;
}

/* Text size: sm is the default, each step is bigger */
html { font-size: 100%; }
html[data-font-size="md"] { font-size: 112.5%; }
html[data-font-size="lg"] { font-size: 125%; }
html[data-font-size="xl"] { font-size: 137.5%; }

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.55;
  min-height: 100vh;
  min-height: 100svh;
  position: relative;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
h1, h2, h3 { font-family: var(--font-head); line-height: 1.15; margin: 0; }
p { margin: 0; }
a { color: var(--link); }
button, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 0.1875rem solid var(--focus); outline-offset: 0.125rem; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 1rem; top: -4rem; z-index: 50; background: var(--panel); color: var(--text); padding: 0.5rem 0.75rem; border-radius: 0.5rem; }
.skip:focus { top: 1rem; }

/* Vibrant background glow — never dimmed by a scrim */
.glow {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(40rem 28rem at 12% -6%, var(--glow-1), transparent 70%),
    radial-gradient(36rem 26rem at 92% 4%, var(--glow-2), transparent 70%),
    radial-gradient(44rem 30rem at 55% 108%, var(--glow-3), transparent 72%);
}
.nav, main, .foot { position: relative; z-index: 1; }

/* ---------- Nav ---------- */
.nav {
  position: sticky;
  top: 0;
  z-index: 20;
  width: 100%;
  background-color: var(--panel);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .nav {
    background-color: var(--panel-glass);
    -webkit-backdrop-filter: blur(14px) saturate(140%);
    backdrop-filter: blur(14px) saturate(140%);
  }
}
.nav-row {
  width: min(100% - 2rem, 83.75rem);
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem 1.25rem;
  padding: 0.55rem 0;
}
.brand { display: inline-flex; align-items: center; gap: 0.6rem; text-decoration: none; color: var(--text); min-width: 0; }
.brand-mark {
  display: inline-grid; place-items: center;
  width: 2.25rem; height: 2.25rem; border-radius: 0.7rem;
  background: #4f46e5; background: linear-gradient(135deg, #4f46e5, #7e22ce 55%, #be185d);
  color: #fff; font-family: var(--font-head); font-weight: 700; font-size: 1.1rem;
  box-shadow: 0 0.4rem 1.2rem rgba(99, 102, 241, 0.45);
}
.brand-name { display: flex; flex-direction: column; line-height: 1.05; }
.brand-top { font-family: var(--font-head); font-weight: 700; font-size: 0.8rem; letter-spacing: 0.08em; color: var(--muted); }
.brand-bottom { font-family: var(--font-head); font-weight: 700; font-size: 1.05rem; }
.nav-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.25rem; }
.nav-links a {
  text-decoration: none; color: var(--text); font-weight: 600; font-size: 0.92rem;
  padding: 0.4rem 0.7rem; border-radius: 999px;
}
.nav-links a:hover { background: var(--panel-2); }
.nav-links a[aria-current="page"] { background: var(--panel-2); box-shadow: inset 0 0 0 1px var(--line); }
.prefs { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; justify-content: center; }
.size-group { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 0.15rem; background: var(--panel); }
.size-btn {
  border: 0; background: transparent; cursor: pointer; border-radius: 999px;
  min-width: 2rem; height: 2rem; padding: 0 0.35rem; font-family: var(--font-head); font-weight: 700; color: var(--text);
  line-height: 1;
}
.size-btn.s1 { font-size: 0.8rem; }
.size-btn.s2 { font-size: 0.95rem; }
.size-btn.s3 { font-size: 1.1rem; }
.size-btn.s4 { font-size: 1.25rem; }
.size-btn[aria-pressed="true"] { background: #4f46e5; color: #ffffff; }
.theme-btn {
  width: 2.4rem; height: 2.4rem; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; display: inline-grid; place-items: center; color: var(--text);
}
.theme-btn svg { width: 1.2rem; height: 1.2rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.theme-btn .i-moon { fill: currentColor; stroke: none; }
:root[data-theme="dark"] .theme-btn .i-moon { display: none; }
:root[data-theme="light"] .theme-btn .i-sun { display: none; }

/* ---------- Hero (compact) ---------- */
.hero {
  width: min(100% - 3rem, 83.75rem);
  margin: 0 auto;
  padding: 1.1rem 0 0.9rem;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 0.55rem;
}
.chip {
  display: inline-flex; align-items: center; gap: 0.45rem;
  font-size: 0.8rem; font-weight: 600; color: var(--text);
  padding: 0.28rem 0.75rem; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line);
}
.chip .dot { width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--pink); box-shadow: 0 0 0.6rem var(--pink); }
.hero h1 {
  font-size: clamp(1.75rem, 1.1rem + 2.6vw, 2.75rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  max-width: 100%;
  overflow-wrap: anywhere;
}
.grad {
  color: var(--purple-soft);
  background: linear-gradient(90deg, var(--indigo-soft), var(--purple-soft) 50%, var(--pink));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
:root[data-theme="light"] .grad {
  color: #7e22ce;
  background: linear-gradient(90deg, #4338ca, #7e22ce 55%, #be185d);
  -webkit-background-clip: text;
  background-clip: text;
}
.subline { font-size: 0.98rem; color: var(--text); max-width: 46rem; }
.subline strong { font-weight: 700; }
.hero-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem; }
.chip-link {
  text-decoration: none; font-weight: 600; font-size: 0.88rem; color: var(--text);
  padding: 0.38rem 0.85rem; border-radius: 999px; background: var(--panel); border: 1px solid var(--line);
}
.chip-link:hover { border-color: var(--accent-strong); }

/* ---------- Board ---------- */
.board {
  width: min(100% - 3rem, clamp(56.25rem, 66vw, 83.75rem));
  margin: 0 auto 1.5rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--gap);
  align-items: start;
}
.card {
  position: relative;
  min-width: 0;
  background-color: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: 0 1rem 2.5rem rgba(10, 10, 40, 0.28);
  overflow: hidden;
}
@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .card {
    background-color: var(--panel-glass);
    -webkit-backdrop-filter: blur(16px) saturate(140%);
    backdrop-filter: blur(16px) saturate(140%);
  }
}
.card::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 0.2rem;
  background: linear-gradient(90deg, var(--indigo), var(--purple), var(--pink));
}
.top-card::before { background: linear-gradient(90deg, var(--pink), var(--purple)); }
.short-card::before { background: linear-gradient(90deg, var(--indigo-soft), var(--purple-soft)); }
.detail-card::before { background: linear-gradient(90deg, var(--purple), var(--indigo)); }
.card h2 { font-size: 1.1rem; font-weight: 700; }
.card-sub { color: var(--muted); font-size: 0.86rem; margin-top: 0.15rem; }

/* Heights below are only a first-paint fallback; engine.js measures the real window and sets the live height. */
.chat-slot { min-width: 0; height: clamp(26rem, 72svh, 38rem); }
.chat-card { height: 100%; display: flex; flex-direction: column; gap: 0.6rem; container-type: inline-size; container-name: chat; }

/* Side cards: flex columns with a measured max-height; only .card-scroll scrolls, the rest stays pinned */
.side { display: flex; flex-direction: column; }
.side > * { flex: none; }
.side > .pill { align-self: center; }
@media (min-width: 700px) { .side > .pill { align-self: flex-start; } }
.side > .card-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.card-scroll > *, .log > * { flex: none; }
.more-cue {
  font-size: 0.78rem; font-weight: 700; color: var(--text); text-align: center;
  padding: 0.2rem 0.6rem; margin: 0.35rem auto 0; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line); width: max-content; max-width: 100%;
}
.more-cue[hidden] { display: none; }
.chat-card > .more-cue { margin-top: -0.25rem; flex: none; }
.chat-card > * { flex: none; }
.chat-card > .log { flex: 1 1 auto; }

/* phones: center aligned except lists */
.side { text-align: center; }
.side ol, .side dl { text-align: left; }

@media (min-width: 700px) {
  .board { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .chat-slot { grid-column: 1 / -1; grid-row: 1; height: clamp(24rem, 62svh, 34rem); }
  .top-card { grid-column: 1; grid-row: 2; }
  .short-card { grid-column: 2; grid-row: 2; }
  .detail-card { grid-column: 3; grid-row: 2; }
  .side { text-align: left; }
}
@media (min-width: 1100px) {
  .board { grid-template-columns: 1.36fr 1.06fr 0.98fr 0.98fr; }
  .chat-slot { grid-column: 1; grid-row: 1; height: clamp(22rem, 100svh - 21rem, 38rem); }
  .top-card { grid-column: 2; grid-row: 1; }
  .short-card { grid-column: 3; grid-row: 1; }
  .detail-card { grid-column: 4; grid-row: 1; }
  .hero { text-align: center; }
}

/* ---------- Chat card ---------- */
.chat-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 0.5rem; row-gap: 0.1rem; }
.chat-head h2 { min-width: 0; overflow-wrap: anywhere; font-size: 1.02rem; }
.chat-actions .icon-btn { width: 2.1rem; height: 2.1rem; }
.chat-head .card-sub { grid-column: 1 / -1; margin-top: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-actions { display: flex; align-items: center; gap: 0.35rem; }
#fullBtn .i-collapse { display: none; }
#fullBtn[aria-pressed="true"] .i-expand { display: none; }
#fullBtn[aria-pressed="true"] .i-collapse { display: block; }
#fullBtn[aria-pressed="true"] { background: #4f46e5; color: #ffffff; border-color: transparent; }
.icon-btn {
  width: 2.25rem; height: 2.25rem; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); display: inline-grid; place-items: center; cursor: pointer;
}
.icon-btn svg { width: 1.1rem; height: 1.1rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.pill-btn {
  border-radius: 999px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 0.4rem 0.8rem; font-weight: 600; font-size: 0.85rem; cursor: pointer; min-height: 2.25rem;
}
.pill-btn[aria-pressed="true"] { background: #4f46e5; color: #ffffff; border-color: transparent; }
.count-chip {
  align-self: flex-start; font-size: 0.78rem; font-weight: 600; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line); padding: 0.15rem 0.6rem; border-radius: 999px;
}
.log {
  position: relative;
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 0.6rem; padding: 0.15rem 0.1rem 0.25rem;
}
.msg { max-width: 92%; padding: 0.65rem 0.85rem; border-radius: 0.9rem; font-size: 0.95rem; overflow-wrap: anywhere; min-width: 0; }
.msg p + p, .msg ul + p, .msg p + ul, .msg ol + p, .msg p + ol { margin-top: 0.5rem; }
.msg ul, .msg ol { margin: 0.35rem 0 0; padding-left: 1.2rem; text-align: left; }
.msg li + li { margin-top: 0.2rem; }
.msg.user { align-self: flex-end; background: var(--user-bubble); color: var(--user-text); border-bottom-right-radius: 0.3rem; }
.msg.bot { align-self: flex-start; background: var(--bot-bubble); color: var(--text); border: 1px solid var(--line); border-bottom-left-radius: 0.3rem; }
.msg.bot a { color: var(--link); }
.msg .h { font-family: var(--font-head); font-weight: 700; }
.msg .try { color: var(--muted); font-size: 0.88rem; }
.msg.error { border-color: var(--coral); color: var(--coral); background: var(--panel); }
.msg .sources { margin-top: 0.6rem; padding-top: 0.5rem; border-top: 1px solid var(--line); font-size: 0.82rem; }
.msg .sources p { font-weight: 700; color: var(--muted); }
.msg .sources ol { margin-top: 0.2rem; }

/* Thinking indicator */
.thinking { display: flex; flex-direction: column; gap: 0.35rem; }
.dots { display: inline-flex; gap: 0.35rem; align-items: center; height: 1.1rem; }
.dots span { width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--accent-strong); animation: pulse 1.2s infinite ease-in-out; }
.dots span:nth-child(2) { animation-delay: 0.2s; background: var(--purple-soft); }
.dots span:nth-child(3) { animation-delay: 0.4s; background: var(--pink); }
.think-note { font-size: 0.82rem; color: var(--muted); }
@keyframes pulse { 0%, 80%, 100% { transform: scale(0.6); opacity: 0.45; } 40% { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .dots span { animation: none; opacity: 1; transform: none; }
}

/* Composer */
.composer { display: flex; flex-direction: column; gap: 0.35rem; }
.composer-row { display: flex; flex-direction: column; gap: 0.5rem; }
.composer-btns { display: flex; gap: 0.5rem; justify-content: flex-end; align-items: center; }
textarea#chatInput {
  width: 100%; min-width: 0; resize: none; border-radius: 0.8rem; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); padding: 0.6rem 0.75rem; line-height: 1.4;
  min-height: 2.6rem; max-height: 8.5rem; overflow-y: hidden; font-size: 1rem;
}
textarea#chatInput::placeholder { color: var(--muted); opacity: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
textarea#chatInput.scrolls { overflow-y: auto; }
.mic-btn {
  width: 2.6rem; height: 2.6rem; flex: 0 0 auto; border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); display: inline-grid; place-items: center; cursor: pointer;
}
.mic-btn[hidden] { display: none; }
.mic-btn svg { width: 1.2rem; height: 1.2rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.mic-btn[aria-pressed="true"] { background: var(--pink); color: #2a0718; border-color: transparent; box-shadow: 0 0 0 0.25rem rgba(244, 114, 182, 0.3); }
.send-btn {
  flex: 0 0 auto; min-width: 4.6rem; height: 2.6rem; padding: 0 1rem; border-radius: 999px; border: 0; cursor: pointer;
  background: #4f46e5; background: linear-gradient(135deg, #4f46e5, #7e22ce); color: #ffffff; font-weight: 700;
}
.send-btn:disabled { opacity: 0.6; cursor: progress; }
.mic-status { font-size: 0.8rem; color: var(--muted); }
.mic-status[hidden], .form-error[hidden] { display: none; }
.form-error { font-size: 0.85rem; color: var(--coral); font-weight: 600; }
.chat-note { font-size: 0.74rem; color: var(--muted); }

@container chat (min-width: 18.5rem) {
  .composer-row { flex-direction: row; align-items: flex-end; }
  .composer-row textarea#chatInput { flex: 1 1 auto; }
}

/* Full page overlay */
.chat-card.is-full {
  position: fixed; z-index: 40;
  top: calc(0.75rem + env(safe-area-inset-top)); bottom: calc(0.75rem + env(safe-area-inset-bottom));
  left: calc(0.75rem + env(safe-area-inset-left)); right: calc(0.75rem + env(safe-area-inset-right));
  height: auto; background-color: var(--panel);
}
body.chat-full { overflow: hidden; }
body.chat-full main { z-index: 30; }

/* ---------- Side cards ---------- */
.pill {
  display: inline-block; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  padding: 0.2rem 0.65rem; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
}
.tile {
  margin-top: 0.7rem; border-radius: 0.85rem; padding: 0.9rem; min-height: 5.25rem;
  background: linear-gradient(135deg, #4f46e5, #9333ea 60%, #db2777);
  color: var(--tile-text);
  display: flex; flex-direction: column; justify-content: flex-end; gap: 0.2rem;
}
.tile-kind { font-size: 0.74rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: #ffffff; }
.tile-title { font-family: var(--font-head); font-size: 1.08rem; font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; color: #ffffff; }
.score-row { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; margin-top: 0.75rem; }
.score-label { font-size: 0.82rem; font-weight: 600; color: var(--muted); }
.score-val { font-family: var(--font-head); font-size: 1.6rem; font-weight: 700; }
.why { font-size: 0.88rem; color: var(--text); margin-top: 0.2rem; overflow-wrap: anywhere; }

.gauge-row { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.6rem; }
.gauge { width: 3.5rem; height: 3.5rem; flex: 0 0 auto; }
.g-track { fill: none; stroke: var(--panel-2); stroke-width: 7; }
.g-fill { fill: none; stroke: var(--purple-soft); stroke-width: 7; stroke-linecap: round; }
:root[data-theme="light"] .g-fill { stroke: #7e22ce; }
.g-text { font-family: var(--font-head); font-size: 15px; font-weight: 700; fill: var(--text); }
.rank-note { font-size: 0.84rem; color: var(--muted); text-align: left; }
.short-list { list-style: none; margin: 0.7rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.short-list button {
  width: 100%; text-align: left; display: flex; align-items: center; gap: 0.5rem; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 0.65rem; padding: 0.45rem 0.6rem; color: var(--text);
}
.short-list button[aria-pressed="true"] { border-color: var(--accent-strong); box-shadow: inset 0 0 0 1px var(--accent-strong); }
.short-list .rank { font-family: var(--font-head); font-weight: 700; color: var(--accent); min-width: 1.2rem; }
.short-list .name { flex: 1 1 auto; min-width: 0; font-size: 0.88rem; font-weight: 600; overflow-wrap: anywhere; }
.short-list .sc { font-family: var(--font-head); font-weight: 700; font-size: 0.9rem; }

.detail-empty { font-size: 0.88rem; color: var(--muted); margin-top: 0.5rem; }
.detail-empty[hidden], .short-empty[hidden] { display: none; }
.short-empty { font-size: 0.84rem; color: var(--muted); margin-top: 0.6rem; font-style: italic; }
.fields { margin: 0.6rem 0 0; display: flex; flex-direction: column; gap: 0.45rem; }
.fields div { min-width: 0; }
.fields dt { font-size: 0.74rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.fields dd { margin: 0.05rem 0 0; font-size: 0.88rem; overflow-wrap: anywhere; }
.guide-link { display: inline-block; margin-top: 0.75rem; font-weight: 700; font-size: 0.88rem; }
.guide-link[hidden] { display: none; }
.next-step { margin-top: 0.85rem; padding-top: 0.7rem; border-top: 1px solid var(--line); }
.next-step[hidden] { display: none; }
.next-step h3 { font-size: 0.95rem; }
.next-step p { font-size: 0.88rem; margin-top: 0.25rem; overflow-wrap: anywhere; }

.foot {
  width: min(100% - 3rem, 83.75rem); margin: 0 auto; padding: 0.5rem 0 calc(1.5rem + env(safe-area-inset-bottom));
  text-align: center; font-size: 0.78rem; color: var(--muted);
}
