/* Name Chooser Overlay - Redesigned */
.name-chooser {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(20, 20, 25, 0.92);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  backdrop-filter: blur(8px);
  animation: fadeIn 0.4s ease-out;
}

.name-chooser.hidden {
  display: none;
}

/* ── 认证错误弹层 ──────────────────────────────────────
   登录失败发生在进入聊天室之前，没有消息流可写，用独立模态承载。
   视觉与 .name-chooser 对齐（深色卡片 + 圆角 + 上浮动画）。 */
.auth-error-overlay {
  max-width: none;
  max-height: none;
  margin: 0;
  border: 0;
  color: inherit;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(20, 20, 25, 0.92);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1100;
  backdrop-filter: blur(8px);
  animation: fadeIn 0.3s ease-out;
  padding: 20px;
  box-sizing: border-box;
}

.auth-error-overlay:not([open]) {
  display: none;
}

.auth-error-dialog {
  position: relative;
  background: #2b2633;
  border-radius: 24px;
  padding: 40px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.08);
  animation: slideUp 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.auth-error-icon {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
  color: rgb(var(--sekai-danger, 235 87 87));
}

.auth-error-code {
  display: inline-block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  letter-spacing: 0.5px;
  color: rgb(var(--sekai-danger, 235 87 87));
  background: rgb(var(--sekai-danger, 235 87 87) / 0.12);
  border: 1px solid rgb(var(--sekai-danger, 235 87 87) / 0.25);
  padding: 3px 10px;
  border-radius: 8px;
  margin-bottom: 14px;
}

.auth-error-title {
  margin: 0 0 12px;
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.auth-error-desc {
  margin: 0 0 18px;
  color: #c9ccd1;
  font-size: 14px;
  line-height: 1.7;
  text-align: left;
}

.auth-error-solution {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 16px;
  color: #d7dae0;
  font-size: 14px;
  line-height: 1.7;
}

.auth-error-solution__label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #8a7bce;
}

.auth-error-debug {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.6;
  color: #7a7f8a;
  background: #1e1b24;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 20px;
  text-align: left;
  word-break: break-word;
  user-select: text;
}

.auth-error-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.auth-error-btn {
  flex: 1;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(35, 39, 42, 0.6);
  color: #e0e0e0;
  transition: background-color 0.2s var(--sekai-ease-out, ease), box-shadow 0.2s var(--sekai-ease-out, ease), transform 0.2s var(--sekai-ease-out, ease), filter 0.2s var(--sekai-ease-out, ease);
  font-family: inherit;
}

.auth-error-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  transform: translateY(-1px);
}

.auth-error-btn--primary {
  background: #5865f2;
  border-color: transparent;
  color: #fff;
}

.auth-error-btn--primary:hover {
  background: #4752c4;
  box-shadow: 0 8px 15px rgba(88, 101, 242, 0.3);
}

.auth-expired-overlay {
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.auth-expired-overlay .auth-error-dialog {
  box-sizing: border-box;
  max-height: 100%;
  overflow-y: auto;
  padding: 28px;
  background: rgb(var(--nc-panel, 43 38 51));
}
.auth-expired-overlay .auth-error-title { color: rgb(var(--sekai-fg, 255 255 255)); }
.auth-expired-mark { display: block; width: 48px; height: 48px; margin: 0 auto 16px; }
.auth-expired-overlay .auth-error-desc { color: rgb(var(--sekai-fg-muted, 201 204 209)); }
.auth-expired-overlay .auth-error-actions { flex-direction: column; }
.auth-expired-overlay .auth-error-btn { min-height: 44px; flex: none; }
.auth-expired-overlay .auth-error-btn:focus-visible { outline: 2px solid rgb(var(--sekai-accent, 167 139 250)); outline-offset: 3px; }
.auth-expired-overlay .auth-error-btn:hover { transform: none; }
.auth-expired-overlay .auth-error-btn:disabled { opacity: .6; cursor: wait; }
.auth-expired-overlay .auth-error-btn:active { filter: brightness(.9); }
@media (prefers-reduced-motion: reduce) {
  .auth-expired-overlay, .auth-expired-overlay .auth-error-dialog { animation: none; }
  .auth-expired-overlay .auth-error-btn { transition: none; }
}

.name-chooser-content {
  position: relative; /* For absolute positioning of close button */
  background: #2b2633;
  border-radius: 24px;
  padding: 48px;
  box-sizing: border-box;
  width: calc(100% - 32px);
  max-width: 478px;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.08);
  transform: translateY(0);
  animation: slideUp 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.logo-area {
  margin-bottom: 24px;
  display: flex;
  justify-content: center;
}

.logo-area svg {
  filter: drop-shadow(0 0 10px rgba(138, 123, 206, 0.4));
  animation: float 6s ease-in-out infinite;
}

.name-chooser-content h2 {
  margin: 0 0 8px;
  color: #fff;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.subtitle {
  margin: 0 0 32px;
  color: #b9bbbe;
  font-size: 14px;
}

.input-wrapper {
  position: relative;
  margin-bottom: 24px;
  text-align: left;
}

.name-input {
  width: 100%;
  padding: 16px 20px;
  background-color: #1e1b24;
  border: 2px solid transparent;
  border-radius: 12px;
  color: #fff;
  font-size: 16px;
  outline: none;
  box-sizing: border-box;
  transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  font-family: inherit;
}

.name-input::placeholder {
  color: #6a6f7a;
}

.name-input:focus {
  background-color: #1e1b24;
  border-color: #7289da;
  box-shadow: 0 0 0 3px rgba(114, 137, 218, 0.15);
}

.name-submit {
  width: 100%;
  padding: 16px;
  background: #5865f2;
  border: none;
  border-radius: 12px;
  color: #ffffff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s var(--sekai-ease-out, ease), box-shadow 0.2s var(--sekai-ease-out, ease), transform 0.2s var(--sekai-ease-out, ease);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  outline: none;
}

.name-submit:hover {
  background: #4752c4;
  transform: translateY(-2px);
  box-shadow: 0 8px 15px rgba(88, 101, 242, 0.3);
}

.name-submit:active {
  transform: translateY(0);
  background: #3c45a5;
}

.sekai-pass-login {
  position: relative;
  width: 100%;
  padding: 14px;
  background: rgba(35, 39, 42, 0.6);
  border: 1px solid rgba(88, 101, 242, 0.3);
  border-radius: 12px;
  color: #e0e0e0;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.3s var(--sekai-ease-out, ease), border-color 0.3s var(--sekai-ease-out, ease), color 0.3s var(--sekai-ease-out, ease), box-shadow 0.3s var(--sekai-ease-out, ease);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  outline: none;
  backdrop-filter: blur(10px);
  overflow: hidden;
}

.sekai-pass-login:hover {
  background: rgba(88, 101, 242, 0.15);
  border-color: #5865f2;
  color: #fff;
  box-shadow: 0 4px 25px rgba(88, 101, 242, 0.35);
}

.sekai-pass-login svg {
  transition: transform 0.3s ease, color 0.3s ease, filter 0.3s ease;
  color: #5865f2;
  will-change: transform;
}

.sekai-pass-login:hover svg {
  transform: scale(1.1);
  color: #fff;
  filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.6));
}

.sekai-pass-login:active {
  transform: scale(0.98);
  background: rgba(88, 101, 242, 0.1);
}

/* Optional: Add a subtle shine effect on hover */
.sekai-pass-login::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 50%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.1),
    transparent
  );
  transform: skewX(-20deg);
  transition: 0.5s;
}

.sekai-pass-login:hover::after {
  left: 150%;
  transition: 0.7s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes float {
  0% { transform: translateY(0px); }
  50% { transform: translateY(-6px); }
  100% { transform: translateY(0px); }
}

.input-error {
  color: rgb(var(--sekai-danger));
  font-size: 13px;
  margin-top: 8px;
  min-height: 20px;
  opacity: 0;
  transition: opacity 0.2s;
  text-align: left;
  font-weight: 500;
}

.input-error.visible {
  opacity: 1;
}

.name-input.error {
  border-color: rgb(var(--sekai-danger));
  box-shadow: 0 0 0 3px rgb(var(--sekai-danger) / 0.15);
}
.name-input.error:focus {
  border-color: rgb(var(--sekai-danger));
}

.chooser-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: transparent;
  border: none;
  color: #b9bbbe;
  cursor: pointer;
  padding: 4px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s, color 0.2s;
  outline: none;
}

.chooser-close:hover {
  background-color: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.chooser-close.hidden {
  display: none;
}

.name-chooser :is(input, button):focus-visible {
  outline: 2px solid rgb(var(--sekai-accent));
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .name-chooser, .name-chooser-content, .name-chooser .logo-area svg {
    animation: none;
  }
  .name-chooser *, .name-chooser *::before, .name-chooser *::after {
    transition: none;
  }
}
