:root {
  color-scheme: light;
  --ink: #201d18;
  --muted: #686159;
  --faint: #8d867d;
  --page: #ebe8df;
  --paper: #fbfaf6;
  --paper-strong: #ffffff;
  --surface: #f2efe7;
  --line: #d8d2c6;
  --line-strong: #bdb5a7;
  --accent: #2f654b;
  --accent-deep: #1f4937;
  --accent-soft: #dce9df;
  --accent-ink: #17382a;
  --signal: #9b3f36;
  --gold: #a97d35;
  --shadow-sm: 0 8px 20px rgba(40, 34, 26, 0.08);
  --shadow-lg: 0 24px 64px rgba(40, 34, 26, 0.15);
  --motion: 180ms ease;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--page);
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  font-family: Inter, "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif;
  background: var(--page);
}

body::before {
  position: fixed;
  inset: 0 0 auto;
  z-index: -1;
  height: 5px;
  background: var(--accent);
  content: "";
  transition: background-color var(--motion);
}

button,
textarea,
select {
  font: inherit;
}

button,
a,
select {
  touch-action: manipulation;
}

button {
  letter-spacing: 0;
}

a {
  color: inherit;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1,
h2,
h3 {
  font-family: "Noto Serif SC", Georgia, serif;
  letter-spacing: 0;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 200;
  padding: 10px 14px;
  color: #fff;
  background: var(--accent-deep);
  transform: translateY(-150%);
  transition: transform var(--motion);
}

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

.site-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  width: min(1440px, calc(100% - 40px));
  min-height: 66px;
  margin: 5px auto 0;
}

.site-mark {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  min-height: 44px;
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
  text-transform: uppercase;
}

.site-mark strong {
  color: var(--accent-deep);
  font-family: "Noto Serif SC", Georgia, serif;
  font-size: 1.05rem;
  transition: color var(--motion);
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.site-nav a {
  display: grid;
  min-height: 44px;
  place-items: center;
  padding: 0 10px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
}

.site-nav a:hover,
.site-nav a:focus-visible {
  color: var(--accent-deep);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(286px, 330px) minmax(0, 1fr);
  align-items: start;
  gap: 18px;
  width: min(1440px, calc(100% - 32px));
  min-height: calc(100dvh - 87px);
  margin: 0 auto 16px;
}

.character-panel,
.chat-panel {
  border: 1px solid var(--line);
  background: var(--paper);
  box-shadow: var(--shadow-sm);
}

.character-panel {
  position: sticky;
  top: 16px;
  display: grid;
  gap: 18px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 16px;
}

.portrait-wrap {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: clamp(190px, 30vh, 250px);
  border: 1px solid var(--line-strong);
  background: var(--surface);
}

.portrait-wrap::after {
  position: absolute;
  inset: auto 0 0;
  height: 32%;
  background: linear-gradient(to bottom, transparent, rgba(20, 18, 15, 0.58));
  content: "";
  pointer-events: none;
}

.portrait-wrap img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity var(--motion), transform 320ms ease;
}

.character-panel.is-changing .portrait-wrap img {
  opacity: 0.72;
  transform: scale(1.015);
}

.portrait-status {
  position: absolute;
  right: 12px;
  bottom: 11px;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
}

.portrait-status > span {
  width: 8px;
  height: 8px;
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  background: #68ba81;
  box-shadow: 0 0 0 3px rgba(26, 27, 22, 0.28);
}

.profile-copy {
  display: grid;
  gap: 7px;
  padding: 0 4px 2px;
}

.eyebrow {
  color: var(--signal);
  font-size: 0.69rem;
  font-weight: 800;
  text-transform: uppercase;
}

.profile-copy h1 {
  font-size: clamp(2rem, 3vw, 2.8rem);
  line-height: 1.05;
}

.role {
  color: var(--accent-deep);
  font-size: 0.9rem;
  font-weight: 800;
  transition: color var(--motion);
}

.summary {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.62;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.character-switcher {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding-top: 15px;
  border-top: 1px solid var(--line);
}

.switch-button {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  padding: 5px 7px;
  cursor: pointer;
  text-align: left;
  transition: color var(--motion), background-color var(--motion), border-color var(--motion);
}

.switch-button img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  filter: saturate(0.76);
  transition: filter var(--motion);
}

.switch-button span {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.2;
}

.switch-button:hover,
.switch-button:focus-visible {
  border-color: var(--line);
  color: var(--ink);
  background: var(--surface);
  outline: none;
}

.switch-button.is-active {
  border-color: color-mix(in srgb, var(--accent) 36%, var(--line));
  color: var(--accent-ink);
  background: var(--accent-soft);
}

.switch-button.is-active img {
  filter: saturate(1);
}

.mobile-character-control {
  display: none;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto auto minmax(260px, 1fr) auto;
  min-height: calc(100dvh - 87px);
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 84px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--paper-strong);
}

.chat-heading {
  display: grid;
  gap: 4px;
}

.chat-heading h2 {
  font-size: clamp(1.75rem, 3vw, 2.65rem);
  line-height: 1.12;
}

.chat-controls {
  display: flex;
  align-items: end;
  gap: 12px;
}

.spoiler-control {
  display: grid;
  gap: 6px;
}

.spoiler-control > span,
.mobile-character-control > span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.spoiler-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-width: 220px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.spoiler-button {
  min-height: 44px;
  border: 0;
  border-radius: 5px;
  color: var(--muted);
  background: transparent;
  padding: 0 12px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 800;
  transition: color var(--motion), background-color var(--motion), box-shadow var(--motion);
}

.spoiler-button:hover,
.spoiler-button:focus-visible {
  color: var(--ink);
  outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent);
  outline-offset: 1px;
}

.spoiler-button.is-active {
  color: var(--accent-ink);
  background: var(--paper-strong);
  box-shadow: 0 2px 8px rgba(38, 33, 26, 0.1);
}

.reset-button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  padding: 0 14px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 800;
  transition: color var(--motion), border-color var(--motion), background-color var(--motion);
}

.reset-button:hover,
.reset-button:focus-visible {
  border-color: var(--line-strong);
  color: var(--ink);
  background: var(--surface);
  outline: none;
}

.prompt-panel {
  display: grid;
  grid-template-columns: minmax(180px, 0.8fr) minmax(0, 2.2fr);
  gap: 22px;
  padding: 14px 24px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.prompt-heading {
  display: grid;
  align-content: start;
  gap: 5px;
}

.prompt-heading h3 {
  font-size: 1.18rem;
}

.character-lens {
  max-width: 34ch;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.prompt-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.prompt-button {
  position: relative;
  display: grid;
  align-content: space-between;
  gap: 14px;
  min-width: 0;
  min-height: 94px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: var(--paper-strong);
  padding: 13px 14px;
  cursor: pointer;
  text-align: left;
  transition: border-color var(--motion), box-shadow var(--motion), transform var(--motion);
}

.prompt-button::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--accent);
  content: "";
  transition: background-color var(--motion);
}

.prompt-button:hover,
.prompt-button:focus-visible {
  border-color: color-mix(in srgb, var(--accent) 42%, var(--line));
  box-shadow: var(--shadow-sm);
  outline: none;
  transform: translateY(-2px);
}

.prompt-button:active {
  transform: translateY(0);
}

.prompt-kind {
  color: var(--accent-deep);
  font-size: 0.67rem;
  font-weight: 800;
  text-transform: uppercase;
}

.prompt-text {
  overflow-wrap: anywhere;
  font-family: "Noto Serif SC", Georgia, serif;
  font-size: 0.93rem;
  font-weight: 600;
  line-height: 1.38;
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 17px;
  min-height: 0;
  overflow-y: auto;
  padding: 26px clamp(20px, 4vw, 52px);
  background: var(--paper);
  scroll-behavior: smooth;
  scrollbar-color: var(--line-strong) transparent;
}

.message {
  display: grid;
  gap: 7px;
  width: min(720px, 88%);
  animation: message-enter 220ms ease-out both;
}

.message-user {
  align-self: end;
  width: min(620px, 82%);
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 24px;
}

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

.message-avatar {
  width: 24px;
  height: 24px;
  border: 1px solid var(--line);
  border-radius: 50%;
  object-fit: cover;
}

.message-avatar-user {
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--accent-deep);
  font-size: 0.68rem;
  font-weight: 800;
}

.message-label {
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 800;
}

.message-bubble {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--paper-strong);
  padding: 14px 16px;
  font-size: 0.98rem;
  line-height: 1.7;
  white-space: pre-wrap;
  box-shadow: 0 3px 12px rgba(38, 33, 26, 0.05);
}

.message-assistant .message-bubble {
  border-left: 3px solid var(--accent);
}

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

.message-system .message-bubble {
  border-color: #bd6e66;
  color: #fff;
  background: #8e3b34;
}

.source-links {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding-left: 3px;
}

.source-links a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  border: 1px solid color-mix(in srgb, var(--accent) 24%, var(--line));
  border-radius: 999px;
  color: var(--accent-deep);
  background: var(--accent-soft);
  padding: 6px 10px;
  font-size: 0.75rem;
  font-weight: 800;
  text-decoration: none;
}

.source-links a:hover,
.source-links a:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.composer {
  display: grid;
  gap: 8px;
  padding: 12px 24px 16px;
  border-top: 1px solid var(--line);
  background: var(--paper-strong);
}

.composer-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.composer-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 9px;
  align-items: end;
}

.composer textarea {
  width: 100%;
  min-height: 56px;
  max-height: 180px;
  resize: none;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  color: var(--ink);
  background: var(--paper);
  padding: 13px 14px;
  font-size: 1rem;
  line-height: 1.5;
  transition: border-color var(--motion), box-shadow var(--motion), background-color var(--motion);
}

.composer textarea:focus {
  border-color: var(--accent);
  background: var(--paper-strong);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
  outline: none;
}

.composer textarea::placeholder {
  color: var(--faint);
}

.composer button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 116px;
  min-height: 56px;
  border: 1px solid var(--accent-deep);
  border-radius: 7px;
  color: #fff;
  background: var(--accent-deep);
  padding: 0 18px;
  cursor: pointer;
  font-weight: 900;
  transition: background-color var(--motion), border-color var(--motion), box-shadow var(--motion);
}

.composer button:hover,
.composer button:focus-visible {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: 0 7px 18px color-mix(in srgb, var(--accent) 22%, transparent);
  outline: none;
}

.composer button:disabled,
.reset-button:disabled,
.prompt-button:disabled,
.spoiler-button:disabled,
.switch-button:disabled,
.mobile-character-control select:disabled {
  cursor: wait;
  opacity: 0.56;
}

.send-arrow {
  font-size: 1.15rem;
  line-height: 1;
}

.thinking-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  pointer-events: none;
  padding: 20px;
  opacity: 0;
  background: rgba(25, 24, 20, 0);
  backdrop-filter: blur(0);
  transform: translateY(6px);
  transition: opacity var(--motion), transform var(--motion), background-color var(--motion), backdrop-filter var(--motion);
}

.thinking-overlay.is-visible {
  opacity: 1;
  background: rgba(25, 24, 20, 0.22);
  backdrop-filter: blur(4px);
  transform: translateY(0);
}

.thinking-card {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  align-items: center;
  gap: 15px;
  width: min(430px, calc(100vw - 32px));
  border: 1px solid var(--line-strong);
  border-top: 4px solid var(--accent);
  border-radius: 8px;
  color: var(--ink);
  background: var(--paper-strong);
  box-shadow: var(--shadow-lg);
  padding: 17px 18px 18px;
}

.thinking-card p {
  font-family: "Noto Serif SC", Georgia, serif;
  font-size: 0.98rem;
  font-weight: 600;
  line-height: 1.48;
}

.thinking-mark {
  position: relative;
  width: 44px;
  height: 44px;
  border: 2px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: thinking-spin 950ms linear infinite;
}

.thinking-mark::before,
.thinking-mark::after {
  position: absolute;
  border-radius: 50%;
  content: "";
}

.thinking-mark::before {
  inset: 6px;
  border: 1px solid var(--gold);
  border-right-color: transparent;
  animation: thinking-spin 1400ms linear infinite reverse;
}

.thinking-mark::after {
  inset: 13px;
  background: var(--accent);
}

.thinking-core {
  display: none;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
}

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

@keyframes thinking-spin {
  to {
    transform: rotate(1turn);
  }
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: minmax(250px, 290px) minmax(0, 1fr);
  }

  .character-switcher {
    grid-template-columns: 1fr;
  }

  .prompt-panel {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .character-lens {
    max-width: 60ch;
  }
}

@media (max-width: 860px) {
  .site-bar {
    width: min(100% - 24px, 680px);
    min-height: 58px;
  }

  .site-mark > span,
  .site-nav {
    display: none;
  }

  .site-mark strong {
    font-size: 1.12rem;
  }

  .app-shell {
    grid-template-columns: 1fr;
    width: min(100% - 20px, 680px);
    min-height: 0;
    margin-bottom: 10px;
  }

  .character-panel {
    position: static;
    grid-template-columns: 112px minmax(0, 1fr);
    align-items: center;
    gap: 14px;
    max-height: none;
    overflow: visible;
    padding: 12px;
  }

  .portrait-wrap {
    grid-row: span 2;
    height: auto;
    aspect-ratio: 4 / 5;
  }

  .portrait-status {
    right: 8px;
    bottom: 8px;
    font-size: 0;
  }

  .profile-copy {
    align-content: center;
    padding: 0;
  }

  .profile-copy h1 {
    font-size: clamp(1.75rem, 8vw, 2.4rem);
  }

  .summary {
    font-size: 0.82rem;
    -webkit-line-clamp: 2;
  }

  .character-switcher {
    display: none;
  }

  .mobile-character-control {
    display: grid;
    gap: 6px;
    align-self: end;
  }

  .mobile-character-control select {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    color: var(--ink);
    background: var(--paper-strong);
    padding: 0 11px;
    font-weight: 700;
  }

  .chat-panel {
    grid-template-rows: auto auto minmax(420px, 1fr) auto;
    min-height: calc(100dvh - 240px);
  }

  .chat-header {
    align-items: stretch;
    flex-direction: column;
    gap: 14px;
    min-height: 0;
    padding: 16px;
  }

  .chat-controls {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .spoiler-control {
    flex: 1 1 180px;
    min-width: 0;
  }

  .spoiler-tabs {
    min-width: 0;
  }

  .reset-button {
    flex: 0 1 auto;
    max-width: 100%;
    min-width: 118px;
    align-self: end;
    white-space: normal;
  }

  .prompt-panel {
    padding: 15px 16px 17px;
  }

  .prompt-list {
    display: flex;
    gap: 9px;
    overflow-x: auto;
    padding: 1px 1px 7px;
    scroll-snap-type: x proximity;
  }

  .prompt-button {
    flex: 0 0 min(78vw, 300px);
    min-height: 100px;
    scroll-snap-align: start;
  }

  .chat-log {
    padding: 20px 16px;
  }

  .message,
  .message-user {
    width: min(92%, 680px);
  }

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

  .composer-box {
    grid-template-columns: minmax(0, 1fr) 58px;
  }

  .composer button {
    min-width: 58px;
    padding: 0;
  }

  #sendLabel {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .send-arrow {
    font-size: 1.35rem;
  }
}

@media (max-width: 480px) {
  .character-panel {
    grid-template-columns: 92px minmax(0, 1fr);
  }

  .role {
    font-size: 0.78rem;
  }

  .chat-controls {
    display: flex;
    gap: 8px;
  }

  .reset-button {
    min-width: 0;
    padding: 0 10px;
    font-size: 0.72rem;
  }

  .character-lens {
    font-size: 0.78rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
