:root {
  --background: #f4f1ea;
  --surface: rgba(255, 251, 245, 0.82);
  --surface-low: rgba(248, 244, 237, 0.68);
  --surface-high: rgba(255, 255, 255, 0.94);
  --surface-variant: rgba(223, 214, 200, 0.9);
  --border: rgba(127, 109, 91, 0.22);
  --border-strong: rgba(89, 73, 58, 0.52);
  --text: #211d19;
  --text-muted: #6a6057;
  --text-soft: #85776b;
  --primary: #405245;
  --primary-soft: rgba(199, 222, 205, 0.56);
  --accent: #7a5c47;
  --danger: #ba1a1a;
  --ok: #496048;
  --shadow: 0 24px 60px rgba(33, 29, 25, 0.08);
  --shadow-soft: 0 8px 24px rgba(33, 29, 25, 0.05);
  --reading-width: 58rem;
}

* {
  box-sizing: border-box;
}

/* HTML's hidden attribute should always win, no matter what later
   class-level CSS sets display to. Keeping this near the top makes the
   rule available before .login-screen / .password-prompt-modal redefine
   `display: flex` for their visible state. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  font-family: 'Noto Serif SC', 'Noto Serif', serif;
  background:
    radial-gradient(circle at top left, rgba(209, 227, 211, 0.34), transparent 28%),
    radial-gradient(circle at top right, rgba(224, 208, 187, 0.22), transparent 26%),
    linear-gradient(180deg, #f9f6f1 0%, var(--background) 100%);
  color: var(--text);
}

.material-symbols-outlined {
  font-variation-settings: 'FILL' 0, 'wght' 350, 'GRAD' 0, 'opsz' 24;
}

.app {
  display: grid;
  grid-template-columns: 1fr;
  height: 100vh;
}

.chat-column {
  padding: 12px 24px 16px;
}

.chat-column {
  border-right: 0;
  display: flex;
  flex-direction: column;
  gap: 0px;
  height: 100vh;
  min-height: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.34) 0%, rgba(249, 246, 241, 0.08) 100%),
    radial-gradient(circle at top left, rgba(211, 232, 213, 0.18), transparent 34%);
}

.topbar {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 10px;
  position: fixed;
  top: 14px;
  left: 18px;
  max-width: min(36rem, calc(100vw - 36px));
  padding: 7px 11px 7px 9px;
  border: 1px solid rgba(127, 109, 91, 0.14);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.68);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(14px);
  z-index: 45;
}

.topbar h1 {
  margin: 0;
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  line-height: 1;
  letter-spacing: -0.01em;
  color: var(--text);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  border-radius: 999px;
  padding: 3px 5px 3px 3px;
  margin-left: -3px;
}

.topbar h1:hover,
.topbar h1:focus-visible {
  background: rgba(69, 88, 73, 0.08);
  outline: none;
}

.brand-logo {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
}

.brand-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-subtitle {
  margin: 0;
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.topbar-context {
  min-width: 0;
  padding-left: 10px;
  border-left: 1px solid rgba(127, 109, 91, 0.12);
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  border-radius: 999px;
  padding-top: 4px;
  padding-right: 7px;
  padding-bottom: 4px;
}

.topbar-context:hover,
.topbar-context:focus-visible {
  background: rgba(69, 88, 73, 0.08);
  outline: none;
}

.topbar-session-menu {
  position: relative;
  min-width: 0;
}

.topbar-session-menu::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  height: 12px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.bottom-controls {
  justify-content: flex-end;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.settings-icon-btn {
  padding: 9px;
  border: 1px solid rgba(127, 109, 91, 0.18);
  background: rgba(255, 255, 255, 0.66);
  box-shadow: var(--shadow-soft);
  color: var(--text) !important;
}

.topbar-actions .icon-btn,
.topbar-actions .icon-btn .material-symbols-outlined {
  color: var(--text) !important;
}

.settings-icon-btn .material-symbols-outlined {
  font-size: 18px;
  color: var(--text) !important;
}

.icon-btn.subtle {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid rgba(195, 200, 193, 0.4);
}

.icon-btn.subtle:hover {
  background: rgba(255, 255, 255, 0.7);
}

.composer textarea {
  border: 1px solid rgba(195, 200, 193, 0.6);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.84);
  color: var(--text);
  font: inherit;
  outline: none;
  transition: border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.composer textarea:focus {
  border-color: rgba(69, 88, 73, 0.42);
  box-shadow: none;
  background: #fff;
}

.composer textarea:focus,
.composer textarea:focus-visible {
  outline: none;
}

button {
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 9px 14px;
  cursor: pointer;
  transition: transform 160ms ease, opacity 160ms ease, background 160ms ease, box-shadow 160ms ease;
  box-shadow: 0 6px 16px rgba(64, 82, 69, 0.18);
}

button:hover {
  background: #394b3d;
}

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

.status-bar {
  border: 1px solid rgba(127, 109, 91, 0.18);
  border-radius: 10px;
  padding: 4px 10px;
  background: rgba(255, 251, 245, 0.9);
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  color: var(--text-muted);
}

.status-bar[data-kind='working'] {
  background: #f8f3e8;
}

.status-bar[data-kind='ok'] {
  background: #e7f0e7;
  color: var(--ok);
}

.status-bar[data-kind='error'] {
  background: #f8e2df;
  color: var(--danger);
}

.mobile-session-menu {
  display: none;
  position: relative;
}

.mobile-session-toggle {
  width: 32px;
  height: 32px;
  min-width: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(127, 109, 91, 0.18);
  background: rgba(255, 255, 255, 0.66);
  box-shadow: var(--shadow-soft);
  color: var(--text);
}

.mobile-session-toggle .material-symbols-outlined {
  font-size: 19px;
}

.mobile-session-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  width: min(22rem, calc(100vw - 16px));
  max-height: 58vh;
  overflow-y: auto;
  border: 1px solid rgba(195, 200, 193, 0.5);
  border-radius: 18px;
  background: rgba(255, 253, 248, 0.97);
  box-shadow: var(--shadow);
  padding: 12px;
  z-index: 95;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 140ms ease, transform 140ms ease, visibility 140ms ease;
}

.mobile-session-panel[aria-hidden='false'] {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

.profile-draft-panel {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid rgba(195, 200, 193, 0.5);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.profile-draft-panel textarea {
  width: 100%;
  min-height: 240px;
  resize: vertical;
  border: 1px solid rgba(195, 200, 193, 0.6);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--text);
  font: 12px/1.6 'Inter', sans-serif;
  padding: 12px 14px;
}

.messages {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 60px 28px 24px;
  min-height: 0;
  scroll-padding-bottom: 140px;
  mask-image: linear-gradient(to bottom, transparent 0%, transparent 32px, black 52px, black calc(100% - 24px), transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, transparent 32px, black 52px, black calc(100% - 24px), transparent 100%);
}

.history-toolbar {
  width: min(100%, var(--reading-width));
  margin: 10px auto 0;
  padding: 0 28px;
  justify-content: center;
  display: none;
}

.history-inline-wrap {
  width: min(100%, var(--reading-width));
  align-self: center;
  display: flex;
  justify-content: center;
  margin-top: -8px;
  margin-bottom: -4px;
}

.empty-session-card {
  width: min(100%, var(--reading-width));
  align-self: center;
  margin-top: 8vh;
  padding: 22px 24px;
  border: 1px solid rgba(127, 109, 91, 0.14);
  border-radius: 22px;
  background: rgba(255, 251, 245, 0.86);
  box-shadow: var(--shadow-soft);
}

.empty-session-card h2 {
  margin: 0 0 8px;
  font-size: 20px;
}

.empty-session-card p {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.7;
}

.empty-session-actions {
  margin-top: 16px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.settings-character-card {
  width: 100%;
  max-width: none;
}

.settings-character-cover-wrap {
  max-width: none;
  width: 100%;
}

.settings-character-copy {
  padding: 14px 16px 16px;
}

.character-manage-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(127, 109, 91, 0.14);
  border-radius: 18px;
  background: rgba(255, 251, 245, 0.84);
  cursor: pointer;
  min-width: 0;
  min-height: 0;
}

.character-manage-card[data-active='true'] {
  border-color: rgba(64, 82, 69, 0.42);
  background: rgba(226, 238, 228, 0.9);
}

.character-manage-cover-wrap {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 14px;
  overflow: hidden;
  background: linear-gradient(160deg, rgba(69, 88, 73, 0.18), rgba(121, 105, 82, 0.18));
  filter: grayscale(1);
  flex-shrink: 0;
  position: relative;
}

.character-manage-card[data-active='true'] .character-manage-cover-wrap {
  filter: none;
}

.character-manage-cover,
.character-manage-cover-fallback {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: flex;
  align-items: center;
  justify-content: center;
}

.character-manage-cover-fallback {
  font-family: 'Noto Serif SC', serif;
  font-size: 30px;
  color: rgba(26, 28, 27, 0.45);
}

.character-manage-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.character-manage-copy strong {
  font-size: 15px;
}

.character-manage-scope,
.character-manage-summary {
  margin: 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-muted);
  white-space: normal;
}

.character-manage-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.character-manage-active {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(64, 82, 69, 0.14);
  color: var(--primary);
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.profile-editor-panel {
  width: min(52rem, 94vw);
}

.history-load-btn {
  background: rgba(255, 255, 255, 0.82);
  color: var(--text-muted);
  border: 1px solid rgba(195, 200, 193, 0.45);
  padding: 7px 12px;
  font-size: 11px;
  letter-spacing: 0.08em;
}

.history-load-btn:hover {
  background: rgba(255, 255, 255, 0.96);
  color: var(--text);
}

@keyframes msgFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.msg {
  animation: msgFadeIn 200ms ease-out;
}

.messages::-webkit-scrollbar,
.debug-float-body::-webkit-scrollbar {
  width: 4px;
}

.messages::-webkit-scrollbar-thumb,
.debug-float-body::-webkit-scrollbar-thumb {
  background: var(--surface-variant);
}

.msg {
  width: min(100%, var(--reading-width));
  align-self: center;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.msg.user {
  background: transparent;
}

.msg.assistant {
  background: transparent;
}

.msg-label {
  margin: 0;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.msg-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(127, 109, 91, 0.12);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 700;
  flex: 0 0 auto;
  overflow: hidden;
  background-size: cover;
  background-position: center;
}

.msg-avatar.assistant {
  object-fit: cover;
  border: 1px solid rgba(127, 109, 91, 0.16);
}

.msg-avatar.user.has-image {
  border: 1px solid rgba(127, 109, 91, 0.16);
}

.msg-body {
  white-space: normal;
  line-height: 1.9;
  letter-spacing: 0.003em;
  font-size: 17px;
  color: var(--text);
}

.msg.assistant .msg-body {
  background: rgba(255, 253, 248, 0.74);
  padding: 22px 24px;
  border-left: 2px solid rgba(64, 82, 69, 0.16);
  border-radius: 18px;
  box-shadow: var(--shadow-soft);
}

.msg.assistant .msg-body p {
  margin: 0 0 0.6em 0;
}

.msg.assistant .msg-body p:last-child {
  margin-bottom: 0;
}

.msg.assistant .msg-body strong {
  color: var(--primary);
}

.msg.assistant .msg-body em {
  color: var(--accent);
}

.msg.assistant .msg-body blockquote {
  margin: 0.5em 0;
  padding: 0.3em 0.8em;
  border-left: 3px solid rgba(69, 88, 73, 0.25);
  color: var(--text-muted);
  background: rgba(211, 232, 213, 0.12);
}

.msg.assistant .msg-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: rgba(195, 200, 193, 0.18);
  padding: 0.15em 0.35em;
  border-radius: 4px;
}

.msg.assistant .msg-body pre {
  margin: 0.6em 0;
  padding: 0.8em 1em;
  background: rgba(26, 28, 27, 0.04);
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.88em;
  line-height: 1.5;
}

.msg.assistant .msg-body pre code {
  background: transparent;
  padding: 0;
}

.msg.assistant .msg-body ul,
.msg.assistant .msg-body ol {
  margin: 0.4em 0;
  padding-left: 1.5em;
}

.msg.assistant .msg-body li {
  margin: 0.2em 0;
}

.msg.assistant .msg-body hr {
  border: 0;
  border-top: 1px solid rgba(195, 200, 193, 0.4);
  margin: 1em 0;
}

.msg.assistant .msg-body h1,
.msg.assistant .msg-body h2,
.msg.assistant .msg-body h3,
.msg.assistant .msg-body h4 {
  margin: 0.8em 0 0.3em 0;
  font-size: 1em;
  font-weight: 700;
  color: var(--text);
}

.msg.user .msg-body {
  background: rgba(232, 240, 233, 0.76);
  padding: 15px 18px;
  color: #2f3a31;
  font-size: 14px;
  border-radius: 16px;
}

.msg.pending .msg-body {
  opacity: 0.74;
}

.messages .msg:first-child {
  margin-top: 6px;
}

.composer {
  display: block;
  padding: 0 28px 12px;
  position: relative;
  z-index: 18;
  pointer-events: none;
}

.composer-shell {
  pointer-events: auto;
  width: min(100%, var(--reading-width));
  margin: 0 auto;
  border: 1px solid rgba(127, 109, 91, 0.16);
  border-radius: 22px;
  background: rgba(255, 251, 245, 0.75);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  padding: 14px 16px 12px;
}

.session-dock-panel {
  position: absolute;
  left: 0;
  top: calc(100% + 10px);
  transform: translateY(-4px);
  width: min(24rem, calc(100vw - 36px));
  max-height: min(62vh, 520px);
  overflow-y: auto;
  border: 1px solid rgba(195, 200, 193, 0.5);
  border-radius: 18px;
  background: rgba(255, 253, 248, 0.97);
  box-shadow: var(--shadow);
  padding: 12px;
  z-index: 90;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease, visibility 140ms ease;
}

.session-dock-panel::before {
  content: "";
  position: absolute;
  top: -12px;
  left: 0;
  right: 0;
  height: 12px;
}

.session-dock-panel[aria-hidden='false'] {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

.topbar-session-menu[data-suppressed='true'] .session-dock-panel {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-4px);
}

.session-dock-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(127, 109, 91, 0.12);
}

.session-dock-heading > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.session-dock-heading .icon-btn {
  padding: 6px;
  min-width: 32px;
  height: 32px;
}

.session-dock-heading span {
  font-size: 15px;
  font-weight: 700;
}

.session-dock-heading small {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  color: var(--text-muted);
}

.session-dock-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.settings-session-list {
  max-height: 320px;
  overflow: auto;
  padding-right: 2px;
}

.session-dock-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.session-dock-item[data-active='true'] .session-dock-open {
  border-color: rgba(69, 88, 73, 0.35);
  background: rgba(211, 232, 213, 0.32);
  color: var(--text);
}

.session-dock-open,
.session-dock-delete {
  font-family: 'Inter', sans-serif;
  letter-spacing: 0;
  text-transform: none;
}

.session-dock-open {
  justify-content: flex-start;
  text-align: left;
  background: rgba(255, 255, 255, 0.86);
  color: var(--text);
  border: 1px solid rgba(195, 200, 193, 0.45);
  padding: 8px 10px;
  font-size: 11px;
}

.session-dock-open:hover {
  background: rgba(255, 255, 255, 0.98);
}

.session-dock-delete {
  width: 28px;
  min-width: 28px;
  height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(123, 47, 42, 0.12);
  color: #7b2f2a;
  border: 1px solid rgba(123, 47, 42, 0.18);
}

.session-dock-delete:hover {
  background: rgba(123, 47, 42, 0.18);
}

.session-dock-delete .material-symbols-outlined {
  font-size: 15px;
}

.session-dock-new {
  margin-top: 2px;
  padding-top: 8px;
  border-top: 1px solid rgba(195, 200, 193, 0.35);
}

.session-dock-new-btn {
  width: 100%;
  justify-content: center;
  background: rgba(69, 88, 73, 0.12);
  color: var(--primary);
  border: 1px solid rgba(69, 88, 73, 0.18);
  padding: 8px 10px;
  font-size: 12px;
}

.session-dock-new-btn:hover {
  background: rgba(69, 88, 73, 0.18);
}

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: rgba(255, 253, 248, 0.74);
  border-left: 1px solid rgba(69, 88, 73, 0.18);
  border-radius: 12px;
}

.typing-indicator-label {
  font-family: 'Inter', sans-serif;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-muted);
}

.typing-dots {
  display: inline-flex;
  gap: 3px;
}

.typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.2s infinite;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.composer textarea {
  width: 100%;
  min-height: 42px;
  resize: vertical;
  padding: 2px 2px 8px;
  font-size: 15px;
  line-height: 1.75;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.composer-footer {
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.composer-status-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.card {
  background: rgba(255, 253, 248, 0.76);
  border: 1px solid rgba(127, 109, 91, 0.16);
  border-radius: 22px;
  padding: 18px 18px;
  box-shadow: var(--shadow-soft);
}

.sidebar-group.card {
  border: 0;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
  background: transparent;
  border-bottom: 1px solid rgba(127, 109, 91, 0.12);
}

.sidebar-group.card:last-child {
  border-bottom: 0;
}

.card h2 {
  margin: 0 0 14px;
  font-size: 15px;
  font-family: 'Inter', sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-muted);
}

.character-card {
  padding: 0;
  overflow: hidden;
  max-width: 280px;
  align-self: flex-start;
  min-height: auto;
  background: rgba(255, 252, 247, 0.92);
}

.character-cover-wrap {
  position: relative;
  width: 100%;
  max-width: 280px;
  aspect-ratio: 280 / 164;
  background: linear-gradient(160deg, rgba(69, 88, 73, 0.18), rgba(121, 105, 82, 0.18));
  border-bottom: 1px solid rgba(127, 109, 91, 0.14);
}

.character-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 1;
  transition: opacity 180ms ease;
}

.character-cover[hidden] {
  display: block;
  opacity: 0;
}

.character-cover-fallback {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Noto Serif SC', serif;
  font-size: 32px;
  letter-spacing: 0.08em;
  color: rgba(26, 28, 27, 0.5);
}

.character-cover-fallback[hidden] {
  display: flex;
  opacity: 0;
  pointer-events: none;
}

.character-copy {
  padding: 12px 14px 14px;
}

.character-name-row {
  display: flex;
  align-items: center;
}

.character-label {
  margin: 0 0 6px;
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-muted);
}

.character-scope {
  margin: 0 0 10px;
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-soft);
}

.character-select {
  width: 100%;
  border: 1px solid rgba(195, 200, 193, 0.55);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--text);
  font-family: 'Noto Serif SC', serif;
  font-size: 14px;
  line-height: 1.3;
  padding: 6px 8px;
}

.character-select:focus {
  outline: none;
  border-color: rgba(69, 88, 73, 0.42);
  background: #fff;
}

.character-subtitle {
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.65;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  max-height: 17.2em;
  overflow-y: auto;
  padding-right: 4px;
}

.state-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 12px;
}

.state-table th,
.state-table td {
  text-align: left;
  vertical-align: top;
  padding: 5px 4px;
  border-bottom: 1px solid rgba(195, 200, 193, 0.2);
  font-size: 12px;
  line-height: 1.5;
}

.state-table th {
  width: 72px;
  color: var(--text-soft);
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.npc-block {
  margin-top: 14px;
}

.state-summary-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid rgba(195, 200, 193, 0.35);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.58);
}

.state-summary-line {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.state-summary-line strong {
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--text-muted);
}

.state-summary-line span {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
}

.npc-block strong {
  display: block;
  margin-bottom: 6px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--text-muted);
}

.npc-table {
  margin-top: 8px;
}

.empty-hint {
  color: var(--text-soft);
  font-size: 13px;
  padding: 6px 4px;
}

.sidebar-group {
  padding: 0;
}

.sidebar-details {
  cursor: default;
}

.sidebar-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px 12px;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-muted);
  list-style: none;
  user-select: none;
  transition: color 160ms ease;
}

.sidebar-summary::-webkit-details-marker {
  display: none;
}

.sidebar-summary::after {
  content: '';
  display: inline-block;
  width: 5px;
  height: 5px;
  border-right: 1.5px solid var(--border-strong);
  border-bottom: 1.5px solid var(--border-strong);
  transform: rotate(-45deg);
  margin-left: auto;
  transition: transform 200ms ease;
}

.sidebar-details[open] > .sidebar-summary::after {
  transform: rotate(45deg);
}

.sidebar-summary:hover {
  color: var(--text);
}

.sidebar-summary-icon {
  font-size: 16px;
}

.sidebar-details-body {
  padding: 0 16px 18px;
}

.entity-detail-body {
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.65;
  color: #3b352f;
}

.object-line + .object-line {
  margin-top: 2px;
  color: var(--text-muted);
}

.npc-link {
  display: block;
  margin-top: 4px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--primary);
  text-decoration: underline;
  cursor: pointer;
  text-align: left;
  font: inherit;
}

.npc-link:hover {
  color: #2f4033;
  background: transparent;
}

.npc-fallback {
  display: block;
  margin-top: 4px;
  color: var(--text-soft);
}

#debugDetail {
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.65;
  color: #3b352f;
}

.debug-card .sidebar-summary {
  cursor: pointer;
}

#debugDetail {
  margin-top: 4px;
}

.status-bar-fading {
  transition: opacity 400ms ease;
  opacity: 0;
}

.settings-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26, 23, 20, 0.2);
  backdrop-filter: blur(8px);
  z-index: 70;
}

.settings-panel {
  display: flex;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(66rem, 95vw);
  background: rgba(250, 246, 240, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-left: 1px solid rgba(127, 109, 91, 0.14);
  box-shadow: -24px 0 70px rgba(33, 29, 25, 0.18);
  z-index: 80;
  flex-direction: row;
  transform: translateX(100%);
  opacity: 0;
  pointer-events: none;
  transition: transform 300ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 300ms ease;
  overflow: hidden;
}

.settings-panel[data-open='true'] {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.settings-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 24px 24px 16px;
  border-bottom: 0;
}

.settings-header h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.settings-kicker {
  margin: 0 0 6px;
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-muted);
}

.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.settings-section {
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
}

.settings-section h3 {
  margin: 0 0 14px;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--text-muted);
}

.settings-stack {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.settings-subsection {
  border: 1px solid rgba(127, 109, 91, 0.12);
  border-radius: 18px;
  padding: 12px 14px;
  background: rgba(255, 253, 248, 0.52);
}

.settings-subsection:last-child {
  border-bottom: 1px solid rgba(127, 109, 91, 0.12);
  padding-bottom: 16px;
}

.settings-section-head {
  margin-bottom: 14px;
}

.settings-section-head h3 {
  margin: 0 0 6px;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--text-muted);
}

.settings-section-head p {
  margin: 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-soft);
}

/* Settings Tab Navigation */
.settings-tabs {
  display: flex;
  gap: 0;
  padding: 0 24px;
  border-bottom: 0;
  flex-shrink: 0;
}

.settings-tab-btn {
  position: relative;
  padding: 10px 18px;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--primary);
  background: var(--primary-soft);
  border: none;
  border-radius: 10px 10px 0 0;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease;
  white-space: nowrap;
}

.settings-tab-btn:hover {
  background: rgba(199, 222, 205, 0.78);
  color: var(--text);
}

.settings-tab-btn[aria-selected='true'] {
  color: var(--text);
  background: transparent;
  font-weight: 600;
}

.settings-tab-btn[aria-selected='true']::after {
  content: '';
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: -1px;
  height: 2px;
  background: var(--primary);
  border-radius: 2px 2px 0 0;
}

.settings-tab-panel {
  display: none;
  flex-direction: column;
  gap: 22px;
}

.settings-tab-panel[data-active='true'] {
  display: flex;
}

.subsection-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.subsection-head h4 {
  margin: 2px 0 0;
  font-size: 18px;
  line-height: 1.2;
}

.settings-micro {
  margin: 0;
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-muted);
}

.config-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field span {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

.field input,
.field select,
.field output,
.field textarea {
  border: 1px solid rgba(195, 200, 193, 0.6);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  padding: 8px 12px;
}

.field input[type='range'] {
  padding: 0;
  accent-color: var(--primary);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: rgba(69, 88, 73, 0.42);
  background: #fff;
}

.field textarea {
  resize: vertical;
  min-height: 220px;
  line-height: 1.65;
}

.field output {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-width: 58px;
  justify-content: center;
  background: rgba(211, 232, 213, 0.34);
  padding: 6px 10px;
}

.field-value {
  font-weight: 600;
}

.field-wide {
  grid-column: 1 / -1;
}

.subtle-btn {
  background: rgba(69, 88, 73, 0.12);
  color: var(--primary);
  border: 1px solid rgba(69, 88, 73, 0.18);
}

.subtle-btn:hover {
  background: rgba(69, 88, 73, 0.18);
}

.inline-feedback {
  min-height: 18px;
  margin-top: 10px;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  color: var(--text-muted);
}

.inline-feedback[data-kind='error'] {
  color: var(--danger);
}

.inline-feedback[data-kind='ok'] {
  color: var(--ok);
}

.inline-feedback[data-kind='warning'] {
  color: var(--warning, #e2a308);
}

.settings-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 8px;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.danger-btn {
  background: #7b2f2a;
}

.danger-btn:hover {
  background: #652520;
}

.subtle-danger {
  background: rgba(123, 47, 42, 0.12);
  color: #7b2f2a;
  border: 1px solid rgba(123, 47, 42, 0.24);
}

.subtle-danger:hover {
  background: rgba(123, 47, 42, 0.18);
}

.muted-section p {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.7;
  font-size: 14px;
}

@media (max-width: 1024px) {
  .app {
    grid-template-columns: 1fr;
  }

  .chat-column {
    border-right: 0;
  }

  .topbar {
    max-width: calc(100vw - 24px);
    left: 12px;
  }
}

@media (max-width: 720px) {
  .chat-column {
    padding: 8px 12px;
  }

  .topbar {
    left: 8px;
    top: 8px;
    max-width: calc(100vw - 16px);
    padding: 6px 8px;
    gap: 6px;
  }

  .topbar h1 {
    font-size: 13px;
  }

  .brand-logo {
    width: 20px;
    height: 20px;
  }

  .topbar-context {
    max-width: 42vw;
    font-size: 10px;
    padding-left: 7px;
    padding-right: 5px;
  }

  .messages {
    padding: 48px 0 16px;
    gap: 18px;
    mask-image: linear-gradient(to bottom, transparent 0%, transparent 28px, black 44px, black calc(100% - 16px), transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, transparent 0%, transparent 28px, black 44px, black calc(100% - 16px), transparent 100%);
  }

  .composer {
    padding: 0 0 8px;
    background: transparent;
  }

  .composer-shell {
    border-radius: 16px;
    padding: 8px 10px 8px;
    background: rgba(255, 251, 245, 0.85);
    backdrop-filter: blur(14px);
  }

  .composer textarea {
    min-height: 30px;
    max-height: 82px;
    padding: 0 2px 4px;
    font-size: 14px;
    line-height: 1.45;
  }

  .composer-footer {
    margin-top: 4px;
    gap: 6px;
  }

  .composer-status-row {
    display: block;
    align-items: center;
    gap: 6px;
  }

  .mobile-session-menu {
    display: none;
  }

  .status-bar {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 3px 8px;
    font-size: 10px;
  }

  .bottom-controls {
    display: none;
  }

  .settings-icon-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    padding: 0;
    justify-content: center;
  }

  .settings-icon-btn .material-symbols-outlined {
    font-size: 17px;
  }

  .session-dock-panel {
    left: auto;
    right: 0;
    width: min(22rem, calc(100vw - 16px));
    max-height: 64vh;
  }

  .msg {
    width: 100%;
  }

  .msg-body {
    font-size: 14px;
  }

  .msg.assistant .msg-body,
  .msg.user .msg-body {
    padding: 14px 16px;
  }

  .composer-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .composer-actions {
    justify-content: flex-end;
    gap: 8px;
  }

  .composer-actions button {
    padding: 8px 12px;
    font-size: 10px;
  }

  .config-grid {
    grid-template-columns: 1fr;
  }

  .subsection-head {
    flex-direction: column;
  }

  .settings-panel {
    display: flex;
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    border-radius: 0;
  }

  .debug-float-panel {
    top: auto;
    right: auto;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%) translateY(100%);
    width: 100vw;
    max-height: 78vh;
    border-right: 1px solid rgba(195, 200, 193, 0.5);
    border-bottom: 0;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 24px rgba(20, 23, 21, 0.08);
  }

  .debug-float-panel[data-open='true'] {
    transform: translateX(-50%) translateY(0);
  }
}

/* LLM 首次设置引导 */
.setup-guide-banner {
  background: var(--color-ink-faint, #2a2520);
  border: 1px solid var(--color-gold, #d4a843);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
  text-align: center;
}
.setup-guide-banner p {
  margin: 4px 0;
  font-size: 0.9rem;
  color: var(--color-ink-light, #c4b8a8);
}
.setup-guide-banner strong {
  color: var(--color-gold, #d4a843);
}

/* 登录弹窗 */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
}
.login-modal {
  background: var(--bg-panel, #1e1b16);
  border: 1px solid var(--border, #3a3428);
  border-radius: 12px;
  padding: 32px;
  width: 340px;
  max-width: 90vw;
}
.login-modal h2 {
  margin: 0 0 16px;
  color: var(--text-primary, #e8dcc8);
}

/* 用户列表项 */
.user-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border, #3a3428);
  font-size: 13px;
  color: var(--text-secondary, #a89b8c);
}
.user-list-item .user-role {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-subtle, #2a2520);
}
.user-list-item .user-delete-btn {
  background: none;
  border: none;
  color: var(--danger, #d44);
  cursor: pointer;
  font-size: 12px;
}

/* ── 调试浮动面板 ── */
.debug-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26, 28, 27, 0.12);
  backdrop-filter: blur(2px);
  z-index: 70;
}

.debug-float-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  transform: translateX(100%);
  width: min(28rem, 92vw);
  max-height: none;
  background: var(--background);
  border: 1px solid rgba(195, 200, 193, 0.5);
  border-right: 0;
  border-radius: 18px 0 0 18px;
  box-shadow: -12px 0 30px rgba(20, 23, 21, 0.08);
  z-index: 80;
  display: flex;
  flex-direction: column;
  pointer-events: none;
  opacity: 0;
  transition: transform 220ms ease, opacity 180ms ease;
}

.debug-float-panel[data-open='true'] {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.debug-float-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px 10px;
  border-bottom: 1px solid rgba(195, 200, 193, 0.3);
}

.debug-float-header h2 {
  margin: 0;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-muted);
}

.debug-float-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.debug-float-body pre {
  margin: 0;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.6;
  color: #3b352f;
}

/* ── 向导样式 ── */
.wizard-section h3 {
  margin-bottom: 8px;
}

.wizard-trigger {
  width: 100%;
  text-align: center;
  padding: 12px 16px;
}

.wizard-section {
  position: relative;
}

.wizard-step {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.wizard-step:not([hidden]) {
  animation: msgFadeIn 180ms ease-out;
}

.typing-indicator {
  display: none !important;
}

.wizard-step[hidden] {
  display: none;
}

/* ── Multi-user UI ───────────────────────────────────────── */

.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at top left, rgba(209, 227, 211, 0.34), transparent 28%),
    radial-gradient(circle at top right, rgba(224, 208, 187, 0.22), transparent 26%),
    linear-gradient(180deg, #f9f6f1 0%, var(--background) 100%);
  z-index: 10000;
}

.login-form {
  width: min(360px, calc(100vw - 32px));
  background: var(--surface-high);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 28px 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-title {
  margin: 0 0 6px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.4rem;
}

.login-title .brand-logo {
  width: 32px;
  height: 32px;
}

.login-hint {
  margin: 0 0 6px;
  color: var(--text-muted);
  font-size: 13px;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.login-field span {
  font-size: 11px;
}

.login-field input {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-high);
  font-family: inherit;
  font-size: 12px;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.login-field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.login-error {
  min-height: 1.2em;
  color: var(--danger);
  font-size: 0.88rem;
}

.login-form button.primary {
  margin-top: 6px;
  background: var(--primary);
  color: #fff;
  padding: 11px 16px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
}

.auth-indicator {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin: 0 0 20px;
  padding: 12px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface-high);
  box-shadow: var(--shadow-soft);
}

.auth-indicator-label {
  white-space: nowrap;
  font-weight: 500;
  color: var(--text);
  font-size: 0.95rem;
}

.auth-logout-btn {
  background: var(--surface-low);
  border: 1px solid var(--border);
  color: var(--danger);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.auth-logout-btn:hover {
  background: #fdf5f5;
  border-color: rgba(186, 26, 26, 0.3);
}

.auth-indicator-label {
  white-space: nowrap;
}

.auth-logout-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
}

.auth-logout-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.multi-user-status {
  flex: 1;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.user-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  gap: 10px;
}

.user-list-row .user-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.user-list-row .user-id {
  font-weight: 600;
}

.user-list-row .user-role-tag {
  align-self: flex-start;
  font-size: 0.78rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-variant);
  color: var(--text);
}

.user-list-row .user-role-tag.admin {
  background: var(--primary-soft);
}

.user-list-row .user-actions {
  display: flex;
  gap: 6px;
}

.account-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface);
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}

.password-prompt-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10500;
  pointer-events: none;
}

.password-prompt-modal:not([hidden]) {
  pointer-events: auto;
}

.password-prompt-form {
  width: min(380px, calc(100vw - 32px));
  background: var(--surface-high);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px 24px 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.password-prompt-title {
  margin: 0;
  font-size: 1.15rem;
}

.password-prompt-hint {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.settings-panel {
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

.settings-sidebar {
  width: 240px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: rgba(240, 235, 225, 0.4);
  border-right: 1px solid var(--border);
}

.settings-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  min-width: 0;
}

.settings-main-header {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 10;
}

.settings-tabs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 16px 24px;
  border-bottom: 0;
}

.settings-tab-btn {
  position: relative;
  padding: 12px 16px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--primary);
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 160ms ease;
  text-align: left;
}

.settings-tab-btn:hover {
  background: rgba(127, 109, 91, 0.08);
  color: var(--text);
}

.settings-tab-btn[aria-selected='true'] {
  background: rgba(127, 109, 91, 0.12);
  color: var(--text);
  font-weight: 700;
}

.settings-tab-btn[aria-selected='true']::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  background: var(--primary);
  border-radius: 0 4px 4px 0;
}

/* Character Carousel styling */
.character-carousel-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
}

.character-manage-grid {
  display: flex;
  overflow-x: auto;
  scroll-behavior: smooth;
  flex-wrap: nowrap;
  flex: 1;
  min-width: 0;
  gap: 14px;
  scrollbar-width: none; /* firefox */
}

.character-manage-grid::-webkit-scrollbar {
  display: none; /* webkit */
}

.character-manage-card {
  flex: 0 0 calc(50% - 7px); /* show exactly 2 items if gap is 14px */
  min-width: 200px;
}

.carousel-btn {
  background: var(--surface-high);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-soft);
  flex-shrink: 0;
  transition: background 150ms ease, color 150ms ease;
}

.carousel-btn:hover {
  background: var(--surface-variant);
  color: var(--text);
}

@media (max-width: 600px) {
  .settings-panel {
    flex-direction: column;
  }
  
  .settings-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  
  .settings-tabs {
    flex-direction: row;
    overflow-x: auto;
    padding: 0 16px 12px;
  }
  
  .settings-tab-btn {
    white-space: nowrap;
  }
  
  .settings-tab-btn[aria-selected='true']::before {
    left: 8px;
    right: 8px;
    bottom: 0;
    top: auto;
    height: 3px;
    width: auto;
    border-radius: 4px 4px 0 0;
  }

  .character-manage-card {
    flex: 0 0 85%; /* on mobile show 1 card + peeking */
  }

  .settings-body {
    padding: 16px 16px 24px;
  }

  .settings-main {
    position: static;
  }

  .settings-main-header {
    top: 16px;
    right: 16px;
  }
}

/* --- NEW UI IMPROVEMENTS --- */

/* Floating Pill Status Indicator */
.floating-pill {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(-150%);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(127, 109, 91, 0.2);
  border-radius: 999px;
  padding: 6px 16px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  color: var(--text);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  z-index: 100;
  opacity: 0;
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
  pointer-events: none;
}

.floating-pill.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.floating-pill.fading {
  opacity: 0;
  transform: translateX(-50%) translateY(-20px);
}

/* Status Dot inside Send Button */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-left: 6px;
  background-color: #4ade80;
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.4);
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.status-dot[data-status="ready"] {
  background-color: #4ade80;
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.4);
}

.status-dot[data-status="generating"] {
  background-color: #fb923c;
  box-shadow: 0 0 8px rgba(251, 146, 60, 0.6);
  animation: breathe 1.5s infinite ease-in-out;
}

.status-dot[data-status="error"] {
  background-color: #ef4444;
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.6);
}

@keyframes breathe {
  0%, 100% { opacity: 0.5; transform: scale(0.9); box-shadow: 0 0 4px rgba(251, 146, 60, 0.3); }
  50% { opacity: 1; transform: scale(1.1); box-shadow: 0 0 12px rgba(251, 146, 60, 0.8); }
}

/* Dropdown Arrow in Topbar */
.dropdown-arrow {
  display: inline-block;
  font-size: 10px;
  margin-left: 2px;
  vertical-align: middle;
  opacity: 0.6;
}

.floating-settings-btn {
  position: fixed;
  top: 18px;
  right: 18px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.4);
  border: 1px solid rgba(127, 109, 91, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 99;
  opacity: 0.7;
  transition: all 0.3s ease, opacity 0.3s ease;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.floating-settings-btn .material-symbols-outlined {
  font-size: 18px;
  color: var(--text);
  transition: transform 0.5s ease;
}

.floating-settings-btn:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transform: translateY(-1px);
}

.floating-settings-btn:hover .material-symbols-outlined {
  transform: rotate(90deg);
}

@media (max-width: 720px) {
  .floating-settings-btn {
    top: 10px;
    right: 10px;
    width: 28px;
    height: 28px;
  }
  .floating-settings-btn .material-symbols-outlined {
    font-size: 16px;
  }
}

/* Toggle Switch Styles */
.settings-row.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-sm) 0;
}

.toggle-label {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--text-muted);
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: .4s;
  border-radius: 34px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

input:checked + .toggle-slider {
  background-color: var(--primary);
}

input:focus + .toggle-slider {
  box-shadow: 0 0 1px var(--primary);
}

input:checked + .toggle-slider:before {
  transform: translateX(16px);
}
