:root {
  --paper: #f4efe4;
  --paper-2: #ece5d5;
  --card: #faf6ec;
  --ink: #26221c;
  --ink-soft: #4f4739;
  --muted: #8a7f6a;
  --accent: #1c5b4c;        /* deep India green */
  --accent-soft: #2f7d69;
  --saffron: #c86a2b;       /* saffron / terracotta */
  --rose: #9a2f3a;          /* the rose on his lapel */
  --rule: #d9cfb8;
  --danger: #9a3324;
  --serif-display: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --serif: "Spectral", Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.6;
  /* subtle handmade-paper grain */
  background-image:
    radial-gradient(circle at 18% 12%, rgba(28,91,76,.035), transparent 60%),
    radial-gradient(circle at 82% 88%, rgba(200,106,43,.035), transparent 60%);
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.6rem;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}
.topbar-id { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.topbar-id .name { font-family: var(--serif-display); font-weight: 600; font-size: 1.5rem; color: var(--accent); letter-spacing: .2px; }
.topbar-id .honorific { font-family: var(--serif-display); font-weight: 600; font-size: 1.4rem; color: var(--saffron); }
.topbar-id .dot { color: var(--muted); }
.topbar-id .years { color: var(--muted); font-size: .95rem; letter-spacing: .12em; margin-left: .3rem; }
.panel-toggle {
  background: none; border: none; cursor: pointer;
  color: var(--saffron); font-family: var(--serif); font-size: 1rem;
}
.panel-toggle:hover { color: var(--accent); }


/* ---------- Thread ---------- */
.thread {
  max-width: 760px; margin: 0 auto;
  padding: 2.4rem 1.5rem 9rem;
  min-height: 40vh;
}
.msg { margin: 0 0 2.6rem; }
.msg .who {
  font-size: .72rem; letter-spacing: .18em; text-transform: uppercase;
  color: var(--saffron); margin-bottom: .6rem; display: flex; align-items: center; gap: .5rem;
}
.msg .who img { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; filter: sepia(.12); }
.msg .who .speak {
  margin-left: .5rem; border: 1px solid var(--rule); background: var(--card);
  color: var(--saffron); cursor: pointer; border-radius: 999px;
  font-size: .8rem; line-height: 1; padding: .2rem .5rem; letter-spacing: 0;
}
.msg .who .speak:hover { border-color: var(--saffron); }
.msg .who .speak.playing { background: var(--accent); color: #fdf7ec; border-color: var(--accent); }

.msg.nehru .body {
  border-left: 2px solid var(--accent-soft);
  padding-left: 1.4rem;
  font-size: 1.18rem; line-height: 1.75;
}
.msg.nehru .body p { margin: 0 0 1.05rem; }

.msg.you { text-align: right; }
.msg.you .who { justify-content: flex-end; color: var(--muted); }
.msg.you .body {
  display: inline-block; text-align: left;
  background: var(--card); border: 1px solid var(--rule);
  border-radius: 12px; padding: .7rem 1.1rem; max-width: 82%;
  color: var(--ink-soft);
}
.sources {
  margin-top: .7rem; font-size: .78rem; color: var(--muted);
  padding-left: 1.4rem;
}
.sources em { color: var(--accent-soft); font-style: italic; }
.cursor::after { content: "▋"; color: var(--accent-soft); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Composer ---------- */
.composer {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 15;
  background: linear-gradient(rgba(244,239,228,0), var(--paper) 30%);
  padding: 1rem 1.5rem 1.2rem;
}
.composer-inner {
  max-width: 760px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: .5rem;
  border-top: 1px solid var(--rule); padding-top: .9rem;
}
#input {
  flex: 1 1 auto; min-width: 0; resize: none; max-height: 32vh;
  border: none; outline: none; background: transparent;
  font-family: var(--serif); font-size: max(1.05rem, 16px); color: var(--ink);
  padding: .5rem 0; line-height: 1.5;
}
#input::placeholder { color: var(--muted); font-style: italic; }
.mic {
  flex: 0 0 auto; border: 1px solid var(--rule); background: var(--card); cursor: pointer;
  border-radius: 10px; width: 44px; height: 44px; font-size: 1.05rem;
}
.mic.on { background: var(--accent); color: #fff; }
.composer-hint { max-width: 760px; margin: .4rem auto 0; font-size: .72rem; color: var(--muted); }
kbd { background: var(--paper-2); border: 1px solid var(--rule); border-radius: 4px; padding: 0 .3rem; font-family: var(--serif); }

/* ---------- Buttons ---------- */
.btn-primary {
  background: var(--accent); color: #fdf7ec; border: none; cursor: pointer;
  font-family: var(--serif); font-size: 1rem; font-weight: 500;
  padding: .6rem 1.4rem; border-radius: 10px;
}
.btn-primary:hover { background: #164a3e; }
.btn-primary:disabled { opacity: .5; cursor: default; }
.send {
  flex: 0 0 auto; align-self: flex-end; height: 44px; padding: 0 1.2rem;
  display: inline-flex; align-items: center; font-size: .98rem;
}
.btn-danger {
  background: none; border: 1px solid var(--danger); color: var(--danger);
  cursor: pointer; border-radius: 10px; padding: .5rem 1rem; font-family: var(--serif);
  width: 100%; margin-top: .6rem;
}
.btn-danger:hover { background: var(--danger); color: #fdf7ec; }

/* ---------- Splash / home entry screen ---------- */
.entry-overlay {
  position: fixed; inset: 0; z-index: 300;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1.1rem; text-align: center; padding: 2rem;
  background: var(--paper);
  padding-top: calc(2rem + env(safe-area-inset-top));
  opacity: 1; transition: opacity 1.1s ease;
}
.entry-overlay.fade-out { opacity: 0; }
.entry-overlay.hidden { display: none; }
.entry-portrait img {
  width: 132px; height: 132px; border-radius: 50%; object-fit: cover;
  filter: sepia(.1); box-shadow: 0 10px 30px rgba(38,34,27,.22);
  border: 3px solid var(--card);
}
.entry-name {
  font-family: var(--serif-display); font-weight: 600; font-size: 2.6rem;
  color: var(--accent); letter-spacing: .5px; line-height: 1.1;
}
.entry-years {
  font-size: .8rem; letter-spacing: .22em; color: var(--muted); font-weight: 500;
}
.entry-line { width: 48px; height: 1px; background: var(--saffron); opacity: .7; }
.entry-desc {
  font-family: var(--serif); font-style: italic; font-size: 1.05rem;
  color: var(--ink-soft); line-height: 1.6; max-width: 22rem;
}
.entry-portrait, .entry-name, .entry-years, .entry-line, .entry-desc {
  animation: entry-rise .9s ease both;
}
.entry-name { animation-delay: .08s; }
.entry-years { animation-delay: .16s; }
.entry-line { animation-delay: .24s; }
.entry-desc { animation-delay: .32s; }
@keyframes entry-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .entry-portrait, .entry-name, .entry-years, .entry-line, .entry-desc { animation: none; }
}

/* ---------- Gate ---------- */
.gate {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(244,239,228,.9); backdrop-filter: blur(3px);
  display: flex; flex-direction: column; align-items: center;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 1.5rem 1rem;
  padding-top: calc(1.5rem + env(safe-area-inset-top));
  padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
}
.gate-card {
  background: var(--card); border: 1px solid var(--rule); border-radius: 16px;
  width: 100%; max-width: 560px; padding: 2rem 2.2rem; box-shadow: 0 20px 60px rgba(38,34,27,.18);
  margin-block: auto;
}
.gate-card h1 { font-family: var(--serif-display); color: var(--accent); font-weight: 600; margin: 0 0 .2rem; font-size: 2rem; }
.eyebrow { font-size: .72rem; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); margin: 0 0 1.2rem; }
.gate-card ul { padding-left: 1.1rem; }
.gate-card li { margin-bottom: .7rem; color: var(--ink-soft); font-size: .96rem; }
.gate-card .btn-primary { width: 100%; margin-top: 1rem; padding: .8rem; }

/* ---------- Side panel ---------- */
.scrim { position: fixed; inset: 0; background: rgba(38,34,27,.35); z-index: 40; }
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 50;
  width: min(420px, 90vw); overflow-y: auto;
  background: var(--card); border-left: 1px solid var(--rule);
  padding: 1.4rem 1.6rem 3rem; box-shadow: -20px 0 50px rgba(38,34,27,.15);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .6rem; }
.panel-head h2 { font-family: var(--serif-display); color: var(--accent); font-weight: 600; margin: 0; font-size: 1.7rem; }
.x { background: none; border: none; font-size: 1.6rem; color: var(--muted); cursor: pointer; line-height: 1; }
.panel section { border-top: 1px solid var(--rule); padding: 1.1rem 0; }
.panel h3 { font-size: .72rem; letter-spacing: .18em; text-transform: uppercase; color: var(--saffron); margin: 0 0 .7rem; }
.skills { display: flex; flex-wrap: wrap; gap: .5rem; }
.skills span {
  font-size: .85rem; padding: .25rem .7rem; border-radius: 999px;
  border: 1px solid var(--rule); color: var(--muted);
}
.skills span.active { background: var(--accent); color: #fdf7ec; border-color: var(--accent); }
.memory { font-size: .9rem; color: var(--ink-soft); white-space: pre-wrap; }
.memory h4 { font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--accent-soft); margin: .8rem 0 .2rem; }
.memory ul { margin: 0 0 .4rem; padding-left: 1.1rem; }
.muted { color: var(--muted); font-size: .9rem; }
.chapters { margin-top: .6rem; max-height: 220px; overflow-y: auto; font-size: .82rem; color: var(--ink-soft); }
.chapters div { padding: .12rem 0; border-bottom: 1px dotted var(--rule); }
.switch { display: flex; align-items: center; gap: .5rem; font-size: .92rem; color: var(--ink-soft); cursor: pointer; }
.legal-links { margin: 1rem 0 0; font-size: .82rem; color: var(--muted); }
.legal-links a { color: var(--saffron); text-decoration: none; }
.legal-links a:hover { text-decoration: underline; }

@media (max-width: 620px) {
  body { font-size: 16px; }
  .topbar { padding: .7rem 1rem; padding-top: calc(.7rem + env(safe-area-inset-top)); }
  .topbar-id { gap: .35rem; }
  .topbar-id .name { font-size: 1.12rem; }
  .topbar-id .honorific { font-size: 1rem; }
  .topbar-id .years { font-size: .72rem; margin-left: .1rem; }
  .panel-toggle { font-size: .82rem; }
  .msg { margin-bottom: 1.7rem; }
  .msg .who { font-size: .66rem; }
  .msg.nehru .body { font-size: 1rem; line-height: 1.62; padding-left: 1rem; }
  .msg.nehru .body p { margin-bottom: .85rem; }
  .msg.you .body { font-size: .98rem; }
  .sources { padding-left: 1rem; font-size: .72rem; }
  .thread { padding: 1.2rem .95rem 7.5rem; }
  .gate-card { padding: 1.5rem 1.25rem; }
  .gate-card h1 { font-size: 1.7rem; }
  .composer { padding: .5rem .9rem .7rem; }
  .composer-inner { padding-top: .7rem; gap: .4rem; }
  .composer-hint { display: none; }
  .mic { width: 40px; height: 40px; font-size: 1rem; }
  .send { height: 40px; padding: 0 .95rem; font-size: .92rem; }
  .entry-name { font-size: 2.1rem; }
  .entry-portrait img { width: 108px; height: 108px; }
  .entry-desc { font-size: .95rem; }
}

/* Safe areas — notches, status bars, and the home indicator (iOS/Android). */
.topbar { padding-top: calc(1rem + env(safe-area-inset-top)); }
.composer {
  padding-left: calc(1.5rem + env(safe-area-inset-left));
  padding-right: calc(1.5rem + env(safe-area-inset-right));
  padding-bottom: calc(1.2rem + env(safe-area-inset-bottom));
}
.panel { padding-top: calc(1.4rem + env(safe-area-inset-top)); padding-bottom: calc(3rem + env(safe-area-inset-bottom)); }
.gate { padding-top: calc(1.5rem + env(safe-area-inset-top)); }

/* Prevent iOS auto-zoom on input focus (font-size >= 16px) and long-press callout. */
#input { font-size: max(1.1rem, 16px); -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
