:root {
  --bg: #0e0e10;
  --bg-soft: #16161a;
  --bg-card: #1b1b20;
  --border: #2a2a30;
  --text: #e8e6e3;
  --text-muted: #9a9690;
  --text-dim: #6e6a64;
  --accent: #d4a373;
  --accent-soft: #e9c9a4;
  --serif: "Fraunces", ui-serif, Georgia, serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --max-w: 680px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s ease;
}
a:hover { border-bottom-color: var(--accent); }

.container {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 6rem 1.5rem 4rem;
}

/* Hero */
.hero { margin-bottom: 4rem; }
.hero h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(2.5rem, 6vw, 3.5rem);
  letter-spacing: -0.02em;
  line-height: 1.05;
  margin: 0 0 1rem;
  font-variation-settings: "opsz" 144;
}
.topnav {
  margin-top: 2rem;
  display: flex;
  gap: 1.75rem;
  font-size: 0.9rem;
  color: var(--text-dim);
  flex-wrap: wrap;
}
.topnav a {
  color: var(--text-dim);
  border-bottom: none;
}
.topnav a:hover { color: var(--accent); }

/* Sections */
section {
  margin: 4rem 0;
  scroll-margin-top: 2rem;
}
section h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
  color: var(--text);
  margin: 0 0 1.25rem;
  position: relative;
  padding-left: 1.25rem;
}
section h2::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.85em;
  width: 0.7rem;
  height: 1px;
  background: var(--accent);
}

section p {
  margin: 0 0 1rem;
  color: var(--text);
}

.emph {
  color: var(--text);
  border-bottom: 1px dotted var(--text-dim);
}

/* Timeline */
.timeline, .links {
  list-style: none;
  padding: 0;
  margin: 0;
}
.timeline li {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 1rem;
  padding: 0.75rem 0;
  border-top: 1px solid var(--border);
}
.timeline li:first-child { border-top: none; }
.timeline .when {
  font-family: var(--serif);
  font-size: 0.85rem;
  color: var(--text-dim);
  font-feature-settings: "tnum";
  padding-top: 0.15rem;
}
.timeline .what { color: var(--text); }
.timeline strong {
  color: var(--accent-soft);
  font-weight: 500;
}

@media (max-width: 540px) {
  .timeline li { grid-template-columns: 1fr; gap: 0.1rem; }
  .timeline .when { font-size: 0.8rem; }
}

/* Links */
.links {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.links li { padding: 0; }
.links a {
  color: var(--accent-soft);
  font-size: 0.95rem;
}

footer {
  margin-top: 6rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}
.footnote {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 0;
}

/* ─── Chat widget ─── */
.chat-toggle {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--accent);
  color: #1a140d;
  border: none;
  border-radius: 999px;
  padding: 0.85rem 1.1rem;
  font-family: var(--sans);
  font-size: 0.9rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  z-index: 100;
}
.chat-toggle:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5), 0 2px 4px rgba(0, 0, 0, 0.3);
}
.chat-toggle[aria-expanded="true"] {
  transform: scale(0.95);
  opacity: 0.75;
}

.chat-panel {
  position: fixed;
  bottom: 5.5rem;
  right: 1.5rem;
  width: 380px;
  max-width: calc(100vw - 3rem);
  height: 560px;
  max-height: calc(100vh - 7rem);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), 0 4px 12px rgba(0, 0, 0, 0.3);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 99;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.chat-panel.open {
  display: flex;
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 540px) {
  .chat-panel {
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    max-height: 100vh;
    max-width: 100vw;
    border-radius: 0;
    border: none;
  }
  .chat-toggle-label { display: none; }
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1rem 0.8rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}
.chat-title {
  font-family: var(--serif);
  font-size: 1.05rem;
  color: var(--text);
}
.chat-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.25rem;
}
.chat-close:hover { color: var(--text); }

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.chat-log::-webkit-scrollbar { width: 6px; }
.chat-log::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.msg {
  max-width: 86%;
  padding: 0.6rem 0.85rem;
  border-radius: 14px;
  font-size: 0.92rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #1a140d;
  border-bottom-right-radius: 4px;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg.system {
  align-self: center;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.8rem;
  font-style: italic;
  text-align: center;
  border: none;
  padding: 0.3rem 0.5rem;
}
.msg.error { color: #e8a2a2; }

.msg .cursor {
  display: inline-block;
  width: 6px;
  height: 1em;
  vertical-align: -2px;
  background: var(--text-muted);
  animation: blink 1s steps(2) infinite;
  margin-left: 2px;
}
@keyframes blink { 50% { opacity: 0; } }

.chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
}
.chat-form textarea {
  flex: 1;
  resize: none;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  font-family: var(--sans);
  font-size: 0.92rem;
  line-height: 1.4;
  max-height: 120px;
  outline: none;
}
.chat-form textarea:focus { border-color: var(--accent); }
.chat-form button {
  background: var(--accent);
  color: #1a140d;
  border: none;
  border-radius: 10px;
  width: 38px;
  height: 38px;
  align-self: flex-end;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.chat-form button:disabled {
  background: var(--border);
  color: var(--text-dim);
  cursor: not-allowed;
}

.chat-disclaimer {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-align: center;
  padding: 0.4rem 0.75rem 0.6rem;
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
}
