:root,
html[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f4f6;
  --card: #ffffff;
  --chip: #f1f2f6;
  --chip-focus: #ffffff;
  --rim: #e1e3ea;
  --rim-strong: #c5c9d4;
  --text: #17181c;
  --dim: #73788a;
  --line: #e4e7ec;
  --primary: #1c1c21;
  --primary-hover: #33333a;
  --primary-text: #ffffff;
  --accent: #007aff;
  --danger: #b42318;
  --ok: #2e7d32;
  --seg: #e7e8ee;
  --seg-on: #ffffff;
  --overlay: rgba(17, 19, 24, 0.45);
  --shadow: 0 1px 2px rgba(17, 19, 24, 0.04);
  --shadow-lg: 0 16px 40px rgba(17, 19, 24, 0.18);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1014;
  --card: #191b21;
  --chip: #101117;
  --chip-focus: #22242c;
  --rim: #2a2d36;
  --rim-strong: #454a58;
  --text: #f2f3f7;
  --dim: #8b90a0;
  --line: #2a2d36;
  --primary: #f2f3f7;
  --primary-hover: #ffffff;
  --primary-text: #111318;
  --accent: #0a84ff;
  --danger: #ff6b6b;
  --ok: #5bd67a;
  --seg: #101117;
  --seg-on: #2a2d36;
  --overlay: rgba(0, 0, 0, 0.64);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 18px 44px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px 24px 8px;
}

.brand-word,
.auth-logo {
  display: block;
  width: auto;
  image-rendering: pixelated;
}

.brand-word {
  height: 44px;
}

.auth-logo {
  height: 52px;
  margin: 0 auto 18px;
}

html[data-theme="dark"] .brand-word,
html[data-theme="dark"] .auth-logo {
  filter: invert(1);
}

.top-actions,
.theme {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme {
  gap: 2px;
  padding: 2px;
  border-radius: 999px;
  background: var(--seg);
}

.theme-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--dim);
  cursor: pointer;
}

.theme-btn.is-on {
  background: var(--seg-on);
  color: var(--text);
}

.lang-select {
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}

.auth-page {
  min-height: calc(100vh - 80px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: min(400px, 100%);
  padding: 28px 26px 24px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.auth-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  padding: 4px;
  border-radius: 12px;
  background: var(--chip);
}

.auth-tab {
  flex: 1;
  padding: 9px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--dim);
  font-weight: 650;
  cursor: pointer;
}

.auth-tab.is-on {
  background: var(--seg-on);
  color: var(--text);
}

.auth-lead,
.captcha-lead {
  margin: 0 0 16px;
  color: var(--dim);
  font-size: 13px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

.field > span:first-child {
  color: var(--dim);
  font-size: 11px;
  font-weight: 600;
}

.well {
  display: flex;
  align-items: center;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: var(--chip);
}

.well:focus-within {
  border-color: var(--rim-strong);
  background: var(--chip-focus);
}

.well input {
  width: 100%;
  padding: 9px 11px;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
}

.well input::placeholder {
  color: var(--dim);
  opacity: 0.7;
}

.signup-only {
  display: none;
}

.auth-card.is-signup .signup-only {
  display: flex;
}

.terms-check {
  align-items: flex-start;
  gap: 8px;
  margin: 2px 0 8px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
}

.terms-check input {
  margin-top: 2px;
}

.terms-check a,
.legal-foot a,
.notice-dialog a {
  color: inherit;
}

.legal-foot {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 12px;
  margin: 0;
  padding: 8px 16px 18px;
  color: var(--dim);
  font-size: 12px;
}

.notice-dialog {
  width: min(460px, 100%);
}

.notice-dialog .terms-check {
  margin-top: 10px;
}

.notice-dialog .btn.primary {
  margin-top: 12px;
}

.btn {
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid var(--rim);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}

.btn.primary {
  width: 100%;
  margin-top: 6px;
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-text);
  font-weight: 650;
}

.btn.primary:hover {
  border-color: var(--primary-hover);
  background: var(--primary-hover);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.human-check {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin: 0 0 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--chip);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.human-box {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  border: 1.5px solid var(--rim-strong);
  border-radius: 4px;
}

.human-check[data-state="checking"] .human-box {
  border-color: var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.human-check[data-state="ok"] .human-box {
  border-color: var(--ok);
  background: var(--ok);
}

.human-copy {
  display: flex;
  flex: 1;
  min-width: 0;
  flex-direction: column;
}

.human-title {
  font-weight: 650;
}

.human-sub {
  color: var(--dim);
  font-size: 12px;
}

.human-shield {
  color: var(--dim);
  font-size: 22px;
}

.captcha-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 16px;
}

.captcha-backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay);
}

.captcha-dialog {
  position: relative;
  width: min(420px, 100%);
  padding: 22px 20px 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  box-shadow: var(--shadow-lg);
}

.captcha-dialog h2 {
  margin: 0 36px 8px 0;
  font-size: 18px;
}

.captcha-x {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--dim);
  font-size: 22px;
  cursor: pointer;
}

.turnstile-slot {
  display: flex;
  justify-content: center;
  min-height: 68px;
}

.extra-ref,
.extra-board {
  display: block;
  width: 96px;
  height: 96px;
  margin: 0 auto 12px;
  border-radius: 10px;
  background: var(--chip);
}

.extra-board {
  width: 100%;
  height: 72px;
  object-fit: contain;
}

.extra-choices,
.extra-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.extra-cell {
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--chip);
  cursor: pointer;
}

.extra-cell.is-on {
  border-color: var(--accent);
}

.extra-cell img {
  display: block;
  width: 100%;
  height: auto;
}

#extraSlide {
  width: 100%;
  margin-bottom: 12px;
}

#extraRefresh,
#tokenCopy {
  width: 100%;
  margin-top: 6px;
}

.error,
.token-warn {
  color: var(--danger);
}

.token-card h2 {
  margin: 0 0 10px;
}

.token-warn {
  margin: 0 0 16px;
}

#tokenValue {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  letter-spacing: 0.04em;
}

.token-check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 14px 0 12px;
}

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

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

@media (max-width: 640px) {
  .topbar {
    padding: 12px 16px 4px;
  }

  .brand-word {
    height: 34px;
  }

  .lang-select {
    max-width: 116px;
  }

  .auth-page {
    align-items: flex-start;
    padding: 28px 16px;
  }

  .auth-card {
    padding: 24px 18px 20px;
  }
}
