:root {
  --canvas: #f4f1eb;
  --paper: #fbfaf7;
  --paper-deep: #f0eee8;
  --ink: #202721;
  --ink-soft: #526057;
  --muted: #7e877f;
  --line: #deded6;
  --line-strong: #cecec4;
  --olive: #526555;
  --olive-dark: #293b30;
  --gold: #a98456;
  --error: #a04f48;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }

html { height: 100%; min-width: 320px; overflow: hidden; background: var(--canvas); }

body { height: 100%; min-width: 320px; min-height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; background: var(--canvas); }

button, textarea { font: inherit; }

button { -webkit-tap-highlight-color: transparent; }

button:focus-visible, textarea:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

.hidden { display: none !important; }

.app-shell { height: 100%; min-height: 0; overflow: hidden; }

/* Sign in */
.login-view {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(400px, .92fr);
  align-items: center;
  gap: clamp(48px, 9vw, 150px);
  width: min(1380px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  padding: clamp(32px, 7vw, 92px);
}

.login-story {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 520px;
  padding: 18px 0 12px 34px;
  border-left: 1px solid var(--line-strong);
}

.story-topline, .story-foot { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: .15em; }

.story-rule { width: 34px; height: 1px; background: var(--gold); }

.story-title { max-width: 700px; margin: auto 0 28px; color: var(--ink); font-family: "Iowan Old Style", "Baskerville", "Times New Roman", serif; font-size: clamp(52px, 7.3vw, 104px); font-weight: 400; letter-spacing: -.065em; line-height: .93; }

.story-title em { color: var(--gold); font-style: italic; }

.story-copy { max-width: 390px; margin: 0 0 48px; color: var(--ink-soft); font-size: 14px; line-height: 1.75; }

.story-foot { width: min(100%, 520px); color: var(--muted); font-size: 9px; }

.story-foot > span:first-child { color: var(--gold); }

.story-foot-line { flex: 1; height: 1px; background: var(--line); }

.login-panel { width: 100%; max-width: 470px; justify-self: end; }

.login-view--callback { grid-template-columns: 1fr; place-items: center; }

.login-view--callback .login-panel { justify-self: center; }

.login-card { padding: clamp(32px, 5vw, 58px); border: 1px solid var(--line); border-radius: 24px; background: var(--paper); box-shadow: 0 22px 55px rgba(40, 44, 35, .08); }

.brand-mark { display: grid; place-items: center; width: 48px; height: 48px; overflow: hidden; border-radius: 15px; background: var(--ink); color: #d4ad73; }

.brand-logo { display: block; width: 100%; height: 100%; object-fit: cover; object-position: 50% 50%; border-radius: inherit; }

.brand-mark.small { width: 34px; height: 34px; border-radius: 10px; }

.eyebrow { margin: 31px 0 16px; color: var(--gold); font-size: 10px; font-weight: 800; letter-spacing: .18em; }

.login-card h1 { margin: 0; color: var(--ink); font-family: "Iowan Old Style", "Baskerville", "Times New Roman", serif; font-size: clamp(42px, 5vw, 64px); font-weight: 400; letter-spacing: -.06em; line-height: .94; }

.login-card h1 span { color: var(--muted); font-style: italic; }

.login-copy { max-width: 340px; margin: 24px 0 30px; color: var(--ink-soft); font-size: 14px; line-height: 1.7; }

.google-button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 15px 16px; border: 1px solid var(--ink); border-radius: 10px; background: var(--ink); color: var(--paper); font-size: 13px; font-weight: 700; text-align: left; cursor: pointer; transition: background .2s ease, transform .2s ease, box-shadow .2s ease; }

.google-button:hover { background: var(--olive-dark); box-shadow: 0 10px 20px rgba(41, 59, 48, .16); transform: translateY(-1px); }

.google-button:disabled { cursor: wait; opacity: .65; transform: none; }

.google-icon { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--paper); color: #3975e7; font-size: 15px; font-weight: 850; }

.button-arrow { width: 19px; height: 19px; margin-left: auto; color: #c7a26b; }

.form-error { min-height: 20px; margin: 12px 0 0; color: var(--error); font-size: 12px; }

.login-note { display: flex; align-items: center; gap: 8px; margin: 28px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }

.privacy-mark { color: var(--gold); font-size: 18px; line-height: 0; }

/* Chat shell */
.chat-view { display: grid; grid-template-columns: 318px minmax(0, 1fr); gap: 16px; width: 100%; height: 100dvh; min-height: 0; max-height: 100dvh; overflow: hidden; padding: 18px; background: var(--canvas); }

.sidebar, .chat-panel { height: 100%; min-height: 0; border: 1px solid var(--line); border-radius: 22px; background: var(--paper); }

.sidebar { display: flex; flex-direction: column; overflow: hidden; padding: 22px 16px 16px; }

.sidebar-top, .brand-lockup, .chat-contact, .profile-card { display: flex; align-items: center; }

.sidebar-top { justify-content: space-between; padding: 0 8px 25px; }

.sidebar-actions { display: flex; gap: 6px; }

.brand-lockup { gap: 10px; }

.brand-lockup strong, .brand-lockup span { display: block; }

.brand-lockup strong { color: var(--ink); font-family: "Iowan Old Style", "Baskerville", Georgia, serif; font-size: 18px; font-weight: 600; letter-spacing: -.02em; }

.brand-lockup span { margin-top: 1px; color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }

.icon-button { display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; transition: border-color .2s, color .2s, background .2s; }

.icon-button svg { width: 17px; height: 17px; }

.icon-button:hover { border-color: var(--line-strong); background: var(--paper-deep); color: var(--ink); }

.profile-card { gap: 10px; padding: 13px 10px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }

.avatar { display: grid; place-items: center; flex: 0 0 auto; overflow: hidden; border-radius: 50%; background: var(--olive); color: var(--paper); font-weight: 800; }

.avatar.large { width: 41px; height: 41px; }

.avatar.large[src] { object-fit: cover; }

.avatar.mini { width: 34px; height: 34px; background: var(--paper-deep); color: var(--olive); font-size: 12px; }

.profile-info { min-width: 0; flex: 1; }

.profile-info strong, .profile-info span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.profile-info strong { color: var(--ink); font-size: 12px; }

.profile-info span { margin-top: 4px; color: var(--muted); font-size: 10px; }

.role-badge { padding: 4px 6px; border: 1px solid #d4ddcf; border-radius: 5px; color: var(--olive); font-size: 8px; font-weight: 800; letter-spacing: .08em; }

.section-label { display: flex; justify-content: space-between; margin: 28px 10px 11px; color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .14em; }

.conversation-list { min-height: 0; overflow: hidden; }

.conversation-item { display: flex; align-items: center; gap: 11px; width: 100%; margin-bottom: 3px; padding: 10px; border: 1px solid transparent; border-radius: 11px; background: transparent; color: var(--ink); text-align: left; cursor: pointer; transition: border-color .2s, background .2s; }

.conversation-item:hover { background: var(--paper-deep); }

.conversation-item.active { border-color: #d6dfd2; background: #edf2eb; }

.conversation-copy { min-width: 0; }

.conversation-copy strong, .conversation-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.conversation-copy strong { font-size: 12px; font-weight: 700; }

.conversation-copy small { margin-top: 4px; color: var(--muted); font-size: 10px; }

.sidebar-footer { margin-top: auto; padding: 17px 10px 0; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }

.status-dot { display: inline-block; width: 6px; height: 6px; margin-right: 6px; border-radius: 50%; background: var(--olive); vertical-align: 1px; }

.chat-panel { display: flex; flex-direction: column; overflow: hidden; }

.chat-header { display: flex; align-items: center; justify-content: space-between; padding: 25px 32px 22px; border-bottom: 1px solid var(--line); }

.chat-contact { gap: 12px; min-width: 0; }

.contact-avatar { width: 42px; height: 42px; background: var(--ink); color: #d6b076; }

.chat-overline { margin: 0 0 5px; color: var(--gold); font-size: 8px !important; font-weight: 800; letter-spacing: .16em; }

.chat-contact h2 { margin: 0; overflow: hidden; color: var(--ink); font-family: "Iowan Old Style", "Baskerville", Georgia, serif; font-size: 20px; font-weight: 600; letter-spacing: -.025em; text-overflow: ellipsis; white-space: nowrap; }

.chat-contact p { margin: 5px 0 0; color: var(--muted); font-size: 10px; }

.chat-contact p.online { color: var(--olive); }

.header-chip { padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: .05em; }

.chat-banner { margin: 18px 32px 0; padding: 10px 13px; border-left: 2px solid var(--gold); background: var(--paper-deep); color: var(--ink-soft); font-size: 11px; line-height: 1.55; }

.message-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 28px 32px; overscroll-behavior: contain; scroll-behavior: smooth; }

.message-list::-webkit-scrollbar, .conversation-list::-webkit-scrollbar { width: 5px; }

.message-list::-webkit-scrollbar-thumb, .conversation-list::-webkit-scrollbar-thumb { border-radius: 99px; background: var(--line-strong); }

.empty-state { display: grid; place-items: center; align-content: center; min-height: 100%; color: var(--muted); text-align: center; }

.empty-state h3 { margin: 16px 0 6px; color: var(--ink); font-family: "Iowan Old Style", "Baskerville", Georgia, serif; font-size: 18px; font-weight: 600; letter-spacing: -.025em; }

.empty-state p { margin: 0; font-size: 11px; }

.empty-icon { display: grid; place-items: center; width: 54px; height: 54px; border: 1px solid var(--line-strong); border-radius: 50%; color: var(--gold); }

.empty-icon svg { width: 28px; height: 28px; }

.date-divider { display: flex; align-items: center; gap: 12px; width: min(100%, 320px); margin: 3px auto 22px; color: var(--muted); font-size: 9px; letter-spacing: .08em; text-align: center; }

.date-divider::before, .date-divider::after { height: 1px; flex: 1; background: var(--line); content: ""; }

.message-row { display: flex; margin: 9px 0; }

.message-row.mine { justify-content: flex-end; }

.message-bubble { max-width: min(70%, 520px); padding: 11px 14px; border: 1px solid var(--line); border-radius: 4px 15px 15px 15px; background: var(--paper); color: var(--ink); box-shadow: 0 4px 12px rgba(40, 44, 35, .035); }

.mine .message-bubble { border-color: var(--olive-dark); border-radius: 15px 4px 15px 15px; background: var(--olive-dark); color: var(--paper); box-shadow: none; }

.message-bubble p { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; font-size: 13px; line-height: 1.55; }

.message-bubble time { display: block; margin-top: 6px; color: var(--muted); font-size: 9px; }

.mine .message-bubble time { color: #b7c5b8; }

.composer { display: flex; align-items: flex-end; gap: 12px; margin: 0 32px 7px; padding: 9px 9px 9px 15px; border: 1px solid var(--line-strong); border-radius: 13px; background: var(--paper); transition: border-color .2s, box-shadow .2s; }

.composer:focus-within { border-color: var(--olive); box-shadow: 0 0 0 3px rgba(82, 101, 85, .09); }

.composer textarea { flex: 1; max-height: 130px; resize: none; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 13px; line-height: 1.5; }

.composer textarea::placeholder { color: #a2a8a0; }

.composer-actions { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 9px; }

.send-button { display: grid; place-items: center; width: 37px; height: 37px; border: 0; border-radius: 9px; background: var(--olive-dark); color: #d4ad73; cursor: pointer; transition: background .2s, transform .2s; }

.send-button svg { width: 20px; height: 20px; }

.send-button:hover { background: var(--olive); transform: translateY(-1px); }

.send-button:disabled, .composer textarea:disabled { cursor: not-allowed; opacity: .45; }

.chat-error { min-height: 17px; margin: 0 38px 7px; color: var(--error); font-size: 10px; }

.chat-error:empty { display: none; }

/* Settings */
.settings-view { min-height: 100dvh; padding: 18px; background: var(--canvas); }

.settings-shell { min-height: calc(100dvh - 36px); border: 1px solid var(--line); border-radius: 22px; background: var(--paper); }

.settings-top { display: flex; align-items: center; justify-content: space-between; padding: 22px 32px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .14em; }

.back-button { display: inline-flex; align-items: center; gap: 8px; padding: 0; border: 0; background: transparent; color: var(--ink-soft); font-size: 11px; font-weight: 700; letter-spacing: 0; cursor: pointer; }

.back-button svg { width: 18px; height: 18px; color: var(--gold); }

.back-button:hover { color: var(--ink); }

.settings-content { width: min(100%, 640px); margin: 0 auto; padding: clamp(48px, 9vw, 96px) 24px 60px; }

.settings-content .eyebrow { margin-top: 0; }

.settings-content h1 { margin: 0; color: var(--ink); font-family: "Iowan Old Style", "Baskerville", "Times New Roman", serif; font-size: clamp(48px, 7vw, 76px); font-weight: 400; letter-spacing: -.06em; line-height: .9; }

.settings-content h1 em { color: var(--gold); font-style: italic; }

.settings-intro { max-width: 430px; margin: 25px 0 34px; color: var(--ink-soft); font-size: 13px; line-height: 1.7; }

.settings-card { padding: clamp(24px, 5vw, 38px); border: 1px solid var(--line); border-radius: 18px; background: #f8f7f3; }

.settings-identity { display: flex; align-items: center; gap: 12px; padding-bottom: 24px; border-bottom: 1px solid var(--line); }

.settings-identity strong, .settings-identity span { display: block; }

.settings-identity strong { color: var(--ink); font-size: 13px; }

.settings-identity span { margin-top: 4px; color: var(--muted); font-size: 10px; }

.settings-identity-copy { min-width: 0; flex: 1; }

.settings-identity-copy small { display: block; margin-top: 7px; color: var(--muted); font-size: 10px; }

.avatar-settings-actions { display: flex; align-items: center; flex: 0 0 auto; }

.avatar-input { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; clip-path: inset(50%); }

.avatar-change-button { padding: 8px 11px; border: 1px solid var(--line-strong); border-radius: 7px; background: var(--paper); color: var(--ink-soft); font-size: 10px; font-weight: 800; cursor: pointer; }

.avatar-change-button:hover { border-color: var(--gold); color: var(--ink); }

.avatar-change-button:disabled { cursor: wait; opacity: .6; }

.settings-status { min-height: 15px; margin: 12px 0 0; color: var(--olive-dark); font-size: 10px; }

.settings-status:empty { display: none; }

.displayname-form { margin-top: 27px; }

.displayname-form label { display: block; margin-bottom: 9px; color: var(--ink); font-size: 11px; font-weight: 800; }

.displayname-form input { width: 100%; padding: 14px 15px; border: 1px solid var(--line-strong); border-radius: 9px; outline: 0; background: var(--paper); color: var(--ink); font-size: 14px; transition: border-color .2s, box-shadow .2s; }

.displayname-form input:focus { border-color: var(--olive); box-shadow: 0 0 0 3px rgba(82, 101, 85, .09); }

.field-meta { display: flex; justify-content: space-between; margin-top: 7px; color: var(--muted); font-size: 9px; }

.settings-save { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; margin-top: 17px; padding: 14px 16px; border: 1px solid var(--ink); border-radius: 9px; background: var(--ink); color: var(--paper); font-size: 12px; font-weight: 750; cursor: pointer; transition: background .2s, transform .2s; }

.settings-save svg { width: 18px; height: 18px; color: #d4ad73; }

.settings-save:hover { background: var(--olive-dark); transform: translateY(-1px); }

.settings-save:disabled { cursor: wait; opacity: .65; transform: none; }

.settings-note { display: flex; align-items: center; gap: 8px; margin: 20px 0 0; color: var(--muted); font-size: 10px; }

@media (max-width: 900px) {
  .login-view { gap: 50px; padding: 48px; }
  .story-title { font-size: clamp(48px, 7vw, 76px); }
  .chat-view { grid-template-columns: 275px minmax(0, 1fr); }
}

@media (max-width: 720px) {
  .login-view { display: block; padding: 28px 20px; }
  .login-story { display: none; }
  .login-panel { display: grid; place-items: center; min-height: calc(100dvh - 56px); max-width: none; }
  .login-card { width: min(100%, 460px); padding: 34px 28px; }
  .chat-view { display: flex; flex-direction: column; gap: 0; height: 100dvh; min-height: 0; max-height: 100dvh; padding: 0; }
  .sidebar, .chat-panel { border-radius: 0; }
  .sidebar { flex: 0 0 auto; max-height: 265px; padding: 18px 14px 12px; border-width: 0 0 1px; }
  .sidebar-top { padding-bottom: 15px; }
  .section-label { margin-top: 16px; }
  .conversation-list { display: flex; gap: 5px; overflow-x: auto; }
  .conversation-item { flex: 0 0 205px; margin: 0; }
  .sidebar-footer { display: none; }
  .chat-panel { flex: 1 1 auto; min-height: 0; border-width: 0; }
  .chat-header { padding: 18px 17px; }
  .header-chip { display: none; }
  .chat-banner { margin: 12px 17px 0; }
  .message-list { padding: 19px 17px; }
  .message-bubble { max-width: 84%; }
  .composer { margin: 0 17px 6px; }
  .settings-view { padding: 0; }
  .settings-shell { min-height: 100dvh; border-radius: 0; border-width: 0; }
  .settings-top { padding: 18px 17px; }
  .settings-top > span { display: none; }
  .settings-content { padding: 50px 20px 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
