:root {
  color-scheme: light;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: #242333;
  background: #f8f7fb;
  --canvas: #f8f7fb;
  --accent: #6d5bd0;
  --accent-ink: #5341ad;
  --accent-surface: #efecfb;
  --muted: #605d70;
  --line: #e4e1eb;
  --neutral: #f0eef4;
  --shadow: #28204412;
  --paper: #fff;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
a { color: var(--accent-ink); }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:disabled, select:disabled { cursor: wait; opacity: .55; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
button { border: 0; border-radius: 9px; font-weight: 650; padding: .68rem .9rem; }
button:hover:not(:disabled) { filter: brightness(.93); }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.8rem, 4.5vw, 2.8rem); line-height: 1.05; letter-spacing: -.045em; }
h2 { font-size: 1.05rem; }
p { line-height: 1.55; }
.topbar {
  min-height: 66px; display: flex; align-items: center; gap: 1rem;
  padding: .65rem clamp(.75rem, 4vw, 2.7rem); background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; font-size: 1.26rem; font-weight: 750; white-space: nowrap; }
.brand-mark { position: relative; width: 36px; height: 36px; overflow: hidden; border-radius: 9px; }
.brand-mark img {
  position: absolute; width: 116px; height: auto; left: 50%; top: 50%;
  transform: translate(-50%, -41.4%);
}
nav { display: flex; gap: .2rem; margin-left: auto; }
nav a { text-decoration: none; color: var(--muted); padding: .5rem .65rem; border-radius: 8px; font-weight: 600; }
nav a:hover, nav a[aria-current] { background: var(--accent-surface); color: var(--accent-ink); }
.primary { background: var(--accent); color: white; }
.quiet { background: var(--neutral); color: var(--accent-ink); }
.danger { color: #8c2e2e; }
.heading { display: grid; gap: .65rem; }
.heading p, .panel p, .account p { color: var(--muted); }
.auth-layout {
  display: grid; place-items: center; min-height: calc(100dvh - 66px); padding: 1.25rem;
  background: radial-gradient(ellipse at 50% 15%, #f0edf9 0%, var(--canvas) 62%);
}
.auth-layout.login-layout {
  background: radial-gradient(ellipse at 50% 15%, #2d2550 0%, #1e1a33 70%);
}
body:has(.auth-layout.login-layout) .topbar {
  background: #25203d; border-bottom-color: #ffffff17;
}
body:has(.auth-layout.login-layout) .topbar a { color: #f5f1ff; }
body:has(.auth-layout.login-layout) .topbar nav a:is(:hover, [aria-current]),
body:has(.auth-layout.login-layout) .topbar .quiet {
  background: #ffffff1a; color: #fff;
}
.auth-card, .panel, .plan, .account { background: var(--paper); border: 1px solid var(--line); border-radius: 17px; }
.auth-card { width: min(100%, 440px); padding: clamp(1.1rem, 5vw, 2.3rem); box-shadow: 0 18px 62px var(--shadow); }
.login-layout .auth-card { box-shadow: 0 18px 52px #100b2866; }
.auth-card .heading { margin-bottom: 1.6rem; }
.stack, label { display: grid; gap: .5rem; }
.stack { gap: 1rem; }
.code-field { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: .5rem; }
.code-field + .notice { margin-bottom: 0; }
label { font-weight: 620; }
input:not([type=radio],[type=checkbox]), textarea, select {
  width: 100%; min-width: 0; border: 1px solid #c6c1d2; border-radius: 9px;
  background: white; color: inherit; padding: .65rem .75rem;
}
.notice { color: #8b3530; margin: .65rem 0; overflow-wrap: anywhere; }
.notice:empty { display: none; }
.auth-card > .quiet { margin-top: .9rem; width: 100%; }
.page { width: min(1120px, 100%); margin: auto; padding: clamp(1.15rem, 5vw, 3rem); }
.page > .heading { margin-bottom: 1.6rem; }
.panel, .plan, .account { padding: 1.1rem; }
.plan { display: grid; gap: .4rem; }
.price { font-weight: 700; color: var(--accent-ink); }
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: .75rem; }
.plans + .panel { margin-top: 1rem; }
.plan.coming-soon { color: var(--muted); background: var(--neutral); }
.panel { display: grid; gap: .65rem; }
.wallet, .code { display: flex; align-items: center; flex-wrap: wrap; gap: .75rem; padding: .8rem; background: var(--neutral); border-radius: 9px; }
code { overflow-wrap: anywhere; min-width: 0; user-select: all; }
.code > .notice { flex-basis: 100%; margin: 0; }
.create-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(105px, auto) auto; align-items: end; gap: .85rem; }
.check { display: flex; align-items: center; grid-column: 1 / 3; grid-row: 2; }
.accounts { display: grid; gap: .6rem; margin-top: .85rem; }
.account { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; gap: .7rem; overflow-wrap: anywhere; }
.badge { color: var(--accent-ink); background: var(--accent-surface); padding: .25rem .55rem; border-radius: 20px; font-size: .86rem; }
.badge[data-status=blocked], .badge[data-status=expired] { color: #812d2b; background: #f9e8e4; }
.badge[data-status=pending] { color: #704b0b; background: #faf0d6; }
.actions { display: flex; flex-wrap: wrap; gap: .45rem; grid-column: 1 / -1; }
.actions select { width: auto; }
.workspace { min-height: calc(100dvh - 66px); display: grid; grid-template-columns: minmax(210px, 265px) minmax(0, 1fr); }
.sidebar {
  background: var(--paper); border-right: 1px solid var(--line); padding: 1.1rem;
  display: flex; flex-direction: column; gap: .95rem; height: calc(100dvh - 66px);
}
.sidebar h2 { color: var(--muted); }
.new-chat { color: var(--accent-ink); background: var(--accent-surface); text-align: left; }
.history { flex: 1; overflow: auto; display: flex; align-items: stretch; flex-direction: column; gap: .35rem; min-height: 0; }
.history p, .profile p { color: var(--muted); font-size: .89rem; }
.history-item { text-align: left; color: inherit; background: transparent; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: none; }
.history-item:hover, .history-item[aria-current] { background: var(--accent-surface); color: var(--accent-ink); }
.profile { border-top: 1px solid var(--line); padding-top: .8rem; overflow-wrap: anywhere; }
.countdown { font-variant-numeric: tabular-nums; font-weight: 650; }
.quota { display: grid; gap: .25rem; margin: .5rem 0; font-size: .89rem; }
.quota progress { width: 100%; height: .6rem; accent-color: var(--accent); }
.chat { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: calc(100dvh - 66px); }
.chat-toolbar { padding: .6rem 1rem 0; text-align: right; min-height: 48px; }
.messages { overflow: auto; padding: 1rem clamp(1rem, 6vw, 5rem); display: flex; flex-direction: column; gap: 1.15rem; }
.welcome { text-align: center; margin: auto; padding: 1rem; }
.message { width: min(100%, 780px); margin: 0 auto; padding: 1rem; border-radius: 14px; }
.message.user { background: var(--accent-surface); }
.message.assistant { background: white; border: 1px solid var(--line); }
.message-label { display: flex; align-items: center; gap: .6rem; font-weight: 700; margin-bottom: .5rem; }
.message-label span { color: var(--muted); font-size: .82rem; font-weight: 550; }
.message-content { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.58; }
.message-image { display: grid; justify-items: start; gap: .65rem; margin-top: .55rem; }
.message-image img { display: block; max-width: 100%; max-height: 60dvh; object-fit: contain; border-radius: 10px; }
.image-download { text-decoration: none; padding: .45rem .7rem; border-radius: 8px; font-weight: 650; }
.compose-area { width: min(100%, 840px); margin: 0 auto; padding: .3rem 1rem 1rem; }
.composer { background: white; border: 1px solid var(--line); padding: .6rem; border-radius: 14px; box-shadow: 0 6px 30px var(--shadow); }
.composer textarea { resize: vertical; max-height: 32vh; border: 0; }
.composer-bar { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }
.composer-bar > .primary { margin-left: auto; }
.composer-modes, .attachments { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin-bottom: .45rem; }
.composer-modes button[aria-pressed="true"] { background: var(--accent-surface); color: var(--accent-ink); }
.attachment-name, .image-tier { color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.image-tier { align-self: center; }
.modes {
  display: grid; grid-template-columns: repeat(2, minmax(70px, 1fr));
  align-self: center; border: 1px solid var(--line); border-radius: 9px; overflow: hidden;
}
.modes label { display: block; position: relative; cursor: pointer; }
.modes label + label { border-left: 1px solid var(--line); }
.modes input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.modes span {
  display: grid; place-items: center; min-height: 44px; padding: .45rem .65rem;
  color: var(--muted); background: var(--neutral); font-size: .9rem;
}
.modes label:hover input:not(:checked):not(:disabled) + span { background: var(--accent-surface); }
.modes input:checked + span { background: var(--accent); color: #fff; }
.modes input:focus-visible + span { outline: 2px solid var(--accent-ink); outline-offset: -4px; }
.modes input:checked:focus-visible + span { outline-color: #fff; }
.modes input:disabled + span { opacity: .5; cursor: not-allowed; }
@media (max-width: 650px) {
  .topbar { gap: .35rem; flex-wrap: wrap; }
  nav a { padding-inline: .45rem; }
  .workspace { display: flex; flex-direction: column; }
  .sidebar { height: auto; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .45rem .65rem; padding: .65rem; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar h2 { align-self: center; grid-row: 1; grid-column: 2; }
  .history { display: flex; flex-direction: row; overflow-x: auto; grid-column: 1 / -1; }
  .history-item { max-width: 13rem; }
  .profile { padding-top: .35rem; font-size: .86rem; grid-column: 1 / -1; }
  .profile p { display: inline-block; margin-right: .6rem; }
  .profile strong { display: block; }
  .chat { height: auto; min-height: 58dvh; grid-template-rows: auto minmax(220px, 1fr) auto; }
  .chat-toolbar { min-height: 24px; }
  .compose-area { position: sticky; bottom: 0; background: var(--canvas); }
  .create-form { grid-template-columns: 1fr; align-items: stretch; }
  .check { grid-column: auto; grid-row: auto; }
}
