:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --bg-soft: #fff7ec;
  --panel: #fffdf8;
  --ink: #2c2a26;
  --muted: #6f6a62;
  --accent: #c86c2a;
  --accent-soft: #f2d5b8;
  --shadow: 0 18px 40px rgba(37, 26, 12, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Source Han Sans SC", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top left, #fff2df, #f4efe6 60%, #efe7da 100%);
}

.app-shell {
  height: 100vh;
  overflow: hidden;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 32px 16px;
}

.title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 1px;
}

.subtitle {
  font-size: 13px;
  color: var(--muted);
  margin-top: 6px;
}

.actions button {
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px;
  cursor: pointer;
  background: var(--accent);
  color: white;
  box-shadow: var(--shadow);
}

.actions button:disabled,
.panel button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.actions .ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  box-shadow: none;
}

.auth-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.user-badge {
  background: #fff0dc;
  border: 1px solid #f0d1af;
  color: #6b3c18;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
}

.ghost-link {
  text-decoration: none;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.algo-switch-bar {
  margin: 12px 24px 0;
  padding: 10px 14px;
  border-radius: 16px;
  background: linear-gradient(135deg, #f7efe2, #f2e5d3);
  border: 1px solid #e6d3be;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.algo-switch-title {
  font-size: 12px;
  font-weight: 600;
  color: #6b3c18;
}

.algo-switch-tabs {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #f0ddc7;
  padding: 4px;
  border-radius: 999px;
  border: 1px solid #e4c7a9;
}

.algo-switch-tab {
  text-decoration: none;
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  color: #6b3c18;
  background: transparent;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.algo-switch-tab.active,
.algo-switch-tab:hover {
  background: var(--accent);
  color: #fff7ec;
  border-color: #b85f22;
  box-shadow: 0 6px 14px rgba(200, 108, 42, 0.25);
}

.algo-switch-desc {
  font-size: 12px;
  color: #6f4b2d;
}

.auth-actions #logout-btn,
.auth-actions #admin-link {
  display: none;
}

.content {
  flex: 1;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  padding: 0 24px 24px;
  min-height: 0;
}

.algo-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  padding: 0 24px;
}

.algo-card {
  border: 1px solid #e1e3e6;
  border-radius: 14px;
  padding: 14px 16px;
  background: #fafbfc;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.06);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.algo-title {
  font-size: 14px;
  font-weight: 600;
  color: #1f2937;
}

.algo-desc {
  font-size: 12px;
  color: #5f6b7a;
  line-height: 1.4;
}

.algo-action {
  align-self: flex-start;
  margin-top: 6px;
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
}

.panel {
  background: var(--panel);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow: auto;
}

.tab-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  position: sticky;
  top: 0;
  background: var(--panel);
  padding-bottom: 6px;
  z-index: 2;
}

.tab {
  border: 1px solid #f0e6d7;
  background: #fffaf3;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  color: #6b3c18;
}

.tab.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: #5b3516;
  box-shadow: var(--shadow);
}

.tab-content {
  display: none;
  flex-direction: column;
  gap: 12px;
}

.tab-content.active {
  display: flex;
}

.section-block {
  border: 1px solid #f0e6d7;
  border-radius: 14px;
  padding: 10px 12px;
  background: #fffaf4;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-title {
  font-weight: 600;
  margin-top: 6px;
}

.status {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: #5b3516;
  font-size: 13px;
}

.stats {
  display: grid;
  gap: 6px;
  font-size: 13px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.note {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

.sim-note {
  margin-top: 6px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid #f0d8b2;
  background: #fff4da;
  color: #8a5b1f;
  font-weight: 600;
}

.demo-fab {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.demo-pill {
  border: 1px solid #f0d8b2;
  background: rgba(255, 247, 230, 0.92);
  color: #7a4b18;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 10px 20px rgba(107, 74, 43, 0.25);
  cursor: pointer;
}

.demo-panel {
  width: 240px;
  max-width: 76vw;
  background: rgba(255, 247, 230, 0.96);
  border: 1px solid #f0d8b2;
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: 0 16px 30px rgba(107, 74, 43, 0.22);
  display: grid;
  gap: 6px;
  opacity: 0;
  transform: translateY(-6px) scale(0.98);
  pointer-events: none;
  transition: all 0.18s ease;
}

.demo-panel .ghost[disabled],
.demo-panel button[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.demo-hint {
  font-size: 12px;
  color: #9b6b32;
}

.demo-fab:hover .demo-panel,
.demo-fab.open .demo-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.demo-fab:hover .demo-pill,
.demo-fab.open .demo-pill {
  background: #f0a84b;
  color: #fff7ec;
  border-color: #d9862d;
}

.demo-title {
  font-size: 12px;
  font-weight: 700;
  color: #7a4b18;
}

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

.filter {
  border: 1px solid #e4dccf;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
  background: #fffaf2;
  width: 100%;
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.rod-list {
  max-height: 220px;
  overflow: auto;
  display: grid;
  gap: 6px;
  padding-right: 4px;
}

.rod-item {
  border: 1px solid #f0e6d7;
  background: #fffaf3;
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12px;
  cursor: pointer;
  text-align: left;
}

.rod-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: #5b3516;
}

.log-box {
  background: #1f1c17;
  color: #f6f1e8;
  border-radius: 10px;
  padding: 10px;
  font-size: 11px;
  line-height: 1.4;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
}

.tips {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: #5b3516;
}

.tip-item {
  padding: 8px 10px;
  border-radius: 10px;
  background: #fff4e0;
  border: 1px solid #f1d6b1;
}

.upload-progress {
  height: 8px;
  border-radius: 999px;
  background: #efe1cf;
  overflow: hidden;
  margin-top: 8px;
}

.upload-progress.hidden,
.upload-progress-text.hidden {
  display: none;
}

.upload-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #f1a23d, #c86c2a);
  width: 0%;
  transition: width 0.2s ease;
}

.upload-progress-text {
  font-size: 12px;
  color: #6b4a2b;
  margin-top: 6px;
}

.viewer {
  background: linear-gradient(120deg, #fff5e1 0%, #f6efe4 40%, #efe7da 100%);
  border-radius: 22px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  min-height: 0;
}

.loading {
  position: absolute;
  inset: 0;
  background: rgba(32, 24, 18, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  z-index: 3;
  text-align: center;
  color: #fff3e1;
  backdrop-filter: blur(2px);
}

.loading.hidden {
  display: none;
}

.loading-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.loading-detail {
  font-size: 12px;
  color: rgba(255, 243, 225, 0.9);
  line-height: 1.5;
  max-width: 320px;
}

.loading-spinner {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 3px solid rgba(255, 243, 225, 0.3);
  border-top-color: #ffbf6a;
  animation: spin 1s linear infinite;
  box-shadow: 0 0 18px rgba(255, 191, 106, 0.35);
}

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

#viewer {
  width: 100%;
  height: 100%;
  display: block;
}

.section {
  border: 1px solid #f0e6d7;
  border-radius: 14px;
  padding: 10px 12px;
  background: #fffaf4;
}

.section[open] {
  background: #fff9f0;
}

.section > summary {
  list-style: none;
  cursor: pointer;
}

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

.section > summary.section-title {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section > summary.section-title::before {
  content: "▸";
  font-size: 12px;
  color: var(--accent);
  transform: translateY(-1px);
}

.section[open] > summary.section-title::before {
  content: "▾";
}

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

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  body {
    overflow: auto;
  }
}

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
  overflow: hidden;
}

.auth-card {
  width: min(520px, 100%);
  background: var(--panel);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 26px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
  z-index: 1;
}

.auth-title {
  font-size: 22px;
  font-weight: 700;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}

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

@media (max-width: 640px) {
  .field-row {
    grid-template-columns: 1fr;
  }
}

.field input,
.field select,
.field textarea {
  border: 1px solid #e4dccf;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  background: #fffaf2;
}

.primary-btn {
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-size: 14px;
}

.link-row {
  display: flex;
  gap: 12px;
  font-size: 12px;
  flex-wrap: wrap;
}

.link-row a {
  color: var(--accent);
  text-decoration: none;
}

.promo-row {
  margin-top: 4px;
}

.promo-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: #ffe6c4;
  border: 1px solid #f2c48b;
  color: #6b3c18;
  font-weight: 600;
  text-decoration: none;
}

.promo-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  padding: 0 8px;
  height: 30px;
  border-radius: 10px;
  background: #f1ad57;
  color: #fff6ea;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  box-shadow: 0 6px 12px rgba(120, 70, 20, 0.18);
}

.promo-text {
  flex: 1;
  text-align: left;
}

.auth-note {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}

.site-notice {
  display: none;
  padding: 10px 12px;
  background: #fff3d9;
  border: 1px solid #f0d1a4;
  border-radius: 12px;
  font-size: 12px;
  color: #6b3c18;
}

.version-footer {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed #f0e0cb;
}

.version-note {
  font-size: 12px;
  color: #7a6a5a;
  white-space: pre-line;
}

.release-notes {
  margin: 6px 0 0;
  padding-left: 18px;
  font-size: 12px;
  color: #7a6a5a;
  display: grid;
  gap: 4px;
  list-style: none;
  padding-left: 0;
}

.release-item {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.release-date {
  font-variant-numeric: tabular-nums;
  color: #5c4a38;
}

.release-tag {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #f1d6b1;
  color: #6b3c18;
}

.release-text {
  color: #7a6a5a;
}

.admin-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 16px;
}

.admin-tab {
  border: 1px solid #e5dccf;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  background: #fff6ea;
  color: #6b5340;
  cursor: pointer;
}

.admin-tab.active {
  background: #f4d3a3;
  border-color: #f0c27c;
  color: #4a3523;
  font-weight: 600;
}

.admin-section {
  display: none;
}

.admin-section.active {
  display: block;
}

.admin-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.admin-summary .stat {
  background: #fff4e4;
  border: 1px solid #f0d8be;
  border-radius: 12px;
  padding: 10px;
  font-size: 12px;
  color: #5a3516;
}

.admin-settings {
  display: grid;
  gap: 10px;
  background: #fffaf3;
  border: 1px solid #f0e6d7;
  border-radius: 12px;
  padding: 12px;
}

.admin-settings textarea {
  border: 1px solid #e4dccf;
  border-radius: 10px;
  padding: 10px;
  font-size: 12px;
  background: #fffaf2;
  resize: vertical;
}

.admin-log-list {
  display: grid;
  gap: 6px;
  max-height: 260px;
  overflow: auto;
  padding-right: 4px;
}

.admin-log-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr 1.4fr;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid #f0e6d7;
  border-radius: 10px;
  background: #fffaf3;
  font-size: 12px;
}

.admin-log-row > div {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-log-row .log-message {
  white-space: nowrap;
}

.admin-log-row .tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
}

.admin-log-row .ok {
  background: #d7f0d8;
  color: #2f6c36;
}

.admin-log-row .fail {
  background: #f7d6d6;
  color: #8b2f2f;
}

.admin-card {
  width: min(860px, 100%);
}

.profile-card {
  width: min(560px, 100%);
}

.profile-info {
  font-size: 12px;
  color: #5b4a39;
  background: #fff8ec;
  border: 1px solid #efe1cf;
  border-radius: 10px;
  padding: 10px 12px;
  line-height: 1.6;
}

.danger-note {
  font-size: 12px;
  color: #7c2d2d;
  background: #fdeaea;
  border: 1px solid #f4bcbc;
  border-radius: 10px;
  padding: 8px 10px;
  line-height: 1.5;
}

.admin-list {
  display: grid;
  gap: 8px;
}

.admin-row {
  display: grid;
  grid-template-columns: 1.2fr 0.9fr 1fr 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid #f0e6d7;
  background: #fffaf3;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
}

.admin-row.user-row {
  grid-template-columns: 1.2fr 0.9fr 0.8fr 0.9fr 0.9fr 1fr auto;
}

.algo-access {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.admin-row.is-disabled {
  background: #f6f1e8;
  opacity: 0.7;
}

.admin-row .role-text {
  color: #6a5947;
}

.admin-row.invite-row {
  grid-template-columns: 1.2fr 0.8fr 1.2fr 1fr auto;
}

.invite-code {
  font-family: "Courier New", monospace;
  letter-spacing: 0.5px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-row.run-row {
  grid-template-columns: 40px 1.2fr 0.9fr 1fr 1fr 0.9fr auto;
}

.admin-row select {
  border: 1px solid #e4dccf;
  border-radius: 8px;
  background: #fffaf2;
  padding: 6px;
  font-size: 12px;
}

.admin-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.admin-actions.muted {
  color: #8b7b6a;
}

.admin-detail {
  border: 1px solid #f0e6d7;
  background: #fffaf3;
  border-radius: 10px;
  padding: 12px;
  font-size: 12px;
  line-height: 1.6;
  color: #4d3b2a;
}

.admin-log {
  margin-top: 8px;
  padding: 8px;
  background: #1f1c17;
  color: #f6f1e8;
  border-radius: 8px;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
}

.toggle.small span {
  font-size: 12px;
}

.toggle.small input {
  transform: scale(0.9);
}

@media (max-width: 720px) {
  .admin-row {
    grid-template-columns: 1fr;
  }

  .admin-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-log-row {
    grid-template-columns: 1fr;
  }
}

.auth-page::before,
.auth-page::after {
  content: "";
  position: absolute;
  width: 360px;
  height: 360px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(200, 108, 42, 0.18), rgba(200, 108, 42, 0));
  top: -120px;
  left: -80px;
  filter: blur(4px);
}

.auth-page::after {
  width: 420px;
  height: 420px;
  top: auto;
  bottom: -180px;
  left: auto;
  right: -120px;
  background: radial-gradient(circle, rgba(97, 140, 122, 0.18), rgba(97, 140, 122, 0));
}
