:root {
  color-scheme: light;
  --bg: #fafaf8; --surface: #fff; --rail: #f0f2f5; --ink: #162033;
  --muted: #515d6e; --line: #d9dee5; --accent: #174fcf; --tint: #e8efff;
  --backdrop: #18243659; --shadow: 0 4px 18px #23384914;
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #161b24; --surface: #202733; --rail: #1c2430; --ink: #f1f5fd;
  --muted: #b6c2d3; --line: #394657; --accent: #aac3ff; --tint: #273957;
  --backdrop: #05081088; --shadow: none;
}
* { box-sizing: border-box }
[hidden] { display: none !important }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink) }
body { display: flex; height: var(--viewport, 100dvh); overflow: hidden }
button, input, textarea { font: inherit; color: inherit; min-width: 0 }
button { cursor: pointer; touch-action: manipulation }
button:disabled { opacity: .5; cursor: default }
button, input, textarea { -webkit-tap-highlight-color: transparent }
a { color: var(--accent); text-underline-offset: .16em }
h1, h2, p { margin: 0 }
h1 { font-size: 16px; letter-spacing: -.02em; white-space: nowrap }
h2 { letter-spacing: -.035em }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, #chat:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px
}
button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round }
.icon, .quiet, .secondary, .primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; border: 1px solid transparent; border-radius: 12px; background: transparent;
}
.icon { width: 44px; flex: 0 0 44px; padding: 0 }
.quiet { color: var(--muted); padding: 4px 10px; font-size: 13px }
.secondary { border-color: var(--line); background: var(--surface); padding: 5px 12px }
.primary, #send { color: #fff; background: #174fcf; padding: 5px 12px }
:root[data-theme="dark"] .primary, :root[data-theme="dark"] #send { background: #aac3ff; color: #102345 }
@media (hover: hover) { button:not(:disabled):hover { filter: brightness(.94) } }
.workspace { min-width: 0; flex: 1; display: flex; flex-direction: column }
.topbar {
  display: flex; align-items: center; gap: 6px;
  min-height: 60px; padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 7px max(12px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.topbar-content { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0 }
.brand { display: flex; align-items: center; gap: 7px; flex: none }
.brand img { display: block }
.model-trigger {
  display: inline-flex; align-items: center; gap: 4px; min-height: 44px; max-width: 100%;
  background: transparent; border: 0; border-radius: 12px; font-size: 13px; padding: 5px 7px; color: var(--muted);
}
.model-trigger span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.model-trigger svg { flex: none; width: 13px; height: 13px }
.chat-heading {
  margin: 0 auto; display: flex; align-items: center; justify-content: space-between;
  max-width: 760px; width: 100%; padding: 0 18px; font-size: 13px; color: var(--muted);
}
#chat-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
#open-rename { flex: none }
#chat { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain }
.message-column { display: flex; flex-direction: column; width: min(100%, 760px); min-height: 100%; margin: auto; padding: 14px 18px 26px }
#message-list { display: flex; flex-direction: column; gap: 20px; min-width: 0 }
.empty { text-align: center; margin: auto; padding: 24px 0 38px }
.empty img { display: block; margin: 0 auto 15px }
.empty h2 { font-size: clamp(26px, 6vw, 38px); line-height: 1.16 }
.empty p { margin-top: 9px; color: var(--muted); font-size: 15px }
.message { min-width: 0; max-width: 100%; overflow-wrap: anywhere }
.message.user { align-self: flex-end; max-width: min(85%, 630px); border-radius: 20px 20px 6px 20px; padding: 10px 14px; background: var(--tint) }
.progress { align-self: flex-start; display: flex; align-items: center; gap: 10px; margin-top: 16px; padding: 8px 12px;
  border-radius: 12px; background: var(--rail); color: var(--muted); font-size: 14px }
.progress-dots { flex: none; display: flex; gap: 3px; color: var(--accent) }
.progress-dots i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; animation: pulse 1.25s ease-in-out infinite }
.progress-dots i:nth-child(2) { animation-delay: .15s }
.progress-dots i:nth-child(3) { animation-delay: .3s }
.progress[data-stage="paused"] .progress-dots { display: none }
@keyframes pulse { 0%, 70%, 100% { opacity: .45; transform: translateY(0) } 35% { opacity: 1; transform: translateY(-3px) } }
.message small { display: block; color: var(--muted); font-weight: 600; font-size: 12px; margin-bottom: 4px }
.message-content > :not(:last-child) { margin-bottom: .65em }
.message-content p { white-space: pre-wrap }
.message-content h3, .message-content h4 { margin-top: .6em; font-size: 1.1em }
.message-content ul, .message-content ol { padding-left: 1.45em; margin-top: .5em; margin-bottom: .5em }
.message-content pre { max-width: 100%; padding: 12px; background: var(--rail); border-radius: 12px; overflow-x: auto; margin: .6em 0 }
.message-content code { font-size: .87em; font-family: ui-monospace, SFMono-Regular, Consolas, monospace }
.message-content p code, .message-content li code { padding: .1em .25em; border-radius: 4px; background: var(--rail) }
.copy { margin-left: -10px; min-width: 44px }
#more-messages { align-self: center; margin-bottom: 8px }
.bottom { width: min(100%, 760px); margin: 0 auto; padding: 6px 16px max(10px, env(safe-area-inset-bottom)); background: var(--bg) }
.notice { margin: 0 6px 6px; color: var(--muted); font-size: 13px }
.notice:empty { display: none }
.access-notice { display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:8px; margin-bottom:8px;
  padding:9px 10px; background:var(--rail); border-radius:12px; font-size:14px }
.access-notice button { color:var(--accent); font-size:13px }
#usage-meter { width:100%; height:8px; accent-color:var(--accent) }
#plan-help { color:var(--muted); font-size:14px; margin-bottom:10px }
#plan-list { display:grid; gap:7px; margin-bottom:8px }
#plan-list .model-option { border-color:var(--line); background:var(--bg) }
#composer { display: flex; align-items: flex-end; gap: 6px; padding: 6px; border-radius: 21px; border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow) }
#composer:focus-within { border-color: var(--accent) }
#prompt { flex: 1; resize: none; min-height: 44px; max-height: 150px; border: 0; padding: 10px 8px; background: transparent; outline: none }
#send { border-radius: 14px; padding: 0 }
.limit-warning { color: var(--muted); font-size: 13px; margin: 5px 6px 0 }
.limit-warning:empty { display: none }
dialog { color: var(--ink); background: var(--surface); border: 1px solid var(--line) }
dialog::backdrop { background: var(--backdrop) }
.dialog-header { display: flex; flex: none; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px }
.dialog-header h2 { font-size: 20px }
dialog input { width: 100%; min-height: 44px; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 6px 10px }
.sheet {
  margin: auto auto 0; width: min(100%, 510px); max-width: 100%; max-height: min(85%, 720px);
  overflow-y: auto; overscroll-behavior: contain; border-radius: 24px 24px 0 0;
  padding: 13px 16px max(16px, env(safe-area-inset-bottom));
}
.sheet[open], .sidebar[open] { animation: appear 130ms ease-out }
@keyframes appear { from { opacity: 0; transform: translateY(5px) } }
#catalog-note, #catalog-page, #history-status, #promo-status, #rename-status { color: var(--muted); font-size: 13px }
#catalog-note { margin: 8px 0 }
#model-results { display: grid; gap: 3px }
.model-option, .chat-option {
  display: block; width: 100%; text-align: left; min-height: 44px; overflow-wrap: anywhere;
  padding: 7px 10px; border: 1px solid transparent; border-radius: 12px; background: transparent
}
.model-option small, .chat-option small { display: block; color: var(--muted); font-size: 13px }
.model-option[aria-current], .chat-option[aria-current] { color: var(--accent); background: var(--tint) }
div.model-option { color: var(--muted) }
#catalog-pages { display: flex; justify-content: space-between; align-items: center; margin-top: 10px }
#catalog-pages button { width: 44px }
.sidebar {
  display: flex; flex-direction: column; gap: 10px;
  margin: 0 auto 0 0; background: var(--rail);
  width: min(89vw, 340px); height: var(--viewport, 100dvh); max-height: 100%;
  border: 0; border-right: 1px solid var(--line);
  padding: max(10px, env(safe-area-inset-top)) 14px max(10px, env(safe-area-inset-bottom));
}
.sidebar:not([open]) { display: none }
@media (max-width: 919px) { .sidebar { touch-action: pan-y pinch-zoom } }
.sidebar > :not(.history-body) { flex-shrink: 0 }
.sidebar .dialog-header { margin: 0; padding: 0 1px 2px }
.sidebar .dialog-header h2 { font-size: 18px }
.sidebar .dialog-header .brand { gap: 9px }
.sidebar-new { justify-content: flex-start; gap: 10px; min-height: 45px; font-size: 15px; font-weight: 650 }
.sidebar-search { position: relative; display: block; color: var(--muted) }
.sidebar-search svg { position: absolute; top: 12px; left: 11px; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; pointer-events: none }
.sidebar-search input { padding-inline-start: 37px; font-size: 16px }
.sidebar-menu { display: grid; gap: 2px; padding-bottom: 9px; border-bottom: 1px solid var(--line) }
.menu-link { width: 100%; justify-content: flex-start; gap: 10px; padding: 4px 10px; color: var(--ink); font-size: 14px; text-align: left }
.menu-link svg { width: 19px; height: 19px; flex: none; color: var(--muted) }
.menu-link .nav-arrow { margin-inline-start: auto; width: 15px; height: 15px }
#history-title, #catalog h3 { margin: 1px 0 0; color: var(--muted); font-size: 13px; font-weight: 650 }
.purpose-nav { padding-bottom: 10px }
#purpose-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-top: 7px }
#purpose-actions .secondary { justify-content: flex-start; text-align: left; font-size: 13px }
.history-body { overflow: auto; overscroll-behavior: contain; flex: 1; min-height: 44px }
.chat-option { padding-inline: 10px; font-size: 14px }
.chat-option > span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.chat-option[aria-current] { font-weight: 650 }
#history-status, #promo-status, #rename-status { padding: 6px 1px }
#history-status:empty, #promo-status:empty, #rename-status:empty { display: none }
.sidebar-footer { border-top: 1px solid var(--line); padding-top: 5px; color: var(--muted); font-size: 13px }
.sidebar-footer .menu-link { min-height: 40px; color: var(--muted); font-size: 13px }
.sidebar-footer #paid-usage { padding: 0 10px 4px }
.gallery { width: min(100%, 640px) }
#gallery-results { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px }
.gallery-card { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: var(--rail) }
.gallery-card .generated { margin: 0; padding: 0 }
.gallery-card .generated img { width: 100%; aspect-ratio: 1; object-fit: contain; border-radius: 0 }
.gallery-card .generated > p { display: grid; padding: 8px; aspect-ratio: 1; align-items: center }
.gallery-card .quiet { font-size: 12px; padding-inline: 7px }
.gallery-card > button { width: 100%; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; border-top: 1px solid var(--line); border-radius: 0 }
#gallery-create, #gallery-more { margin-top: 12px }
@media (max-height: 550px) { .sidebar { overflow: auto; } }
.action-form { display: flex; gap: 6px; align-items: center }
.action-form input { flex: 1 }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%) }
@media (min-width: 920px) {
  .sidebar { position: static; flex: 0 0 290px; width: 290px; max-width: none }
  #close-history, #open-history { display: none }
  .topbar { padding-inline: 22px }
  .sheet { margin-top: auto; margin-bottom: auto; border-radius: 24px }
}
@media (prefers-reduced-motion: reduce) { .sheet[open], .sidebar[open], .progress-dots i { animation: none } }

.provider-mark { width: 25px; height: 25px; flex: 0 0 auto; object-fit: contain; background: #fff; border-radius: 6px; padding: 2px }
#selected-mark, .message small .provider-mark { width: 19px; height: 19px }
.model-trigger { gap: 6px }
.model-option { display: flex; align-items: center; gap: 9px }
.model-option > span { min-width: 0 }
.message small { display: flex; align-items: center; gap: 5px }
#image-mode { flex: none; font-weight: 600; padding-inline: 8px }
#image-mode[aria-pressed="true"] { color: var(--accent); background: var(--tint); border-color: var(--accent) }
.generated { margin: 8px 0 0; max-width: min(100%, 480px) }
.generated img { display: block; max-width: 100%; height: auto; border-radius: 14px }
.generated-actions { display: flex; flex-wrap: wrap; gap: 1px 2px; align-items: center }
.generated-actions button { color: var(--accent); font-weight: 650 }
