:root {
  color-scheme: light dark;
  --app-bg: #f6f7f8;
  --surface: #ffffff;
  --surface-soft: #f1f7f2;
  --surface-muted: #eef1f0;
  --line: #e2e7e3;
  --text: #171b18;
  --muted: #69726b;
  --accent: #087f3e;
  --accent-strong: #056a32;
  --accent-soft: #e7f5ec;
  --danger: #b42318;
  --warning: #a15c00;
  --shadow: 0 12px 30px rgba(32, 51, 39, 0.08);
  --radius: 16px;
  --radius-small: 12px;
  --tap-size: 44px;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --app-bg: #121714;
    --surface: #1b211d;
    --surface-soft: #173221;
    --surface-muted: #252d27;
    --line: #344037;
    --text: #f1f5f1;
    --muted: #b3beb5;
    --accent: #35b56b;
    --accent-strong: #54cb85;
    --accent-soft: #163b25;
    --danger: #ff8377;
    --warning: #f3b25d;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.26);
  }
}

:root[data-theme="light"] {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --app-bg: #121714;
  --surface: #1b211d;
  --surface-soft: #173221;
  --surface-muted: #252d27;
  --line: #344037;
  --text: #f1f5f1;
  --muted: #b3beb5;
  --accent: #35b56b;
  --accent-strong: #54cb85;
  --accent-soft: #163b25;
  --danger: #ff8377;
  --warning: #f3b25d;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.26);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--app-bg);
}

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  background: var(--app-bg);
  font-size: 16px;
  line-height: 1.45;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  min-height: var(--tap-size);
  border: 0;
  border-radius: var(--radius-small);
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 2px;
}

input,
textarea,
select {
  width: 100%;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--surface);
}

input,
select {
  min-height: var(--tap-size);
  padding: 0 13px;
}

textarea {
  min-height: 112px;
  padding: 12px 13px;
  resize: vertical;
}

textarea::placeholder,
input::placeholder {
  color: var(--muted);
  opacity: 0.85;
}

button:active {
  transform: translateY(1px);
}

.app-shell {
  width: min(100%, 720px);
  min-height: var(--visual-viewport-height, 100dvh);
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(90px + env(safe-area-inset-bottom));
}

.top-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  margin-bottom: 14px;
}

.top-bar h1,
.top-bar h2 {
  margin: 0;
  font-size: 23px;
  letter-spacing: -0.02em;
}

.top-bar h2 {
  flex: 1;
  font-size: 18px;
  text-align: center;
}

.top-bar__copy {
  flex: 1;
  min-width: 0;
}

.top-bar__copy p {
  margin: 2px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button {
  display: inline-grid;
  width: var(--tap-size);
  height: var(--tap-size);
  min-width: var(--tap-size);
  padding: 0;
  place-items: center;
  color: var(--text);
  background: transparent;
  font-size: 24px;
}

.icon-button--quiet {
  color: var(--muted);
}

.primary-button,
.secondary-button,
.quiet-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: var(--tap-size);
  padding: 0 16px;
  font-weight: 650;
  white-space: nowrap;
}

.primary-button {
  color: #fff;
  background: var(--accent);
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  color: var(--accent);
  border: 1px solid var(--accent);
  background: var(--surface);
}

.quiet-button {
  color: var(--text);
  border: 1px solid var(--line);
  background: var(--surface);
}

.danger-button {
  color: #fff;
  background: var(--danger);
}

.wide-button {
  width: 100%;
}

.screen {
  display: grid;
  gap: 14px;
}

.panel,
.list-card,
.composer-card,
.draft-card,
.account-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.section-heading h2,
.section-heading h3 {
  margin: 0;
  font-size: 17px;
}

.section-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.context-switcher {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  min-height: 44px;
  padding: 0 13px;
  overflow: hidden;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--surface);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.context-switcher span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--surface-soft);
  color: var(--text);
  font-size: 14px;
}

.notice--error {
  border-color: color-mix(in srgb, var(--danger) 35%, var(--line));
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
}

.notice--warning {
  border-color: color-mix(in srgb, var(--warning) 35%, var(--line));
  background: color-mix(in srgb, var(--warning) 11%, var(--surface));
}

.notice--offline {
  position: sticky;
  top: calc(env(safe-area-inset-top) + 4px);
  z-index: 3;
}

.session-list,
.setting-list {
  overflow: hidden;
}

.session-row,
.setting-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 82px;
  padding: 12px;
  color: var(--text);
  border-radius: 0;
  background: transparent;
  text-align: left;
}

.session-row + .session-row,
.setting-row + .setting-row {
  border-top: 1px solid var(--line);
}

.session-row:hover,
.setting-row:hover {
  background: var(--surface-soft);
}

.avatar {
  display: inline-grid;
  width: 48px;
  height: 48px;
  place-items: center;
  color: #fff;
  border-radius: 12px;
  background: linear-gradient(135deg, #4b8c65, #8db79c);
  font-size: 25px;
  font-weight: 700;
}

.avatar--large {
  width: 76px;
  height: 76px;
  border-radius: 15px;
  font-size: 36px;
}

.session-copy,
.setting-copy {
  min-width: 0;
}

.session-copy strong,
.setting-copy strong {
  display: block;
  overflow: hidden;
  font-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-copy span,
.setting-copy span {
  display: block;
  overflow: hidden;
  margin-top: 3px;
  color: var(--muted);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-status {
  color: var(--accent);
  font-size: 14px;
  font-weight: 650;
}

.chevron {
  color: var(--muted);
  font-size: 24px;
  font-weight: 300;
}

.empty-state,
.loading-state {
  display: grid;
  min-height: 220px;
  padding: 30px 20px;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.empty-state > div,
.loading-state > div {
  max-width: 280px;
}

.empty-state strong,
.loading-state strong {
  display: block;
  margin-bottom: 7px;
  color: var(--text);
  font-size: 18px;
}

.loading-bars {
  display: grid;
  gap: 10px;
  width: 100%;
}

.loading-bars span {
  height: 52px;
  border-radius: var(--radius-small);
  background: linear-gradient(90deg, var(--surface-muted), var(--surface), var(--surface-muted));
  background-size: 220% 100%;
  animation: loading-shimmer 1.2s ease-in-out infinite;
}

.chat-screen {
  gap: 12px;
}

.chat-meta {
  margin-top: -8px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.message-stream {
  display: grid;
  gap: 12px;
  min-height: 150px;
}

.message-date {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.message-row {
  display: flex;
  gap: 9px;
  align-items: flex-start;
}

.message-row--draft {
  justify-content: flex-end;
}

.message-bubble {
  max-width: min(82%, 510px);
  padding: 12px 14px;
  border-radius: 15px;
  background: var(--surface-muted);
  white-space: pre-wrap;
  word-break: break-word;
}

.message-bubble--draft {
  color: #fff;
  background: var(--accent);
}

.message-caption {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.composer-card,
.draft-card {
  padding: 14px;
}

.composer-card h3,
.draft-card h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.action-row,
.tone-row,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.action-row {
  margin-top: 10px;
}

.tone-row {
  margin: 10px 0;
}

.tone-row strong {
  width: 100%;
  font-size: 14px;
}

.tone-button {
  min-height: 40px;
  padding: 0 13px;
  color: var(--text);
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 14px;
}

.tone-button[aria-pressed="true"] {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 650;
}

.helper-text {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.draft-card {
  border-color: color-mix(in srgb, var(--accent) 27%, var(--line));
}

.draft-card__label {
  display: inline-flex;
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.draft-card textarea {
  min-height: 122px;
}

.screenshot-preview {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  gap: 11px;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--surface-soft);
}

.screenshot-preview img {
  width: 78px;
  height: 78px;
  object-fit: cover;
  border-radius: 9px;
  background: var(--surface-muted);
}

.screenshot-preview p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
}

.ocr-result {
  margin-top: 10px;
}

.ocr-result textarea {
  min-height: 92px;
}

.profile-hero {
  display: flex;
  gap: 15px;
  align-items: center;
  padding: 16px;
}

.profile-hero h2 {
  margin: 0;
  font-size: 22px;
}

.profile-hero p {
  margin: 4px 0 0;
  color: var(--muted);
}

.profile-note {
  margin: 0 16px 16px;
}

.nav-bar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 4;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  min-height: calc(64px + env(safe-area-inset-bottom));
  padding: 6px max(16px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.nav-button {
  display: grid;
  min-height: 52px;
  padding: 4px;
  place-items: center;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
}

.nav-button span:first-child {
  font-size: 21px;
  line-height: 1;
}

.nav-button[aria-current="page"] {
  color: var(--accent);
  font-weight: 700;
}

.form-stack {
  display: grid;
  gap: 13px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label,
.field legend {
  color: var(--text);
  font-size: 14px;
  font-weight: 650;
}

.field small {
  color: var(--muted);
  font-size: 13px;
}

.auth-shell {
  display: grid;
  min-height: 100dvh;
  padding: max(24px, env(safe-area-inset-top)) 22px max(24px, env(safe-area-inset-bottom));
  place-items: center;
}

.auth-card {
  display: grid;
  gap: 20px;
  width: 100%;
  min-width: 0;
  max-width: 420px;
  padding: 26px 20px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-card h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: -0.04em;
}

.auth-card > p {
  margin: -12px 0 0;
  color: var(--muted);
}

.auth-switch {
  min-height: 32px;
  padding: 0;
  color: var(--accent);
  background: transparent;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  align-items: end;
  background: rgba(15, 22, 17, 0.42);
}

.sheet {
  max-height: min(86dvh, 680px);
  padding: 14px 16px calc(18px + env(safe-area-inset-bottom));
  overflow: auto;
  border-radius: 22px 22px 0 0;
  background: var(--surface);
  box-shadow: 0 -16px 42px rgba(0, 0, 0, 0.16);
}

.sheet__handle {
  width: 36px;
  height: 4px;
  margin: 0 auto 16px;
  border-radius: 999px;
  background: var(--line);
}

.sheet__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.sheet__header h2 {
  margin: 0;
  font-size: 19px;
}

.radio-list {
  display: grid;
  gap: 8px;
  margin: 8px 0 14px;
}

.radio-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 50px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--surface);
}

.radio-item input {
  width: 21px;
  height: 21px;
  min-height: 21px;
  accent-color: var(--accent);
}

.radio-item span {
  display: grid;
}

.radio-item small {
  color: var(--muted);
}

.status-line {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.status-line--error {
  color: var(--danger);
}

.status-line--success {
  color: var(--accent);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes loading-shimmer {
  from { background-position: 100% 0; }
  to { background-position: -120% 0; }
}

@media (min-width: 760px) {
  body {
    padding: 22px;
  }

  .app-shell,
  .auth-shell {
    min-height: calc(100dvh - 44px);
    border: 1px solid var(--line);
    border-radius: 24px;
    background: var(--app-bg);
    box-shadow: var(--shadow);
  }

  .nav-bar {
    right: auto;
    left: 50%;
    width: min(100%, 720px);
    transform: translateX(-50%);
    border-right: 1px solid var(--line);
    border-left: 1px solid var(--line);
    border-radius: 0 0 24px 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
