/* Lee Kuan Yew Digital Archive — plain CSS, no framework, no CDN, no webfonts. */
:root {
  --bg: #f7f4ee;
  --surface: #fffdf8;
  --ink: #1e2024;
  --muted: #62666d;
  --line: #e2ddd2;
  --accent: #a3262a;
  --accent-ink: #fff;
  --free: #2f6f3e;
  --free-bg: #e6f1e8;
  --paid: #8a5a00;
  --paid-bg: #fbefd5;
  --warn-bg: #fff4d6;
  --err: #a3262a;
  --err-bg: #fbe5e4;
  --radius: 10px;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-read: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.55;
}
img { max-width: 100%; display: block; }
a { color: #1a5fb4; }
button { font-family: var(--font-ui); cursor: pointer; }
button:focus-visible, a:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.sr-only {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- 3-column layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 380px;
  height: 100dvh;
  transition: grid-template-columns .3s ease;
}
/* Collapsed panels: the column shrinks to 0 and the center expands.
   The rail handle (see below) slides with the panel edge. */
.layout.no-sidebar { grid-template-columns: 0 minmax(0, 1fr) 380px; }
.layout.no-panel { grid-template-columns: 300px minmax(0, 1fr) 0; }
.layout.no-sidebar.no-panel { grid-template-columns: 0 minmax(0, 1fr) 0; }
.layout.no-sidebar .sidebar { overflow: hidden; border-right: 0; visibility: hidden; }
.layout.no-panel .panel { overflow: hidden; border-left: 0; visibility: hidden; }
.sidebar, .center, .panel { min-height: 0; overflow-y: auto; }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); }
.panel { background: var(--surface); border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.center { display: flex; flex-direction: column; min-width: 0; }

/* ---------- Panel rails (collapse / reopen handles) ---------- */
.rail-btn {
  position: fixed; top: 50%; transform: translateY(-50%);
  width: 22px; height: 72px; z-index: 30;
  background: var(--surface); border: 1px solid var(--line);
  color: var(--muted); font-size: 17px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 0; cursor: pointer;
  transition: left .3s ease, right .3s ease, background .15s ease, color .15s ease;
}
.rail-btn:hover { background: #f0ece2; color: var(--ink); }
#rail-left { left: 300px; border-radius: 0 8px 8px 0; border-left: 0; }
#rail-left.closed { left: 0; }
#rail-right { right: 380px; border-radius: 8px 0 0 8px; border-right: 0; }
#rail-right.closed { right: 0; }

/* ---------- Left sidebar ---------- */
.brand { display: flex; flex-wrap: wrap; gap: 0 12px; padding: 22px 20px 8px; align-items: flex-start; }
.brand-bar { width: 4px; align-self: stretch; background: var(--accent); border-radius: 2px; }
.brand h1 { font-size: 21px; letter-spacing: .14em; margin: 0; line-height: 1.15; }
.brand-sub { margin: 2px 0 0; font-size: 11px; letter-spacing: .18em; color: var(--muted); }
.brand-tag { flex-basis: 100%; margin: 12px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }

.portrait { margin: 14px 20px 0; position: relative; }
.portrait img { width: 100%; height: auto; border-radius: 4px; }
.portrait figcaption { position: absolute; left: 10px; bottom: 8px; }
.portrait .signature { width: 110px; height: auto; filter: drop-shadow(0 0 3px rgba(255,255,255,.9)); }

.sidenav { display: flex; flex-direction: column; gap: 2px; margin: 18px 12px 0; }
.sidenav button {
  display: flex; align-items: center; gap: 10px;
  background: none; border: 0; border-radius: 8px;
  padding: 9px 12px; font-size: 14px; color: var(--ink); text-align: left;
}
.sidenav button:hover { background: #f0ece2; }
.sidenav button.active { color: var(--accent); font-weight: 600; background: #f6e9e9; }
.nav-ic { width: 18px; text-align: center; color: var(--muted); }
.sidenav button.active .nav-ic { color: var(--accent); }

.try { padding: 18px 20px 0; }
.try h2, .panel h2 {
  font-size: 11px; letter-spacing: .12em; color: var(--muted);
  margin: 0 0 10px; text-transform: uppercase;
}
.try-list { display: flex; flex-direction: column; gap: 8px; }
.try-card {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  width: 100%; text-align: left; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 11px 12px; font-size: 13.5px; line-height: 1.45; color: var(--ink);
}
.try-card:hover { border-color: var(--accent); }
.try-card .arrow { color: var(--muted); flex-shrink: 0; }
.try-card .tag {
  display: block; font-size: 11px; color: var(--paid); margin-top: 4px;
}
.try-card.out { border-style: dashed; }

.skyline { margin: 22px 20px 24px; position: relative; border-radius: 4px; overflow: hidden; }
.skyline img { width: 100%; height: 260px; object-fit: cover; filter: grayscale(1) contrast(1.05); }
.skyline blockquote {
  position: absolute; inset: auto 0 0 0; margin: 0; padding: 40px 16px 14px;
  background: linear-gradient(transparent, rgba(0,0,0,.82));
  color: #fff; font-family: var(--font-read); font-style: italic;
  font-size: 15px; line-height: 1.5;
}
.skyline blockquote p { margin: 0 0 6px; }
.skyline blockquote footer { font-family: var(--font-ui); font-style: normal; font-size: 10.5px; letter-spacing: .14em; opacity: .85; }

/* ---------- Center: top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 14px 20px 10px;
}
.mobile-brand { display: none; font-size: 12px; letter-spacing: .12em; font-weight: 700; }
.live-pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 12px; font-size: 12.5px; color: var(--muted);
}
.live-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--free); flex-shrink: 0; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.model-badge {
  font-size: 12.5px; border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 6px 12px; color: var(--ink); white-space: nowrap;
}
.status-pill {
  font-size: 12.5px; font-weight: 600; border-radius: 999px; padding: 6px 12px; white-space: nowrap;
}
.status-pill.live { background: var(--free-bg); color: var(--free); }
.status-pill.waking { background: var(--warn-bg); color: var(--paid); animation: pulse 1.6s ease-in-out infinite; }
.status-pill.down { background: var(--err-bg); color: var(--err); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }

.banner {
  margin: 0 20px 10px; padding: 11px 14px; border-radius: var(--radius);
  font-size: 14px; line-height: 1.5;
}
.banner.warn { background: var(--warn-bg); border: 1px solid #ead9a8; }
.banner.err { background: var(--err-bg); border: 1px solid #eec5c3; }
.banner button { margin-left: 6px; }

/* ---------- Center: thread ---------- */
.thread { flex: 1; overflow-y: auto; padding: 6px 20px 16px; }
.empty-state { max-width: 640px; margin: 8px auto 0; color: var(--muted); font-size: 16px; }
.empty-state p { margin: 0 0 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 8px 14px; font-size: 14px; color: var(--ink);
}
.chip:hover { border-color: var(--accent); }
.chip.out { border-style: dashed; color: var(--muted); }
.empty-note { font-size: 12.5px; margin-top: 16px; }
.linklike { background: none; border: 0; padding: 0; color: #1a5fb4; font-size: inherit; text-decoration: underline; }

.msg { max-width: 720px; margin: 0 auto 18px; }
.msg .time { font-size: 11.5px; color: var(--muted); margin-top: 5px; }
.user-msg { display: flex; flex-direction: column; align-items: flex-end; }
.user-bubble {
  background: #ece7db; border-radius: 14px 14px 4px 14px;
  padding: 11px 14px; max-width: 85%; font-size: 16px; line-height: 1.55;
}
.user-msg .time { text-align: right; }

.asst { display: flex; gap: 12px; align-items: flex-start; }
.asst .avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; flex-shrink: 0; margin-top: 2px; }
.asst .body { min-width: 0; flex: 1; }
.asst .who { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 7px; margin-bottom: 3px; }
.rag-tag { font-size: 10.5px; font-weight: 700; letter-spacing: .06em; color: var(--accent); border: 1px solid var(--accent); border-radius: 4px; padding: 1px 5px; }
.answer { font-family: var(--font-read); font-size: 18px; line-height: 1.65; }
.answer p { margin: 0 0 12px; }
.answer blockquote {
  margin: 4px 0 14px; padding: 10px 16px;
  border-left: 3px solid var(--accent); background: #faf6ee;
  font-style: italic;
}
.answer blockquote p { margin: 0; }
.cite {
  display: inline-block; min-width: 20px; height: 20px; padding: 0 4px;
  border: 1px solid var(--accent); border-radius: 5px; background: #fff;
  color: var(--accent); font-family: var(--font-ui); font-size: 11px; font-weight: 700;
  line-height: 18px; text-align: center; vertical-align: 2px; margin: 0 1px;
}
.cite:hover { background: var(--accent); color: #fff; }
.meta-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.badge { border-radius: 999px; padding: 3px 9px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.free { background: var(--free-bg); color: var(--free); }
.badge.paid { background: var(--paid-bg); color: var(--paid); }
.fallback-note { font-size: 12.5px; color: var(--muted); font-style: italic; margin-top: 6px; }
.pending { color: var(--muted); font-size: 15px; }
.pending .dots::after { content: ""; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

.error-box {
  background: var(--err-bg); border: 1px solid #eec5c3; border-radius: var(--radius);
  padding: 11px 14px; font-size: 15px; margin-top: 4px;
}
.error-box .actions { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  padding: 7px 13px; font-size: 13px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Sources */
.sources { margin-top: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.sources summary { cursor: pointer; padding: 10px 14px; font-size: 13.5px; font-weight: 600; list-style: none; display: flex; justify-content: space-between; gap: 8px; }
.sources summary::-webkit-details-marker { display: none; }
.sources summary .view-all { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.sources ol { list-style: none; margin: 0; padding: 0 6px 6px; }
.sources li {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 10px 8px; border-top: 1px solid var(--line); border-radius: 6px;
}
.sources li:target, .sources li.flash { background: #fdf3d7; }
.sources .rank { font-size: 13px; font-weight: 700; color: var(--muted); width: 20px; text-align: center; padding-top: 2px; flex-shrink: 0; }
.sources .src-main { min-width: 0; flex: 1; }
.sources .src-title { font-size: 14px; font-weight: 600; line-height: 1.4; }
.sources .src-title a { color: var(--ink); text-decoration: none; }
.sources .src-title a:hover { text-decoration: underline; }
.sources .src-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.sources .src-score { font-size: 12px; color: var(--muted); white-space: nowrap; padding-top: 3px; }
.flag {
  display: inline-block; font-size: 11px; font-weight: 600; color: var(--paid);
  background: var(--paid-bg); border-radius: 4px; padding: 1px 6px; margin: 4px 4px 0 0;
}

/* ---------- Composer ---------- */
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 12px 20px 16px; background: var(--bg);
  border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 999px;
  padding: 11px 16px; font-family: var(--font-ui); font-size: 16px; line-height: 1.45;
  background: var(--surface); color: var(--ink); max-height: 110px;
}
.composer textarea:disabled { opacity: .6; }
.counter { font-size: 11.5px; color: var(--muted); align-self: center; white-space: nowrap; }
.icon-btn, .send {
  flex-shrink: 0; width: 42px; height: 42px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 17px;
}
.icon-btn { border: 1px solid var(--line); background: var(--surface); color: var(--muted); }
.send { border: 0; background: var(--ink); color: #fff; }
.send:disabled { opacity: .45; cursor: default; }

/* ---------- Text-to-speech controls ---------- */
.listen-btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 4px 11px; font-size: 12.5px; color: var(--ink);
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.listen-btn:hover { border-color: var(--accent); }
.listen-btn.speaking { background: var(--accent); border-color: var(--accent); color: #fff; }
.tts-stop {
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
  border-radius: 999px; padding: 6px 12px; font-size: 12.5px; font-weight: 600;
  white-space: nowrap;
}
.tts-stop:hover { background: #8d1f23; }

/* ---------- Right panel ---------- */
.tabs {
  display: flex; gap: 2px; padding: 12px 16px 0;
  border-bottom: 1px solid var(--line); position: sticky; top: 0;
  background: var(--surface); z-index: 2;
}
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent;
  padding: 8px 10px; font-size: 13.5px; color: var(--muted);
}
.tabs button.active { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }
.panel-body { flex: 1; padding: 16px 18px; }
.panel-foot { padding: 12px 18px 16px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); }

.banner-img { position: relative; border-radius: var(--radius); overflow: hidden; margin-bottom: 18px; }
.banner-img img { width: 100%; height: 130px; object-fit: cover; filter: grayscale(1) contrast(1.05) brightness(.85); }
.banner-img blockquote {
  position: absolute; inset: auto 0 0 0; margin: 0; padding: 34px 16px 12px;
  background: linear-gradient(transparent, rgba(0,0,0,.85));
  color: #fff; font-family: var(--font-read); font-style: italic; font-size: 16px; line-height: 1.4;
}
.banner-img blockquote footer { font-family: var(--font-ui); font-style: normal; font-size: 10.5px; letter-spacing: .14em; opacity: .85; margin-top: 4px; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.stat-grid .stat {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); padding: 12px 14px;
}
.stat-grid .stat.full { grid-column: 1 / -1; }
.stat .num { font-size: 22px; font-weight: 700; line-height: 1.1; }
.stat .lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }

.chip-row { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 18px; }
.topic {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 5px 11px; font-size: 12.5px;
}
.kv { display: grid; grid-template-columns: 118px 1fr; gap: 6px 12px; font-size: 13.5px; margin-bottom: 18px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.kv dd .sub { display: block; color: var(--muted); font-size: 12.5px; }

.note-box {
  background: #fbeeee; border: 1px solid #eecfc9; border-radius: var(--radius);
  padding: 13px 15px; font-size: 13.5px; line-height: 1.55; margin-bottom: 18px;
}
.note-box h3 { margin: 0 0 6px; font-size: 13.5px; color: var(--err); }
.note-box p { margin: 0; }

.decades { margin: 4px 0 18px; }
.decades .row { display: grid; grid-template-columns: 64px 1fr 26px; align-items: center; gap: 10px; font-size: 13px; margin-bottom: 6px; }
.decades .bar { height: 9px; background: #eee8da; border-radius: 5px; overflow: hidden; }
.decades .bar i { display: block; height: 100%; background: var(--accent); border-radius: 5px; }

.eval-table, .chain-table { width: 100%; border-collapse: collapse; font-size: 13.5px; margin-bottom: 18px; }
.eval-table td, .chain-table td, .eval-table th, .chain-table th {
  padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top;
}
.eval-table td:last-child, .chain-table td:last-child { text-align: right; }
.eval-table th:last-child, .chain-table th:last-child { text-align: right; }
.eval-table th, .chain-table th { font-size: 12px; color: var(--muted); font-weight: 600; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.speech-list { display: flex; flex-direction: column; gap: 8px; }
.speech-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; background: var(--surface); }
.speech-card .t { font-size: 13.5px; font-weight: 600; line-height: 1.4; }
.speech-card .t a { color: var(--ink); text-decoration: none; }
.speech-card .t a:hover { text-decoration: underline; }
.speech-card .s { font-size: 12.5px; color: var(--muted); margin-top: 3px; }

.example-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 14px; margin-bottom: 14px; background: var(--surface); }
.example-card .q { font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.example-empty {
  border: 1px dashed #aaa; border-radius: var(--radius);
  padding: 16px; color: var(--muted); font-size: 14px; line-height: 1.55;
}

/* ---------- Mobile: single column ---------- */
@media (max-width: 640px) {
  .layout { display: block; height: auto; }
  .sidebar, .center, .panel { overflow-y: visible; }
  .center { order: -1; }
  .mobile-brand { display: block; }
  .live-pill { font-size: 11.5px; }
  .topbar { position: sticky; top: 0; background: var(--bg); z-index: 5; padding: 10px 14px 8px; }
  .thread { padding: 6px 14px 14px; overflow-y: visible; }
  .answer { font-size: 17px; }
  /* On mobile the panels stack below the chat; collapsing hides the
     section outright and the rail handles sit on the screen edges. */
  .layout.no-sidebar .sidebar { display: none; }
  .layout.no-panel .panel { display: none; }
  #rail-left, #rail-left.closed { left: 0; }
  #rail-right, #rail-right.closed { right: 0; }
  .composer {
    position: sticky; bottom: 0; z-index: 6;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  }
  .composer textarea { font-size: 16px; }
  .sidebar { border-right: 0; border-top: 1px solid var(--line); }
  .portrait img { height: 300px; object-fit: cover; object-position: center 18%; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .tabs { position: sticky; top: 0; }
  .sources summary { padding: 10px 12px; }
  .kv { grid-template-columns: 104px 1fr; }
}
