:root {
  --paper: #f5f0e6;
  --paper-deep: #ebe2d1;
  --ink: #27231f;
  --muted: #746c61;
  --line: rgba(55, 47, 39, 0.13);
  --terracotta: #a55237;
  --terracotta-dark: #7d3825;
  --sage: #617063;
  --white: #fffdf8;
  --shadow: 0 18px 60px rgba(55, 43, 30, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 8%, rgba(181, 119, 83, 0.14), transparent 30%),
    radial-gradient(circle at 88% 90%, rgba(97, 112, 99, 0.12), transparent 34%),
    var(--paper);
}
button, textarea { font: inherit; }
button { cursor: pointer; }

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
}

.sidebar {
  min-height: 100vh;
  padding: 34px 28px 26px;
  border-right: 1px solid var(--line);
  background: rgba(246, 241, 231, 0.84);
  backdrop-filter: blur(18px);
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 45px; height: 45px; border-radius: 50%; display: grid; place-items: center;
  color: var(--white); background: var(--terracotta); font-size: 20px;
  box-shadow: 0 8px 24px rgba(165, 82, 55, 0.24);
}
.eyebrow {
  margin: 0 0 4px; text-transform: uppercase; letter-spacing: .14em;
  font-size: 10px; font-weight: 760; color: var(--muted);
}
h1, h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-weight: 500; }
h1 { font-size: 25px; }
h2 { font-size: 24px; }

.journey-card, .focus-card, .practice-card {
  border: 1px solid var(--line); background: rgba(255, 253, 248, 0.72);
  box-shadow: 0 8px 30px rgba(55, 43, 30, 0.05);
}
.journey-card { border-radius: 18px; padding: 19px; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.section-heading h2 { font-family: inherit; font-size: 14px; font-weight: 720; }
.status-pill {
  border-radius: 999px; padding: 5px 9px; background: rgba(97, 112, 99, .11);
  color: var(--sage); font-size: 10px; font-weight: 750; text-transform: uppercase; letter-spacing: .07em;
}
.week-row { display: flex; justify-content: space-between; margin-top: 20px; color: var(--muted); font-size: 13px; }
.progress-track { height: 7px; border-radius: 999px; background: var(--paper-deep); margin-top: 10px; overflow: hidden; }
.progress-fill { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--terracotta), #cc8b67); transition: width .45s ease; }

.practice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.practice-card { border-radius: 16px; padding: 15px 13px; display: grid; gap: 3px; }
.practice-card strong { font-family: Georgia, serif; font-size: 25px; font-weight: 500; }
.practice-card > span:last-child { color: var(--muted); font-size: 11px; line-height: 1.3; }
.practice-icon { color: var(--terracotta); font-size: 16px; }
.focus-card { border-radius: 16px; padding: 17px; }
.focus-card > p:last-child { margin: 0; color: #514a42; font-size: 13px; line-height: 1.55; }
.sidebar-spacer { flex: 1; }
.privacy-note { display: flex; gap: 10px; align-items: flex-start; color: var(--muted); font-size: 11px; line-height: 1.45; }
.privacy-note span { color: var(--sage); font-size: 19px; }
.privacy-note p { margin: 0; }
.quiet-button {
  width: 100%; border: 1px solid var(--line); background: transparent; color: var(--muted);
  padding: 11px; border-radius: 12px; font-size: 12px;
}
.quiet-button:hover { border-color: rgba(165, 82, 55, .35); color: var(--terracotta-dark); }

.login-screen {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(circle at 50% 20%, rgba(181,119,83,.16), transparent 38%);
}
.login-card {
  width: min(440px, 100%); padding: 42px; text-align: center; border: 1px solid var(--line);
  border-radius: 24px; background: rgba(255,253,248,.88); box-shadow: var(--shadow);
}
.login-mark {
  width: 58px; height: 58px; margin: 0 auto 18px; display: grid; place-items: center;
  border-radius: 50%; background: var(--terracotta); color: white; font-size: 25px;
}
.login-card h1 { font-size: 34px; }
.login-card > p:not(.eyebrow):not(.login-error) { margin: 18px 0 24px; color: var(--muted); line-height: 1.6; }
.login-card button {
  border: 0; border-radius: 13px; padding: 13px 18px; background: var(--terracotta); color: white; font-weight: 720;
}
.login-card button:hover { background: var(--terracotta-dark); }
.login-error { min-height: 1.4em; margin: 14px 0 0; color: var(--terracotta-dark); font-size: 12px; }

.user-block {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 2px;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.user-copy { min-width: 0; display: grid; gap: 2px; }
.user-copy strong, .user-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-copy strong { font-size: 12px; }
.user-copy span { color: var(--muted); font-size: 10px; }
.user-block button { border: 0; background: transparent; color: var(--muted); font-size: 10px; padding: 5px; }
.user-block button:hover { color: var(--terracotta-dark); }

.threads-panel { min-height: 0; }
.new-thread-button {
  width: 27px; height: 27px; border: 1px solid var(--line); border-radius: 9px;
  background: rgba(255,253,248,.68); color: var(--terracotta-dark); font-size: 17px; line-height: 1;
}
.thread-list { display: grid; gap: 4px; max-height: 150px; overflow-y: auto; margin-top: 9px; padding-right: 3px; }
.thread-row { min-width: 0; display: grid; grid-template-columns: minmax(0,1fr) 30px; border-radius: 10px; }
.thread-row:hover, .thread-row.active { background: rgba(165,82,55,.08); }
.thread-row.active { box-shadow: inset 2px 0 var(--terracotta); }
.thread-select, .thread-menu {
  min-width: 0; border: 0; background: transparent; color: #554e46; padding: 8px 9px; font-size: 11px;
}
.thread-select { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.thread-menu { padding: 6px 4px; color: var(--muted); letter-spacing: .08em; }
.thread-menu:hover { color: var(--terracotta-dark); }

.chat-panel { min-width: 0; height: 100vh; display: grid; grid-template-rows: auto 1fr auto auto auto; }
.chat-header {
  padding: 28px 42px 21px; border-bottom: 1px solid var(--line); display: flex;
  align-items: center; justify-content: space-between; background: rgba(255, 253, 248, .42);
}
.chat-header h2 { font-size: 28px; }
.connection { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 7px; }
.connection-dot { width: 7px; height: 7px; border-radius: 50%; background: #6d8d6e; box-shadow: 0 0 0 4px rgba(109,141,110,.12); }

.messages {
  overflow-y: auto; padding: 34px max(42px, calc((100% - 850px) / 2));
  scroll-behavior: smooth;
}
.message { display: flex; gap: 12px; margin-bottom: 23px; animation: rise .22s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(5px); } }
.avatar {
  flex: 0 0 33px; height: 33px; border-radius: 50%; display: grid; place-items: center;
  background: var(--terracotta); color: white; font-size: 13px; margin-top: 2px;
}
.bubble { max-width: min(720px, 88%); color: #38322c; line-height: 1.64; font-size: 15px; white-space: pre-wrap; }
.bubble p { margin: 0 0 9px; }
.user-message { justify-content: flex-end; }
.user-message .bubble {
  background: var(--terracotta); color: var(--white); border-radius: 18px 18px 5px 18px;
  padding: 13px 17px; box-shadow: 0 8px 24px rgba(125,56,37,.13);
}
.user-message .avatar { display: none; }
.guide-message .bubble {
  background: rgba(255,253,248,.72); border: 1px solid var(--line); border-radius: 5px 18px 18px 18px;
  padding: 14px 18px; white-space: normal;
}
.guide-message .bubble > :first-child { margin-top: 0; }
.guide-message .bubble > :last-child { margin-bottom: 0; }
.guide-message .bubble h1,
.guide-message .bubble h2,
.guide-message .bubble h3,
.guide-message .bubble h4 {
  margin: 1.15em 0 .45em; color: var(--ink); font-family: Georgia, "Times New Roman", serif; line-height: 1.25;
}
.guide-message .bubble h1 { font-size: 1.45em; }
.guide-message .bubble h2 { font-size: 1.28em; }
.guide-message .bubble h3 { font-size: 1.13em; }
.guide-message .bubble ul,
.guide-message .bubble ol { margin: .55em 0 .8em; padding-left: 1.45em; }
.guide-message .bubble li { margin: .28em 0; padding-left: .1em; }
.guide-message .bubble blockquote {
  margin: .8em 0; padding: .2em 0 .2em 1em; border-left: 3px solid rgba(165,82,55,.45); color: var(--muted);
}
.guide-message .bubble blockquote p { margin: .25em 0; }
.guide-message .bubble a { color: var(--terracotta-dark); text-decoration-thickness: 1px; text-underline-offset: 2px; }
.guide-message .bubble code {
  border-radius: 5px; padding: .12em .35em; background: var(--paper-deep); font: .88em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.guide-message .bubble pre {
  overflow-x: auto; margin: .8em 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: #2f2b27; color: #f8f2e7;
}
.guide-message .bubble pre code { padding: 0; background: transparent; color: inherit; }
.guide-message .bubble hr { border: 0; border-top: 1px solid var(--line); margin: 1.1em 0; }
.guide-message .bubble table { width: 100%; border-collapse: collapse; margin: .8em 0; font-size: .92em; }
.guide-message .bubble th,
.guide-message .bubble td { border: 1px solid var(--line); padding: 7px 9px; text-align: left; vertical-align: top; }
.guide-message .bubble th { background: var(--paper-deep); }
.typing .bubble { color: var(--muted); letter-spacing: .22em; }
.error-message .bubble { border-color: rgba(165,82,55,.35); color: var(--terracotta-dark); }

.quick-prompts {
  display: flex; gap: 8px; flex-wrap: wrap; padding: 0 max(42px, calc((100% - 850px) / 2)) 14px;
}
.quick-prompts button {
  border: 1px solid var(--line); background: rgba(255,253,248,.62); color: #5d554c;
  border-radius: 999px; padding: 8px 12px; font-size: 11px;
}
.quick-prompts button:hover { border-color: rgba(165,82,55,.38); color: var(--terracotta-dark); }

.composer {
  margin: 0 max(42px, calc((100% - 850px) / 2)); padding: 9px 10px 9px 18px;
  display: flex; gap: 10px; align-items: flex-end; border: 1px solid rgba(55,47,39,.18);
  border-radius: 18px; background: var(--white); box-shadow: var(--shadow);
}
.composer textarea {
  flex: 1; border: 0; outline: 0; resize: none; min-height: 34px; max-height: 150px;
  padding: 8px 0; background: transparent; color: var(--ink); line-height: 1.45;
}
.composer textarea::placeholder { color: #9b9287; }
.composer button {
  border: 0; border-radius: 12px; background: var(--terracotta); color: white;
  min-height: 40px; padding: 0 15px; display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700;
}
.composer button:hover { background: var(--terracotta-dark); }
.composer button:disabled { opacity: .55; cursor: wait; }
.disclaimer { text-align: center; color: #90877d; font-size: 10px; margin: 9px 0 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { min-height: auto; padding: 18px; border-right: 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; }
  .brand, .user-block, .threads-panel { grid-column: 1 / -1; }
  .journey-card { grid-column: 1 / -1; }
  .thread-list { max-height: 100px; }
  .focus-card, .privacy-note, .quiet-button, .sidebar-spacer { display: none; }
  .chat-panel { height: calc(100vh - 300px); min-height: 520px; }
  .chat-header { padding: 18px; }
  .chat-header h2 { font-size: 23px; }
  .messages { padding: 24px 16px; }
  .quick-prompts { padding: 0 16px 12px; overflow-x: auto; flex-wrap: nowrap; }
  .quick-prompts button { white-space: nowrap; }
  .composer { margin: 0 14px; }
  .bubble { max-width: 92%; }
}
