:root {
  color-scheme: light;
  --paper: #fbf8ef;
  --surface: #fffdf6;
  --ink: #383328;
  --muted: #756951;
  --gold: #d6b862;
  --line: #dfc879;
  --focus: #86651f;
  --composer-surface: #fffbed;
  --control-surface: #f9e9ae;
  --control-hover: #f4df92;
  --reply-surface: #f4ead2;
  --reply-edge: #9c752b;
  --error: #8a4433;
  --dialog-overlay: #35281736;
  --glass-fill: linear-gradient(150deg, rgb(255 254 243 / .6), rgb(245 209 109 / .28));
  --glass-hover: linear-gradient(150deg, rgb(255 250 223 / .66), rgb(245 209 109 / .46));
  --glass-border: rgb(210 181 107 / .65);
  --glass-shadow: inset 0 1px 3px #fffefa, inset 0 -1px 4px #a77b2520, 0 2px 8px #70531916;
  font-family: Inter, system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #1d1a16;
  --surface: #25211b;
  --ink: #f5eddd;
  --muted: #c2b49b;
  --gold: #a78340;
  --line: #806840;
  --focus: #edca73;
  --composer-surface: #29241b;
  --control-surface: #40331d;
  --control-hover: #534225;
  --reply-surface: #362c1d;
  --reply-edge: #c09a4b;
  --error: #ffab96;
  --dialog-overlay: #100d0ab0;
  --glass-fill: linear-gradient(150deg, rgb(75 61 40 / .94), rgb(43 35 24 / .86));
  --glass-hover: linear-gradient(150deg, rgb(100 80 47 / .97), rgb(60 48 29 / .92));
  --glass-border: #8a7145;
  --glass-shadow: inset 0 1px 3px #f5d89120, inset 0 -1px 4px #100d0a50, 0 2px 8px #100d0a60;
}

@keyframes theme-reveal {
  from { clip-path: circle(0px at var(--theme-reveal-origin)); }
  to { clip-path: circle(var(--theme-reveal-radius) at var(--theme-reveal-origin)); }
}

:root.theme-revealing::view-transition { pointer-events: none; }
:root.theme-revealing::view-transition-group(root) { animation: none; }
:root.theme-revealing::view-transition-old(root) {
  animation: none;
  mix-blend-mode: normal;
}
:root.theme-revealing::view-transition-new(root) {
  /* With linear x and y = t², the circle expands at constant acceleration. */
  animation: theme-reveal 480ms cubic-bezier(.333333, 0, .666667, .333333) both;
  mix-blend-mode: normal;
}

* { box-sizing: border-box; }
body { margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

main {
  position: relative;
  width: min(100% - 40px, 660px);
  min-height: var(--visible-chat-height, 100dvh);
  margin: auto;
  padding: 32px 0 max(32px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  justify-content: center;
}

header { text-align: center; }
.logo {
  display: block;
  width: 62px;
  height: 58px;
  margin: 0 auto 12px;
  padding: 0;
  border: 0;
  background: transparent;
}
.logo svg {
  display: block;
  width: 100%;
  height: 100%;
  color: var(--focus);
}
h1 {
  width: fit-content;
  margin: 0 auto;
  font: 400 clamp(54px, 10vw, 72px)/1.05 Inter, system-ui, sans-serif;
  letter-spacing: -.04em;
  padding-right: .04em;
}
header p, .tagline-transition {
  margin: 15px 0 0;
  color: var(--muted);
  font: 400 18px/1.5 Inter, system-ui, sans-serif;
  letter-spacing: .025em;
}
.tagline-transition {
  position: fixed;
  margin: 0;
  text-align: center;
  pointer-events: none;
}
.logo svg { transform-origin: center; }
#messages:empty { display: none; }
.composer-area {
  position: relative;
  flex: none;
  margin-top: 46px;
}
#composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 7px;
  background: var(--composer-surface);
  border: 1px solid var(--line);
  border-radius: 30px;
}
#composer:focus-within { border-color: var(--focus); }
textarea {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  max-height: 144px;
  padding: 10px 8px 10px 15px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  line-height: 24px;
}
textarea::placeholder { color: var(--muted); }
.send {
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  height: 44px;
  color: var(--focus);
  background: var(--control-surface);
  border: 0;
  border-radius: 50%;
}
.send:hover, .actions button:hover { background: var(--control-hover); }
.send:disabled { opacity: .5; cursor: wait; }

main.chatting {
  height: var(--visible-chat-height, 100dvh);
  min-height: 0;
  justify-content: flex-start;
  padding-top: max(18px, env(safe-area-inset-top));
}
.chatting header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding-bottom: 14px;
}
.chatting .logo { width: 28px; height: 44px; margin: 0; }
.chatting h1 { margin: 0; font-size: 36px; }
.chatting header p { display: none; }
#messages {
  flex: 1;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 10px 2px;
}
.chatting #messages {
  --scrollbar-offset: 12px;
  margin-inline-end: calc(-1 * var(--scrollbar-offset));
  padding-inline-end: calc(2px + var(--scrollbar-offset));
}
.message {
  width: fit-content;
  max-width: 90%;
  margin: 0 0 12px;
  padding: 10px 15px;
  border-radius: 20px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.6;
}
.user { margin-left: auto; border: 1px solid var(--line); }
.assistant {
  background: var(--reply-surface);
  border-inline-start: 4px solid var(--reply-edge);
  border-radius: 0 12px 12px 0;
  padding: 9px 14px;
}
.error { color: var(--error); }
.chatting .composer-area { margin-top: 12px; }

dialog {
  width: min(420px, 100% - 32px);
  max-height: calc(100dvh - 32px);
  padding: 24px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--gold);
  border-radius: 16px;
}
dialog::backdrop { background: var(--dialog-overlay); }
.dialog-head, .actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
h2 { margin: 0; font-size: 18px; font-weight: 500; }
dialog p { color: var(--muted); font-size: 13px; line-height: 1.5; }
dialog label { display: block; margin-top: 14px; font-size: 13px; }
dialog input, .actions button, #close {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
}
dialog input { display: block; margin-top: 5px; width: 100%; padding: 8px 10px; font-size: 16px; }
.actions button, #close { min-height: 44px; padding: 8px 12px; }

@media (max-width: 550px) {
  main { width: calc(100% - 32px); }
  .composer-area { margin-top: 36px; }
  main.chatting { padding-bottom: max(14px, env(safe-area-inset-bottom)); }
}

@media (max-width: 700px) and (prefers-reduced-motion: no-preference) {
  main:not(.chatting) > header,
  main:not(.chatting) > .composer-area {
    transform: translate3d(0, var(--welcome-offset, 0px), 0);
  }
}
