:root {
  color-scheme: dark;
  --background: #08090b;
  --background-elevated: #0d0f12;
  --surface: #121419;
  --surface-strong: #181b21;
  --surface-muted: #20242b;
  --text: #f7f7f4;
  --text-soft: #deded8;
  --text-muted: #9b9b96;
  --gold: #d8b06a;
  --gold-bright: #f0cb86;
  --gold-dark: #6f5934;
  --red: #d93845;
  --red-bright: #f04a57;
  --red-dark: #641923;
  --danger: #ff727d;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.17);
  --shadow: 0 28px 90px rgba(0, 0, 0, 0.54);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --motion-fast: 140ms;
  --motion-base: 220ms;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--background);
}

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 72% -10%, rgba(217, 56, 69, 0.17), transparent 34rem),
    radial-gradient(circle at 4% 100%, rgba(216, 176, 106, 0.07), transparent 30rem),
    var(--background);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
}

button,
textarea,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

button:not(:disabled) {
  cursor: pointer;
}

button:focus-visible,
textarea:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid var(--gold-bright);
  outline-offset: 3px;
}

.is-hidden {
  display: none !important;
}

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

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: #120b08;
  background: var(--gold-bright);
  font-weight: 800;
  transform: translateY(-150%);
  transition: transform var(--motion-fast) ease;
}

.skip-link:focus {
  transform: translateY(0);
}

.background-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.2;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(to bottom, black, transparent 75%);
}

.background-glow {
  position: fixed;
  width: 26rem;
  height: 26rem;
  border: 1px solid rgba(255, 255, 255, 0.045);
  border-radius: 50%;
  pointer-events: none;
}

.background-glow--one {
  top: -20rem;
  left: -8rem;
  box-shadow: 0 0 0 5rem rgba(217, 56, 69, 0.018), 0 0 0 10rem rgba(255, 255, 255, 0.008);
}

.background-glow--two {
  right: -18rem;
  bottom: -14rem;
  box-shadow: 0 0 0 5rem rgba(217, 56, 69, 0.018), 0 0 0 10rem rgba(255, 255, 255, 0.008);
}

.startup {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 20px;
  color: var(--text-soft);
  background: var(--background);
}

.startup p {
  margin: 0;
}

.loader {
  width: 32px;
  height: 32px;
  border: 2px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(100% - 48px, 1080px);
  height: calc(100dvh - 48px);
  margin: 24px auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: rgba(13, 15, 18, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

.app-header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 28px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(17, 19, 23, 0.9);
}

.brand-block {
  min-width: 0;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 6px;
  color: #d8aeb2;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.18em;
}

.eyebrow span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--red-bright);
  box-shadow: 0 0 0 4px rgba(240, 74, 87, 0.1);
}

.app-header h1 {
  margin: 0;
  color: var(--text);
  font-size: clamp(22px, 3vw, 30px);
  line-height: 1.25;
  letter-spacing: 0.035em;
  text-wrap: balance;
}

.warning-line {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  max-width: 46rem;
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

.warning-line svg {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  margin-top: 2px;
  fill: none;
  stroke: var(--gold);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.logout-button {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-soft);
  background: rgba(255, 255, 255, 0.025);
  transition: border-color var(--motion-fast) ease, color var(--motion-fast) ease, background var(--motion-fast) ease;
}

.logout-button:hover:not(:disabled) {
  border-color: var(--border-strong);
  color: var(--text);
  background: var(--surface-muted);
}

.logout-button:active:not(:disabled) {
  background: var(--red-dark);
}

.logout-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.conversation {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: var(--gold-dark) transparent;
  padding: 36px clamp(20px, 5vw, 64px);
}

.empty-state {
  display: grid;
  min-height: 100%;
  place-content: center;
  justify-items: center;
  max-width: 610px;
  margin: auto;
  text-align: center;
}

.login-seal {
  display: grid;
  place-items: center;
  color: var(--gold-bright);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.08), transparent 38%),
    radial-gradient(circle at 50% 30%, #bd303a, #72121b 64%, #3a090d);
  border: 1px solid var(--gold);
  box-shadow: 0 16px 46px rgba(89, 8, 15, 0.42), inset 0 0 0 5px rgba(7, 4, 3, 0.22);
}

.empty-state__title {
  margin: 0;
  color: var(--text);
  font-size: clamp(28px, 5vw, 44px);
  font-weight: 750;
  letter-spacing: -0.04em;
  text-wrap: balance;
}

.empty-state__copy {
  max-width: 35rem;
  margin: 14px 0 0;
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.8;
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 820px;
  margin: 0 auto;
}

.message {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  animation: message-in var(--motion-base) ease-out both;
}

@keyframes message-in {
  from { opacity: 0; transform: translateY(8px); }
}

.message--user {
  justify-content: flex-end;
}

.message__avatar {
  display: grid;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  place-items: center;
  margin-top: 2px;
  border: 1px solid var(--border-strong);
  border-radius: 10px 4px 10px 4px;
  color: var(--gold-bright);
  background: var(--red-dark);
  font-size: 13px;
  font-weight: 900;
}

.message__body {
  min-width: 0;
  max-width: min(78%, 680px);
}

.message__label {
  margin: 0 0 6px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.message--user .message__label {
  text-align: right;
}

.message__content {
  margin: 0;
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: 5px 16px 16px 16px;
  color: var(--text-soft);
  background: var(--surface);
  line-height: 1.72;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message--user .message__content {
  border-color: rgba(212, 59, 71, 0.34);
  border-radius: 16px 5px 16px 16px;
  color: #fff5e8;
  background: linear-gradient(145deg, #7f1520, #5d0e16);
}

.message--error .message__content {
  border-color: rgba(255, 114, 125, 0.46);
  color: #ffdadd;
  background: rgba(76, 14, 20, 0.54);
}

.message__retry {
  min-height: 40px;
  margin-top: 10px;
  padding: 0 14px;
  border: 1px solid rgba(255, 114, 125, 0.5);
  border-radius: 999px;
  color: #ffe5e7;
  background: transparent;
}

.message__retry:hover {
  background: rgba(169, 31, 43, 0.28);
}

.typing-caret::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 4px;
  vertical-align: -0.12em;
  background: var(--gold);
  animation: blink 0.9s steps(1) infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

.composer-area {
  position: relative;
  z-index: 2;
  padding: 10px clamp(16px, 4vw, 40px) calc(18px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: rgba(11, 13, 16, 0.97);
}

.chat-status {
  min-height: 22px;
  max-width: 820px;
  margin: 0 auto 6px;
  color: var(--text-muted);
  font-size: 13px;
}

.chat-status--error {
  color: #ff9aa2;
}

.composer-form {
  max-width: 820px;
  margin: 0 auto;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #14171b;
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.22);
  transition: border-color var(--motion-fast) ease, box-shadow var(--motion-fast) ease;
}

.composer-form:focus-within {
  border-color: rgba(240, 74, 87, 0.7);
  box-shadow: 0 0 0 3px rgba(240, 74, 87, 0.1), 0 14px 44px rgba(0, 0, 0, 0.24);
}

.composer-form textarea {
  display: block;
  width: 100%;
  min-height: 48px;
  max-height: 180px;
  resize: none;
  padding: 5px 6px;
  overflow-y: hidden;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  line-height: 1.6;
}

.composer-form textarea::placeholder {
  color: #9c8c77;
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  margin-top: 6px;
}

.composer-hint,
.character-count {
  color: var(--text-muted);
  font-size: 12px;
}

.character-count {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}

.send-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 92px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(135deg, var(--red-bright), #b92532);
  box-shadow: 0 8px 24px rgba(185, 37, 50, 0.26);
  font-weight: 900;
  transition: filter var(--motion-fast) ease, box-shadow var(--motion-fast) ease;
}

.send-button:hover:not(:disabled) {
  filter: brightness(1.08);
  box-shadow: 0 10px 28px rgba(217, 56, 69, 0.35);
}

.send-button:active:not(:disabled) {
  filter: brightness(0.94);
}

.send-button:disabled,
.logout-button:disabled,
.login-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.send-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.login-screen {
  position: fixed;
  z-index: 40;
  inset: 0;
  display: grid;
  place-items: center;
  overflow-y: auto;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  background: rgba(5, 3, 2, 0.78);
  backdrop-filter: blur(16px);
}

.login-card {
  position: relative;
  width: min(100%, 470px);
  padding: 42px clamp(24px, 7vw, 52px) 38px;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 50% 0, rgba(169, 31, 43, 0.22), transparent 16rem),
    linear-gradient(150deg, rgba(33, 23, 19, 0.98), rgba(12, 9, 7, 0.99));
  box-shadow: var(--shadow), inset 0 1px rgba(255, 255, 255, 0.04);
  text-align: center;
  animation: login-in 280ms ease-out both;
}

@keyframes login-in {
  from { opacity: 0; transform: translateY(12px); }
}

.login-card::before {
  content: "";
  position: absolute;
  inset: 8px;
  pointer-events: none;
  border: 1px solid rgba(226, 185, 102, 0.07);
  border-radius: 18px;
}

.login-card__topline {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 26px;
  color: var(--gold);
  font-size: 10px;
  letter-spacing: 0.19em;
}

.login-card__topline span {
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-dark));
}

.login-card__topline span:last-child {
  transform: rotate(180deg);
}

.login-seal {
  width: 68px;
  height: 68px;
  margin: 0 auto 18px;
  border-radius: 50%;
  font-size: 27px;
  font-weight: 900;
}

.login-kicker {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.22em;
}

.login-card h1 {
  margin: 0;
  font-size: clamp(25px, 7vw, 34px);
  line-height: 1.25;
  text-wrap: balance;
}

.login-warning {
  margin: 12px 0 30px;
  color: #d8c39f;
  font-size: 13px;
}

.login-form {
  position: relative;
  z-index: 1;
  text-align: left;
}

.login-form > label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-soft);
  font-size: 14px;
  font-weight: 700;
}

.password-field {
  display: flex;
  align-items: stretch;
  min-height: 48px;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: rgba(7, 5, 4, 0.72);
}

.password-field:focus-within {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(226, 185, 102, 0.09);
}

.password-field input {
  min-width: 0;
  flex: 1;
  padding: 11px 14px;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
}

.password-field button {
  min-width: 64px;
  border: 0;
  border-left: 1px solid var(--border);
  color: var(--gold-bright);
  background: var(--surface-strong);
  font-size: 13px;
  font-weight: 700;
}

.password-field button:hover {
  background: var(--surface-muted);
}

.login-helper,
.form-error {
  min-height: 21px;
  margin: 7px 0 0;
  font-size: 12px;
}

.login-helper {
  color: var(--text-muted);
}

.form-error {
  color: #ff9aa2;
}

.login-button {
  width: 100%;
  min-height: 48px;
  margin-top: 12px;
  border: 1px solid var(--gold);
  border-radius: 12px 4px 12px 4px;
  color: #fff1c9;
  background: linear-gradient(135deg, #a91f2b, #6e1119);
  box-shadow: 0 12px 30px rgba(89, 8, 15, 0.36);
  font-weight: 900;
  letter-spacing: 0.08em;
  transition: filter var(--motion-fast) ease, background var(--motion-fast) ease;
}

.login-button:hover:not(:disabled) {
  filter: brightness(1.12);
}

@media (max-width: 680px) {
  body {
    background: var(--background);
  }

  .background-glow,
  .background-grid {
    opacity: 0.22;
  }

  .app-shell {
    width: 100%;
    height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  .app-header {
    gap: 10px;
    padding: calc(16px + env(safe-area-inset-top)) 16px 15px;
  }

  .eyebrow {
    font-size: 9px;
  }

  .eyebrow span {
    width: 18px;
  }

  .app-header h1 {
    font-size: 20px;
  }

  .warning-line {
    font-size: 12px;
  }

  .logout-button {
    min-width: 44px;
    padding: 0;
  }

  .logout-button span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .conversation {
    padding: 24px 16px;
  }

  .empty-state__copy {
    max-width: 19rem;
  }

  .message-list {
    gap: 20px;
  }

  .message__body {
    max-width: calc(100% - 44px);
  }

  .composer-area {
    padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  }

  .composer-form {
    padding: 9px;
  }

  .composer-hint {
    display: none;
  }

  .character-count {
    margin-left: 4px;
  }

  .send-button {
    min-width: 76px;
    padding: 0 13px;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .app-header {
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .warning-line,
  .eyebrow {
    display: none;
  }

  .conversation {
    padding-top: 14px;
    padding-bottom: 14px;
  }

  .empty-state {
    text-align: center;
  }

  .chat-status {
    display: none;
  }

  .composer-area {
    padding-top: 7px;
    padding-bottom: 7px;
  }

  .composer-form textarea {
    min-height: 36px;
  }
}

@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;
  }
}
