:root {
  --bg: #f7f7f5;
  --panel: rgba(255,255,255,.88);
  --panel-solid: #fff;
  --text: #202124;
  --muted: #777b82;
  --muted-2: #a0a3a8;
  --line: rgba(31,35,40,.11);
  --line-strong: rgba(31,35,40,.18);
  --hover: rgba(31,35,40,.055);
  --accent: #191a1c;
  --accent-text: #fff;
  --danger: #b5483f;
  --soft: rgba(255,255,255,.5);
  --shadow: 0 18px 60px rgba(30,32,36,.07), 0 1px 2px rgba(30,32,36,.05);
  --popup-shadow: 0 20px 55px rgba(30,32,36,.14), 0 4px 14px rgba(30,32,36,.07);
}

:root[data-theme="dark"] {
  --bg: #171817;
  --panel: rgba(35,36,35,.94);
  --panel-solid: #232423;
  --text: #f2f2ef;
  --muted: #9b9d98;
  --muted-2: #767873;
  --line: rgba(255,255,255,.10);
  --line-strong: rgba(255,255,255,.18);
  --hover: rgba(255,255,255,.07);
  --accent: #f0f0ed;
  --accent-text: #171817;
  --danger: #df776d;
  --soft: rgba(255,255,255,.04);
  --shadow: 0 18px 60px rgba(0,0,0,.22), 0 1px 2px rgba(0,0,0,.24);
  --popup-shadow: 0 20px 60px rgba(0,0,0,.38), 0 3px 12px rgba(0,0,0,.24);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  min-height: 100vh;
  background: radial-gradient(circle at 50% 20%, rgba(255,255,255,.58), transparent 31%), var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
:root[data-theme="dark"] body { background: radial-gradient(circle at 50% 18%, rgba(255,255,255,.035), transparent 30%), var(--bg); }
button, textarea, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: inherit; }

.app-shell, .simple-shell { min-height: 100vh; display: grid; grid-template-rows: auto 1fr auto; }
.topbar, .simple-topbar {
  height: 72px; display: flex; align-items: center; justify-content: space-between; padding: 0 28px;
}
.simple-topbar { max-width: 1180px; width: 100%; margin: 0 auto; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 650; letter-spacing: .01em; }
.brand-mark { width: 28px; height: 28px; display: grid; place-items: center; }
.brand-mark svg { width: 100%; height: 100%; }
.brand-name { font-size: 15px; }
.top-actions { display: flex; align-items: center; gap: 9px; }
.ghost-btn, .login-btn, .text-btn, .icon-btn, .tool-chip, .send-btn, .suggestion, .menu-item, .tool-option, .primary-wide, .secondary-wide {
  border: 0; cursor: pointer;
}
.ghost-btn { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: transparent; }
.ghost-btn:hover { background: var(--hover); }
.ghost-btn svg { width: 19px; height: 19px; }
.login-btn, .text-btn { height: 38px; padding: 0 16px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; font-size: 14px; font-weight: 600; }
.login-btn { background: var(--accent); color: var(--accent-text); }
.text-btn { background: transparent; }
.text-btn:hover { background: var(--hover); }
.login-btn:active, .send-btn:active, .primary-wide:active { transform: translateY(1px); }

.main-area { width: min(780px, calc(100% - 32px)); margin: 0 auto; padding: 9vh 0 40px; }
.welcome { text-align: center; margin-bottom: 34px; }
.hero-icon { width: 52px; height: 52px; margin: 0 auto 18px; display: grid; place-items: center; border-radius: 18px; background: var(--panel-solid); box-shadow: 0 8px 30px rgba(0,0,0,.06); }
.hero-icon svg { width: 29px; height: 29px; }
.welcome h1 { margin: 0; font-size: clamp(28px,4vw,40px); line-height: 1.18; letter-spacing: -.035em; font-weight: 680; }
.subtitle { margin: 12px auto 0; color: var(--muted); font-size: 15px; line-height: 1.7; }

.composer-card { width: 100%; }
.input-wrap { min-height: 138px; border: 1px solid var(--line); background: var(--panel); backdrop-filter: blur(18px); border-radius: 24px; box-shadow: var(--shadow); padding: 8px; position: relative; overflow: visible; }
textarea { display: block; width: 100%; min-height: 70px; max-height: 180px; resize: none; border: 0; outline: none; background: transparent; color: var(--text); padding: 16px 16px 8px; font-size: 16px; line-height: 1.55; }
textarea::placeholder, input::placeholder { color: var(--muted-2); }
.composer-actions { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 2px; }
.left-actions { display: flex; align-items: center; gap: 6px; }
.menu-anchor { position: relative; }
.icon-btn { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; background: transparent; }
.icon-btn:hover, .tool-chip:hover, .icon-btn[aria-expanded="true"], .tool-chip[aria-expanded="true"] { background: var(--hover); }
.icon-btn svg { width: 20px; height: 20px; }
.tool-chip { height: 38px; display: inline-flex; align-items: center; gap: 6px; border-radius: 12px; padding: 0 9px 0 10px; background: transparent; font-size: 14px; }
.tool-chip > svg:first-child { width: 17px; height: 17px; }
.chevron { width: 15px; height: 15px; opacity: .65; transition: transform .16s ease; }
.tool-chip[aria-expanded="true"] .chevron { transform: rotate(180deg); }
.send-btn { width: 40px; height: 40px; border-radius: 14px; display: grid; place-items: center; background: var(--accent); color: var(--accent-text); }
.send-btn svg { width: 20px; height: 20px; }
.disclaimer { margin: 10px 0 0; text-align: center; color: var(--muted); font-size: 12px; }

.popover { position: absolute; z-index: 30; left: 0; bottom: calc(100% + 10px); min-width: 252px; border: 1px solid var(--line); background: var(--panel-solid); border-radius: 17px; padding: 7px; box-shadow: var(--popup-shadow); }
.popover[hidden] { display: none; }
.add-menu { width: 272px; }
.tool-menu { width: 286px; }
.popover-title { padding: 7px 9px 6px; font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.menu-item, .tool-option { width: 100%; min-height: 54px; border-radius: 12px; background: transparent; display: flex; align-items: center; text-align: left; padding: 9px 10px; }
.menu-item:hover, .tool-option:hover { background: var(--hover); }
.menu-icon { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 10px; display: grid; place-items: center; margin-right: 10px; flex: 0 0 auto; }
.menu-icon svg { width: 18px; height: 18px; }
.menu-item strong, .option-copy strong { display: block; font-size: 13px; font-weight: 640; }
.menu-item small, .option-copy small { display: block; margin-top: 3px; font-size: 11px; color: var(--muted); }
.tool-option { justify-content: space-between; gap: 12px; }
.option-copy { min-width: 0; }
.check { opacity: 0; font-size: 15px; font-weight: 700; }
.tool-option.is-active .check { opacity: 1; }
.tool-option.is-active { background: var(--hover); }

.suggestions { margin-top: 26px; display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 10px; }
.suggestion { min-height: 84px; display: flex; gap: 10px; align-items: flex-start; text-align: left; padding: 14px; border: 1px solid var(--line); border-radius: 18px; background: rgba(255,255,255,.30); }
:root[data-theme="dark"] .suggestion { background: rgba(255,255,255,.025); }
.suggestion:hover { background: var(--hover); }
.suggestion-icon { width: 20px; text-align: center; line-height: 1.4; opacity: .76; }
.suggestion strong { display: block; font-size: 13px; font-weight: 650; }
.suggestion small { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; line-height: 1.45; }

.footer { min-height: 58px; display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 7px; color: var(--muted); font-size: 12px; padding: 12px 20px 20px; }
.footer a { color: inherit; text-decoration: none; }
.footer a:hover, .footer a[aria-current="page"] { text-decoration: underline; }
.dot { opacity: .5; }

.toast { position: fixed; left: 50%; bottom: 28px; z-index: 70; transform: translateX(-50%); max-width: calc(100% - 32px); border: 1px solid var(--line); background: var(--panel-solid); color: var(--text); box-shadow: var(--popup-shadow); border-radius: 999px; padding: 10px 16px; font-size: 12px; white-space: nowrap; }
.toast[hidden] { display: none; }

/* Authentication */
.auth-wrap { width: min(430px, calc(100% - 32px)); margin: 0 auto; display: flex; align-items: center; justify-content: center; padding: 42px 0 64px; }
.auth-wrap-register { width: min(450px, calc(100% - 32px)); }
.auth-card { width: 100%; border: 1px solid var(--line); background: var(--panel); backdrop-filter: blur(16px); border-radius: 24px; box-shadow: var(--shadow); padding: 30px; }
.auth-head { text-align: center; margin-bottom: 26px; }
.auth-head h1 { margin: 0; font-size: 28px; letter-spacing: -.025em; }
.auth-head p { margin: 9px 0 0; color: var(--muted); font-size: 14px; }
.auth-form { display: grid; gap: 16px; }
.field { display: grid; gap: 8px; }
.field > span { font-size: 13px; font-weight: 600; }
.field em { color: var(--danger); font-style: normal; font-size: 11px; font-weight: 700; margin-left: 5px; }
.field input { width: 100%; height: 46px; border: 1px solid var(--line-strong); border-radius: 12px; outline: none; background: var(--panel-solid); color: var(--text); padding: 0 13px; transition: border-color .15s ease, box-shadow .15s ease; }
.field input:focus { border-color: var(--text); box-shadow: 0 0 0 3px var(--hover); }
.invite-field input { border-style: solid; }
.form-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.check-row { display: flex; align-items: flex-start; gap: 8px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.check-row input { margin: 1px 0 0; accent-color: var(--text); }
.check-row a { color: var(--text); }
.terms-check { margin-top: -2px; }
.muted-link { color: var(--muted); text-decoration: none; font-size: 12px; }
.muted-link:hover { text-decoration: underline; }
.primary-wide, .secondary-wide { width: 100%; height: 46px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; font-weight: 650; font-size: 14px; }
.primary-wide { background: var(--accent); color: var(--accent-text); }
.secondary-wide { border: 1px solid var(--line-strong); background: transparent; color: var(--text); }
.secondary-wide:hover { background: var(--hover); }
.form-status { margin: -4px 0 0; border-radius: 10px; background: var(--hover); color: var(--muted); padding: 9px 11px; font-size: 11px; line-height: 1.5; }
.auth-divider { display: flex; align-items: center; gap: 12px; color: var(--muted); margin: 22px 0 14px; font-size: 11px; }
.auth-divider::before, .auth-divider::after { content: ""; height: 1px; background: var(--line); flex: 1; }

/* Legal */
.legal-topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: blur(14px); }
.back-link { color: var(--muted); text-decoration: none; font-size: 13px; }
.back-link:hover { color: var(--text); }
.legal-wrap { width: min(860px, calc(100% - 32px)); margin: 0 auto; padding: 42px 0 68px; }
.legal-card { border: 1px solid var(--line); background: var(--panel); border-radius: 24px; box-shadow: var(--shadow); padding: clamp(26px,5vw,54px); }
.legal-header { padding-bottom: 28px; border-bottom: 1px solid var(--line); margin-bottom: 30px; }
.eyebrow { color: var(--muted); font-size: 10px; letter-spacing: .16em; font-weight: 800; }
.legal-header h1 { margin: 10px 0 8px; font-size: clamp(30px,5vw,42px); letter-spacing: -.035em; }
.legal-header p { margin: 0; color: var(--muted); font-size: 13px; }
.legal-card section + section { margin-top: 28px; }
.legal-card h2 { margin: 0 0 10px; font-size: 17px; letter-spacing: -.01em; }
.legal-card p { margin: 0; color: color-mix(in srgb, var(--text) 78%, var(--muted)); font-size: 14px; line-height: 1.9; }
.legal-card p + p { margin-top: 10px; }

@media (max-width: 720px) {
  .topbar, .simple-topbar { height: 64px; padding: 0 16px; }
  .main-area { padding-top: 8vh; }
  .suggestions { grid-template-columns: 1fr; }
  .suggestion { min-height: 72px; }
  .auth-card { padding: 24px 20px; border-radius: 20px; }
  .legal-wrap { padding-top: 24px; }
  .legal-card { border-radius: 20px; }
}
@media (max-width: 480px) {
  .brand-name { font-size: 14px; }
  .top-actions { gap: 4px; }
  .login-btn, .text-btn { height: 36px; padding: 0 12px; }
  .welcome { margin-bottom: 26px; }
  .hero-icon { width: 46px; height: 46px; border-radius: 16px; }
  .input-wrap { min-height: 130px; border-radius: 20px; }
  .main-area { width: min(100% - 22px,780px); }
  .popover { position: fixed; left: 12px; right: 12px; bottom: 18px; width: auto; min-width: 0; }
  .toast { white-space: normal; text-align: center; width: max-content; }
  .form-row { align-items: flex-start; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}

/* Generation modes */
.mode-chip {
  height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  border-radius: 12px;
  padding: 0 10px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
}
.mode-chip:hover { background: var(--hover); }
.mode-chip svg { width: 17px; height: 17px; flex: 0 0 auto; }
.mode-chip[aria-pressed="true"] {
  background: var(--hover);
  box-shadow: inset 0 0 0 1px var(--line-strong);
  font-weight: 600;
}

@media (max-width: 640px) {
  .main-area { width: min(100% - 20px, 780px); padding-top: 6vh; }
  .input-wrap { border-radius: 20px; }
  .left-actions { gap: 2px; min-width: 0; }
  .tool-chip, .mode-chip { padding-left: 8px; padding-right: 8px; }
  .mode-chip span { display: none; }
  .mode-chip { width: 38px; justify-content: center; }
}
