:root {
  color-scheme: dark;
  --bg: #050505;
  --panel: #111111;
  --panel-soft: rgba(10, 10, 10, 0.82);
  --panel-line: #262626;
  --text: #f5f5f5;
  --muted: #b8b8b8;
  --accent: #ff4f8b;
  --accent-soft: rgba(255, 79, 139, 0.2);
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  line-height: 1.5;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

img {
  display: block;
  max-width: 100%;
}

.flash-stack {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 30;
  display: grid;
  gap: 12px;
  width: min(360px, calc(100vw - 32px));
}

.flash {
  padding: 12px 14px;
  border-radius: 8px;
  background: rgba(17, 17, 17, 0.96);
  border: 1px solid var(--panel-line);
  box-shadow: var(--shadow);
}

.flash-success {
  border-left: 3px solid #2fb171;
}

.flash-error {
  border-left: 3px solid #d64545;
}

.public-index-page,
.public-chat-page {
  background: var(--bg);
}

.role-directory {
  min-height: 100vh;
  padding: 8px 0 28px;
  background: #000000;
}

.role-directory__header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border-top: 1px solid #575757;
  border-bottom: 1px solid #3a3a3a;
  background: #121212;
}

.role-directory__header h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0;
  color: #ffffff;
}

.role-directory__auth {
  position: absolute;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: #d8d8d8;
  font-size: 13px;
}

.role-directory__auth a:hover {
  color: #ffffff;
}

.role-directory__search {
  padding: 10px 8px 8px;
  background: #0b0b0b;
}

.role-search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid #202020;
  background: #111111;
  color: #909090;
}

.role-search-box__icon {
  font-size: 13px;
  line-height: 1;
}

.role-search-box input {
  width: 100%;
  border: 0;
  outline: none;
  background: transparent;
  color: #dedede;
}

.role-search-box input::placeholder {
  color: #777777;
}

.role-directory__list {
  display: grid;
}

.role-list-item {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  min-height: 76px;
  padding: 12px 12px 12px 10px;
  border-top: 1px solid rgba(120, 0, 24, 0.28);
  border-bottom: 1px solid rgba(120, 0, 24, 0.28);
  background: #080808;
}

.role-list-item:hover {
  background: #101010;
}

.role-list-item[hidden] {
  display: none;
}

.role-list-item__avatar img,
.role-list-item__fallback {
  width: 42px;
  height: 42px;
  border-radius: 8px;
}

.role-list-item__avatar img {
  object-fit: cover;
}

.role-list-item__fallback {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #ff4f8b, #8f3cd7);
  color: #ffffff;
  font-weight: 700;
}

.role-list-item__body {
  min-width: 0;
}

.role-list-item__body h2 {
  margin: 0 0 4px;
  color: #ff3a75;
  font-size: 16px;
  line-height: 1.15;
}

.role-list-item__body p {
  margin: 0;
  color: #c8c8c8;
  font-size: 13px;
  line-height: 1.35;
}

.role-directory__empty {
  padding: 48px 20px;
  text-align: center;
  color: var(--muted);
}

.role-directory__footer {
  margin: 12px 0 0;
  text-align: center;
  color: #8b8b8b;
  font-size: 14px;
  letter-spacing: 1px;
}

.public-auth-page {
  color-scheme: light;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(103, 118, 226, 0.92), rgba(122, 75, 171, 0.94)),
    #6d6fdf;
  color: #111827;
}

.auth-shell {
  display: flex;
  justify-content: center;
  min-height: 100vh;
  padding: 0 16px;
}

.auth-card {
  width: min(100%, 750px);
  background: #ffffff;
}

.auth-card__header {
  display: flex;
  min-height: 129px;
  align-items: flex-start;
  justify-content: center;
  gap: 18px;
  padding: 0 24px;
  background: linear-gradient(90deg, #6578e4, #8050ae);
  color: #ffffff;
  text-align: center;
}

.auth-card__header h1 {
  margin: 0;
  padding-top: 2px;
  font-size: 40px;
  font-weight: 300;
  line-height: 1.12;
  letter-spacing: 0;
}

.auth-card__header p {
  margin: 14px 0 0;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.2;
}

.auth-card__icon {
  position: relative;
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  margin-top: 0;
}

.auth-card__person::before,
.auth-card__person::after {
  position: absolute;
  left: 8px;
  content: "";
  background: #ffffff;
}

.auth-card__person::before {
  top: 0;
  width: 23px;
  height: 23px;
  border-radius: 50%;
}

.auth-card__person::after {
  top: 28px;
  width: 40px;
  height: 18px;
  border-radius: 18px 18px 5px 5px;
}

.auth-card__plus::before,
.auth-card__plus::after {
  position: absolute;
  content: "";
  border-radius: 999px;
  background: #ffffff;
}

.auth-card__plus::before {
  top: 19px;
  right: 0;
  width: 16px;
  height: 5px;
}

.auth-card__plus::after {
  top: 14px;
  right: 5px;
  width: 5px;
  height: 16px;
}

.auth-form {
  display: grid;
  gap: 23px;
  padding: 54px 50px 32px;
}

.auth-field {
  display: grid;
  gap: 9px;
  color: #111827;
  font-size: 20px;
  line-height: 1.25;
}

.auth-field input {
  width: 100%;
  min-height: 64px;
  padding: 0 20px;
  border: 2px solid #e3e7ef;
  border-radius: 12px;
  outline: none;
  background: #ffffff;
  color: #1f2937;
  font-size: 18px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.auth-field input:focus {
  border-color: #6f83ff;
  box-shadow: 0 0 0 4px rgba(111, 131, 255, 0.22);
}

.auth-field small {
  color: #5d6b80;
  font-size: 17px;
  line-height: 1.48;
}

.auth-password {
  position: relative;
}

.auth-password input {
  padding-right: 58px;
}

.auth-password__toggle {
  position: absolute;
  top: 50%;
  right: 14px;
  width: 38px;
  height: 38px;
  padding: 0;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  cursor: pointer;
}

.auth-password__toggle::before {
  position: absolute;
  top: 12px;
  left: 8px;
  width: 22px;
  height: 14px;
  border: 3px solid #6c7784;
  border-radius: 50%;
  content: "";
}

.auth-password__toggle::after {
  position: absolute;
  top: 17px;
  left: 17px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #6c7784;
  content: "";
}

.auth-password__toggle.is-visible::after {
  background: #6f83ff;
}

.auth-strength {
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8ebef;
}

.auth-strength span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: #9ca3af;
  transition: width 0.2s ease, background-color 0.2s ease;
}

.auth-strength span[data-strength="weak"] {
  width: 34%;
  background: #ef4444;
}

.auth-strength span[data-strength="medium"] {
  width: 67%;
  background: #f59e0b;
}

.auth-strength span[data-strength="strong"] {
  width: 100%;
  background: #16a34a;
}

.auth-submit {
  min-height: 60px;
  border: 0;
  border-radius: 10px;
  background: #6f6ee8;
  color: #ffffff;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.auth-submit:hover {
  background: #5f5ed8;
}

.auth-submit:disabled {
  opacity: 0.68;
  cursor: not-allowed;
  transform: none;
}

.auth-form__message {
  padding: 12px 14px;
  border-radius: 8px;
  background: #fef2f2;
  color: #991b1b;
  font-size: 15px;
  line-height: 1.4;
}

.auth-form__message.is-success {
  background: #ecfdf5;
  color: #047857;
}

.auth-switch {
  margin: -4px 0 0;
  color: #5d6b80;
  font-size: 16px;
  text-align: center;
}

.auth-switch a {
  color: #4f6cff;
  font-weight: 700;
}

.chat-page {
  display: flex;
  justify-content: center;
  min-height: 100vh;
  background: #dfe6ef;
}

.chat-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(100%, 430px);
  min-height: 100vh;
  overflow: hidden;
  background:
    linear-gradient(rgba(255, 255, 255, 0.14), rgba(0, 0, 0, 0.14)),
    var(--chat-stage-bg, linear-gradient(180deg, #4d5964, #d7dbe0));
  background-position: center;
  background-size: cover;
}

.chat-stage__header {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 40px;
  align-items: center;
  min-height: 64px;
  padding: 8px 10px;
  background: rgba(18, 18, 18, 0.95);
}

.chat-stage__back,
.chat-stage__header-side {
  width: 36px;
  height: 36px;
}

.chat-stage__back {
  display: grid;
  place-items: center;
  color: #ffffff;
  font-size: 34px;
  line-height: 1;
}

.chat-stage__title {
  min-width: 0;
  text-align: center;
}

.chat-stage__title h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: #ffffff;
}

.chat-header-status {
  margin: 2px 0 0;
  color: rgba(255, 255, 255, 0.72);
  font-size: 12px;
  line-height: 1.2;
}

.chat-stage__body {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.chat-stage__overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.16) 0%, rgba(7, 10, 14, 0.12) 100%);
  pointer-events: none;
}

.chat-stage__content,
.chat-form {
  position: relative;
  z-index: 1;
}

.chat-stage__content {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  width: 100%;
  padding: 14px;
  overflow-y: auto;
}

.chapter-panel,
.chat-context {
  border-radius: 16px;
  backdrop-filter: blur(12px);
}

.chapter-panel {
  padding: 14px;
  background: rgba(14, 18, 24, 0.56);
  color: #ffffff;
}

.chapter-panel__grid {
  display: grid;
  gap: 12px;
}

.field-block {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
}

.field-block select {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  background: rgba(10, 12, 16, 0.7);
  color: #ffffff;
  outline: none;
}

.chapter-summary {
  margin-top: 10px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 12px;
  line-height: 1.5;
}

.chat-status {
  align-self: center;
  max-width: min(100%, 320px);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(120, 120, 120, 0.62);
  color: #ffffff;
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
}

.chat-status[hidden],
.chat-context[hidden],
.chat-starters[hidden] {
  display: none;
}

.chat-context {
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.18);
  color: rgba(255, 255, 255, 0.92);
  font-size: 12px;
  line-height: 1.5;
}

.chat-starters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.starter-pill {
  min-height: 38px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: #ff5b92;
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 10px 24px rgba(255, 91, 146, 0.28);
  cursor: pointer;
}

.chat-messages {
  display: grid;
  gap: 14px;
  min-height: 280px;
  padding-bottom: 8px;
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.message-row--user {
  justify-content: flex-end;
}

.message-avatar {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  overflow: hidden;
  border-radius: 12px;
  background: rgba(20, 20, 20, 0.82);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.14);
}

.message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.message-avatar span {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
}

.message-bubble {
  max-width: min(78%, 280px);
  padding: 12px 14px;
  border-radius: 18px;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.55;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.16);
}

.message-bubble--assistant {
  border-bottom-left-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  color: #222222;
  white-space: normal;
}

.message-bubble--user {
  border-bottom-right-radius: 8px;
  background: linear-gradient(135deg, #ff5b92, #ff7ca8);
  color: #ffffff;
  white-space: pre-wrap;
}

.message-bubble.is-streaming {
  color: rgba(34, 34, 34, 0.55);
  white-space: pre-wrap;
}

.message-bubble--assistant > :first-child {
  margin-top: 0;
}

.message-bubble--assistant > :last-child {
  margin-bottom: 0;
}

.message-bubble--assistant p,
.message-bubble--assistant ul,
.message-bubble--assistant ol,
.message-bubble--assistant pre {
  margin: 0;
}

.message-bubble--assistant p + p,
.message-bubble--assistant p + ul,
.message-bubble--assistant p + ol,
.message-bubble--assistant ul + p,
.message-bubble--assistant ol + p,
.message-bubble--assistant ul + ul,
.message-bubble--assistant ol + ol {
  margin-top: 10px;
}

.message-bubble--assistant ul,
.message-bubble--assistant ol {
  padding-left: 18px;
}

.message-bubble--assistant li + li {
  margin-top: 4px;
}

.message-bubble--assistant strong {
  font-weight: 700;
}

.message-bubble--assistant code {
  padding: 1px 5px;
  border-radius: 6px;
  background: rgba(17, 17, 17, 0.08);
  font-family: "Consolas", "SFMono-Regular", monospace;
  font-size: 0.92em;
}

.dynamic-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -4px 0 4px 46px;
  max-width: min(78%, 320px);
}

.dynamic-suggestions__button {
  min-height: 34px;
  padding: 7px 11px;
  border: 1px solid rgba(255, 91, 146, 0.34);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  color: #523444;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.35;
  text-align: left;
}

.dynamic-suggestions__button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.attachment-preview {
  display: grid;
  gap: 8px;
  width: min(100%, 220px);
}

.attachment-preview img,
.attachment-preview video {
  width: 100%;
  max-height: 220px;
  border-radius: 10px;
  object-fit: cover;
  background: rgba(0, 0, 0, 0.12);
}

.attachment-preview__caption {
  font-size: 12px;
  line-height: 1.3;
  opacity: 0.88;
}

.chat-stage__footer {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 8px;
  padding: 0 14px calc(12px + env(safe-area-inset-bottom));
}

.chat-upload-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.chat-upload-actions__button,
.chat-upload-tray__remove {
  border: 0;
  cursor: pointer;
}

.chat-upload-actions__button {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 4px;
  background: rgba(34, 34, 34, 0.92);
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
}

.chat-upload-actions__button:disabled,
.chat-upload-tray__remove:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.chat-upload-tray {
  display: grid;
  gap: 6px;
}

.chat-upload-tray[hidden] {
  display: none;
}

.chat-upload-tray__item {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 4px;
  background: rgba(18, 18, 18, 0.74);
  color: #ffffff;
  font-size: 12px;
  line-height: 1.3;
  backdrop-filter: blur(8px);
}

.chat-upload-tray__item span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-upload-tray__remove {
  flex: 0 0 auto;
  padding: 4px 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
  font-size: 12px;
}

.scene-dock {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-items: stretch;
}

.scene-dock__item {
  display: flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  background: rgba(228, 225, 220, 0.18);
  color: #ffffff;
  text-align: center;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.12);
  backdrop-filter: blur(8px);
}

.scene-dock__item span {
  color: inherit;
  font-size: 12px;
  line-height: 1.2;
  text-align: center;
}

.scene-dock__item.is-active {
  border-color: rgba(255, 79, 139, 0.9);
  background: rgba(255, 79, 139, 0.24);
}

.chat-form {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 70px;
  flex-shrink: 0;
  gap: 10px;
  align-items: end;
  padding: 0;
  background: none;
}

.chat-form__plus,
#chat-send-btn {
  border: 0;
  border-radius: 14px;
  cursor: pointer;
}

.chat-form__plus {
  width: 42px;
  height: 42px;
  background: rgba(34, 34, 34, 0.96);
  color: #ff5b92;
  font-size: 28px;
  line-height: 1;
}

.chat-form textarea {
  min-height: 44px;
  max-height: 160px;
  padding: 11px 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  background: rgba(34, 34, 34, 0.96);
  color: #f5f5f5;
  resize: none;
  outline: none;
}

.chat-form textarea::placeholder {
  color: #8e8e8e;
}

#chat-send-btn {
  min-height: 44px;
  background: #ff5b92;
  color: #ffffff;
  font-weight: 700;
}

#chat-send-btn:disabled,
.starter-pill:disabled,
.chat-form__plus:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

@media (min-width: 768px) {
  .chat-page {
    padding: 24px 12px 32px;
  }

  .chat-stage {
    min-height: 760px;
    height: min(860px, calc(100vh - 48px));
    border-radius: 18px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
  }

  .chapter-panel__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 767px) {
  .role-directory__header {
    min-height: 72px;
    flex-direction: column;
    gap: 8px;
  }

  .role-directory__auth {
    position: static;
  }

  .auth-shell {
    padding: 0;
  }

  .auth-card {
    min-height: 100vh;
  }

  .auth-card__header {
    min-height: 112px;
    gap: 10px;
  }

  .auth-card__header h1 {
    font-size: 32px;
  }

  .auth-card__header p {
    font-size: 17px;
  }

  .auth-form {
    gap: 19px;
    padding: 34px 22px 28px;
  }

  .auth-field {
    font-size: 18px;
  }

  .auth-field input {
    min-height: 58px;
    font-size: 17px;
  }

  .auth-field small {
    font-size: 15px;
  }

  .chat-stage {
    width: 100%;
    border-radius: 0;
    box-shadow: none;
  }

  .chat-stage__content {
    padding: 12px;
  }

  .chat-stage__footer {
    gap: 6px;
    padding: 0 12px calc(10px + env(safe-area-inset-bottom));
  }

  .chat-form {
    gap: 8px;
  }

  .message-bubble {
    max-width: min(80%, 280px);
  }
}
