: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: #17191b;
  --surface: #202326;
  --ink: #eae9e4;
  --muted: #aaa9a0;
  --gold: #a9905d;
  --line: #615a4c;
  --focus: #d9bb79;
  --composer-surface: #292c2e;
  --control-surface: #423c2f;
  --control-hover: #554b36;
  --reply-surface: #30302b;
  --reply-edge: #b69a5d;
  --error: #ffab96;
  --dialog-overlay: #100d0ab0;
  --glass-fill: linear-gradient(150deg,#363633,#292b2b);
  --glass-hover: linear-gradient(150deg,#4b463a,#35342f);
  --glass-border: #766b53;
  --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; }
:root[data-pointer-navigation] button:focus-visible { outline: none; }

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;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  overscroll-behavior: contain;
  padding: 10px 2px;
  outline: none;
}
#messages::-webkit-scrollbar { display: none; }
.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;
}
.reply-web-image { display: block; max-width: min(100%, 420px); max-height: 360px; width: auto; height: auto; object-fit: contain; margin: 10px 0; border-radius: 10px; }
.message.assistant.streaming-reply {
  box-sizing: border-box;
  overflow: hidden;
  transition: height 150ms cubic-bezier(.22, 1, .36, 1);
}
@media (prefers-reduced-motion: reduce) { .message.assistant.streaming-reply { transition: none; } }
.error { color: var(--error); }
.notice { color: var(--muted); }
.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);
  }
}

#conversation-tokens:not([hidden]), .reply-tokens {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
#conversation-tokens {
  position: absolute;
  inset-inline-end: 14px;
  inset-block-end: calc(100% + 4px);
}
.chatting .composer-area:has(#conversation-tokens:not([hidden])) { margin-top: 24px; }
.message.assistant:has(> .reply-tokens) {
  position: relative;
  margin-bottom: 26px;
}
.reply-tokens {
  position: absolute;
  inset-inline-start: -4px;
  inset-block-start: calc(100% + 2px);
  color: color-mix(in srgb, var(--muted) 78%, var(--paper));
  font-size: 10px;
  line-height: 12px;
  white-space: nowrap;
}

/* Message actions: a short fade on hover, delayed icon labels. */
.chat-message-wrap { width: fit-content; max-width: 90%; margin: 0 0 12px; }
.chat-message-wrap.user-wrap { margin-left: auto; }
.user-message-enter > .message { animation: user-message-in 200ms cubic-bezier(.22, 1, .36, 1) both; transform-origin: right bottom; }
@keyframes user-message-in { from { opacity: 0; transform: translateY(3px) scale(.99); } to { opacity: 1; transform: translateY(0) scale(1); } }
.sent-attachments { display: flex; justify-content: flex-end; align-items: flex-end; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.sent-attachments:last-child, .sent-attachments:has(+ .message[hidden]) { margin-bottom: 0; }
.sent-attachment-image { display: block; max-width: 140px; max-height: 140px; object-fit: contain; border-radius: 10px; }
.sent-attachment-file { display: flex; align-items: center; gap: 7px; max-width: 220px; padding: 10px 12px; border-radius: 11px; background: color-mix(in srgb, var(--ink) 6%, var(--surface)); color: var(--ink); font-size: 12px; }
.sent-attachment-file svg { flex: none; width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.5; }
.sent-attachment-file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { .user-message-enter > .message { animation: none; } }
.chat-message-wrap > .message { max-width: 100%; margin-bottom: 0; }
.chat-message-wrap > .message.assistant:has(> .reply-tokens) { margin-bottom: 15px; }
.chat-message-actions { display: flex; align-items: center; gap: 3px; min-height: 27px; margin-top: 2px; color: var(--muted); opacity: 0; visibility: hidden; transition: opacity 90ms ease, visibility 0s linear 90ms; }
.user-wrap .chat-message-actions { justify-content: flex-end; }
.chat-message-wrap:hover .chat-message-actions, .chat-message-wrap:focus-within .chat-message-actions { opacity: 1; visibility: visible; transition-delay: 0s; }
.chat-message-actions time { font-size: 11px; margin-right: 4px; font-variant-numeric: tabular-nums; }
.chat-message-action { position: relative; display: grid; place-items: center; width: 27px; height: 27px; padding: 4px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); }
.chat-message-action:hover, .chat-message-action:focus-visible { color: var(--ink); background: color-mix(in srgb, var(--ink) 6%, transparent); }
.chat-message-action svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.chat-message-action::after { content: attr(data-tooltip); position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translate(-50%, 3px); padding: 5px 8px; border-radius: 7px; background: var(--surface); background: color-mix(in srgb, var(--ink) 14.5%, var(--surface)); color: var(--ink); font-size: 12px; line-height: 1.2; white-space: nowrap; pointer-events: none; opacity: 0; visibility: hidden; transition: opacity 150ms ease, transform 150ms ease, visibility 0s linear 150ms; }
.chat-message-action:hover::after, .chat-message-action:focus-visible::after { opacity: 1; visibility: visible; transform: translate(-50%, 0); transition-delay: 550ms, 550ms, 550ms; }
@media (hover: none) { .chat-message-actions { opacity: 1; visibility: visible; } }
@media (prefers-reduced-motion: reduce) { .chat-message-actions, .chat-message-action::after { transition: none; } }

/* Chat type is adjusted only for precise-pointer desktop layouts. */
@media (hover:hover) and (pointer:fine) {
  #composer textarea, #messages .message.user, #messages .message.assistant { font-size:var(--chat-responsive-size, clamp(14px, calc(18.4px - 0.3125vw), 16px)); }
}
.chatting #messages.top-fade { -webkit-mask-image:linear-gradient(to bottom, transparent, #000 65px); mask-image:linear-gradient(to bottom, transparent, #000 65px); }

/* Keep message-action tooltips within the conversation viewport. */
.user-wrap .chat-message-action::after { left:auto; right:0; transform:translate(0,3px); }
.user-wrap .chat-message-action:hover::after, .user-wrap .chat-message-action:focus-visible::after { transform:translate(0,0); }
.assistant-wrap .chat-message-action:first-child::after { left:0; transform:translate(0,3px); }
.assistant-wrap .chat-message-action:first-child:hover::after, .assistant-wrap .chat-message-action:first-child:focus-visible::after { transform:translate(0,0); }
#thinking-panel { position:relative; display:flex; flex-direction:column; box-sizing:border-box; flex:none; width:100%; max-height:min(280px,44vh); overflow:hidden; margin:0 0 10px; padding:16px; border-radius:14px; background:var(--surface); color:var(--ink); box-shadow:0 8px 24px #0002; z-index:1; animation:thinking-in 180ms ease-out both; }
#thinking-panel.is-floating { position:fixed; top:max(12px,env(safe-area-inset-top)); right:12px; width:var(--thinking-width,260px); margin:0; }
#workspace-menu.sidebar-open ~ #thinking-panel.is-floating { filter:blur(3px); }
body.sidebar-pinned #workspace-menu.sidebar-open ~ #thinking-panel.is-floating { filter:none; }
#thinking-panel[hidden] { display:none; }
#thinking-panel.is-leaving { animation:thinking-out 180ms ease-in both; }
#thinking-panel strong { display:block; flex:none; font-size:14px; }
#thinking-content { flex:0 1 auto; min-height:0; max-height:125px; overflow-y:auto; margin-top:9px; color:var(--muted); font-size:13px; line-height:1.65; white-space:pre-wrap; overflow-wrap:anywhere; }
@keyframes thinking-in { from { opacity:0; transform:translateY(5px); } to { opacity:1; transform:none; } }
@keyframes thinking-out { to { opacity:0; transform:translateY(5px); } }
@media(prefers-reduced-motion:reduce) { #thinking-panel, #thinking-panel.is-leaving { animation:none; } }
.thinking-skill { display:flex; flex:none; align-items:center; gap:9px; margin-bottom:8px; padding:9px 10px; border-radius:10px; background:var(--surface-raised, rgba(127,127,127,.09)); color:var(--ink); font-size:13px; animation:thinking-in 180ms ease-out both; }
.thinking-skill svg { width:17px; height:17px; flex:none; color:var(--muted); }
.thinking-skill[hidden] { display:none; }
@media(prefers-reduced-motion:reduce) { .thinking-skill { animation:none; } }

.conversation-search-input-card { display:flex; align-items:center; gap:9px; padding:11px 13px; }
.conversation-search-input-card svg { flex:none; width:17px; height:17px; fill:none; stroke:var(--muted); stroke-width:1.7; stroke-linecap:round; }
.conversation-search-input-card input { flex:1; width:0; min-width:0; padding:0; border:0; outline:0; background:transparent; color:var(--ink); font:inherit; font-size:14px; }
.conversation-search-input-card input::placeholder { color:var(--muted); }
.conversation-search-input-card input::-webkit-search-cancel-button { cursor:pointer; }
.conversation-search-status { margin:0 8px; color:var(--muted); font-size:12px; line-height:1.5; }
.conversation-search-status:empty { display:none; }
#conversation-search-results { display:grid; gap:8px; }
.conversation-search-result { width:100%; padding:12px 13px; border:0; border-radius:12px; background:color-mix(in srgb,var(--ink) 4.5%,var(--surface)); color:var(--ink); text-align:left; cursor:pointer; transition:background 150ms ease,opacity 150ms ease,transform 150ms ease; animation:search-result-in 160ms ease-out both; }
.conversation-search-result:hover,.conversation-search-result:focus-visible { background:var(--sidebar-hover); }
.conversation-search-result small { display:block; margin-bottom:5px; color:var(--muted); font-size:11px; }
.conversation-search-result .excerpt { display:block; font-size:13px; line-height:1.6; overflow-wrap:anywhere; }
.conversation-search-result mark { color:var(--focus); background:transparent; font-weight:600; }
.preview-search-match { color:inherit; border-radius:3px; background:color-mix(in srgb,var(--focus) 38%,transparent); animation:search-hit 2.4s ease-out forwards; }
@keyframes search-result-in { from { opacity:0; transform:translateY(3px); } to { opacity:1; transform:none; } }
@keyframes search-hit { 0%,55% { background:color-mix(in srgb,var(--focus) 42%,transparent); } 100% { background:transparent; } }
@media(max-width:650px){.conversation-search-input-card input{font-size:16px;}}
@media(prefers-reduced-motion:reduce){.conversation-search-result,.preview-search-match{animation:none;transition:none;}}

#messages { scrollbar-width:none; -ms-overflow-style:none; }
#messages::-webkit-scrollbar { display:none; }
#chat-timeline { position:absolute; z-index:0; left:0; right:0; top:0; height:22px; display:flex; justify-content:flex-start; align-items:center; gap:clamp(3px, .5vw, 8px); overflow-x:auto; overflow-y:hidden; scrollbar-width:none; -ms-overflow-style:none; touch-action:pan-x; opacity:0; visibility:hidden; pointer-events:none; transform:translateY(-3px); transition:opacity 240ms ease, transform 240ms ease, visibility 0s linear 240ms; }
main.chatting header { position:relative; z-index:1; }
#chat-timeline::-webkit-scrollbar { display:none; }
#chat-timeline::before, #chat-timeline::after { content:""; flex:0 0 34px; }
#chat-timeline::before { margin-left:auto; }
#chat-timeline::after { margin-right:auto; }
#chat-timeline.fade-right { -webkit-mask-image:linear-gradient(to right,#000 0%,#000 calc(100% - 34px),transparent 100%); mask-image:linear-gradient(to right,#000 0%,#000 calc(100% - 34px),transparent 100%); }
#chat-timeline.fade-left { -webkit-mask-image:linear-gradient(to right,transparent 0%,#000 34px,#000 100%); mask-image:linear-gradient(to right,transparent 0%,#000 34px,#000 100%); }
#chat-timeline.fade-left.fade-right { -webkit-mask-image:linear-gradient(to right,transparent 0%,#000 34px,#000 calc(100% - 34px),transparent 100%); mask-image:linear-gradient(to right,transparent 0%,#000 34px,#000 calc(100% - 34px),transparent 100%); }
#chat-timeline.is-visible { opacity:1; visibility:visible; pointer-events:auto; transform:translateY(0); transition-delay:0s; }
#chat-timeline button { appearance:none; flex:0 0 10px; min-width:10px; height:20px; padding:0; border:0; background:transparent; position:relative; cursor:pointer; opacity:var(--ui-visibility,1); transition:opacity 120ms ease; }
#chat-timeline button::after { content:""; position:absolute; top:6px; bottom:6px; left:calc(50% - 1.25px); width:2.5px; border-radius:4px; background:color-mix(in srgb,var(--muted) 38%,transparent); transition:background 150ms ease,transform 150ms ease; }
#chat-timeline button::before { content:""; position:absolute; z-index:1; top:6px; bottom:6px; left:calc(50% - 1.25px); width:2.5px; border-radius:4px; background:var(--focus); opacity:var(--tick-activity,0); transform:scaleY(1.2); transition:opacity 180ms ease-out,transform 180ms ease-out; }
#chat-timeline button:hover::before, #chat-timeline button:focus-visible::before { opacity:1; transform:scaleY(1.3); }
@media(prefers-reduced-motion:reduce){#chat-timeline,#chat-timeline button,#chat-timeline button::before,#chat-timeline button::after{transition:none;}}
.preview-details { margin-top:6px; color:var(--muted); font-size:12px; line-height:1.5; }
.preview-details-controls { display:flex; flex-wrap:wrap; gap:16px; }
.preview-details-toggle { border:0; background:transparent; color:inherit; font:inherit; cursor:pointer; padding:3px 0; }
.preview-details-toggle::before { content:'▸'; display:inline-block; margin-right:5px; transition:transform 200ms ease; }
.preview-details-toggle[aria-expanded="true"]::before { transform:rotate(90deg); }
.preview-details-toggle:hover,.preview-details-toggle:focus-visible { color:var(--focus); }
.preview-details-panel { height:0; overflow:hidden; opacity:0; transition:height 220ms cubic-bezier(.22,.7,.25,1), opacity 180ms ease; }
.preview-details-panel.is-open { opacity:1; }
.preview-details-inner { transform:translateY(-8px); transition:transform 220ms cubic-bezier(.22,.7,.25,1); }
.preview-details-panel.is-open .preview-details-inner { transform:translateY(0); }
.preview-details-inner a { display:block; max-width:420px; margin-top:4px; color:var(--muted); overflow-wrap:anywhere; text-decoration:none; }
.preview-details-inner a:hover,.preview-details-inner a:focus-visible { color:var(--focus); text-decoration:underline; }
.preview-reasoning { white-space:pre-wrap; overflow-wrap:anywhere; }
.preview-file-download { display:block; margin-top:8px; padding:8px 12px; border:1px solid var(--line); border-radius:10px; background:var(--surface); color:var(--ink); font:inherit; font-size:13px; cursor:pointer; }
.preview-file-row { display:flex; align-items:center; gap:12px; }
.preview-file-progress { position:relative; flex:0 0 60px; height:3px; margin-top:8px; overflow:hidden; border-radius:99px; background:color-mix(in srgb, var(--line) 30%, transparent); }
.preview-file-progress[hidden] { display:none; }
.preview-file-progress span { position:absolute; inset:0; border-radius:inherit; background:var(--line); transform-origin:left; transform:scaleX(0); transition:transform 120ms ease-out; }
@media (prefers-reduced-motion: reduce) { .preview-file-progress span { transition:none; } }
.preview-file-status:not(:empty) { margin-top: 6px; color: var(--muted); font-size: 13px; }
.preview-file-download:hover,.preview-file-download:focus-visible { background:var(--control-surface); }
.preview-file-names { margin-top:5px; color:var(--muted); font-size:12px; overflow-wrap:anywhere; }
@media(prefers-reduced-motion:reduce) { .preview-details-panel,.preview-details-inner,.preview-details-toggle::before { transition:none; } }
