:root {
  --bg: #f0f4f8;
  --surface: #ffffff;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #dbeafe;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --success: #059669;
  --success-bg: #d1fae5;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --error: #dc2626;
  --error-bg: #fee2e2;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(135deg, #eef2ff 0%, var(--bg) 50%, #ecfdf5 100%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

.header {
  text-align: center;
  margin-bottom: 2rem;
}

.header h1 {
  font-size: 1.875rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-muted);
  margin-top: 0.5rem;
  font-size: 0.95rem;
}

.progress-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.75rem;
}

.progress-label {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.progress-count strong {
  font-size: 1.75rem;
  color: var(--primary);
}

.progress-bar {
  height: 10px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #6366f1);
  border-radius: 999px;
  width: 0%;
  transition: width 0.4s ease;
}

.progress-hint {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.main-grid {
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 720px) {
  .main-grid {
    grid-template-columns: 1fr;
  }
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 1.125rem;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.form-group input[type="text"] {
  width: 100%;
  padding: 0.65rem 0.875rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.2s;
}

.form-group input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.preference-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.625rem;
}

.pref-rank {
  flex-shrink: 0;
  width: 72px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--primary);
}

.pref-rank.rank-1 { color: #b45309; }
.pref-rank.rank-2 { color: #64748b; }

.preference-row select {
  flex: 1;
  padding: 0.55rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.82rem;
  background: white;
  cursor: pointer;
  min-width: 0;
}

.preference-row select:focus {
  outline: none;
  border-color: var(--primary);
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.btn {
  padding: 0.65rem 1.25rem;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-primary:disabled {
  background: #94a3b8;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1.5px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

.form-message {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  display: none;
}

.form-message.show {
  display: block;
}

.form-message.success {
  background: var(--success-bg);
  color: var(--success);
}

.form-message.error {
  background: var(--error-bg);
  color: var(--error);
}

.form-message.info {
  background: var(--primary-light);
  color: var(--primary);
}

.name-list {
  list-style: none;
  max-height: 360px;
  overflow-y: auto;
}

.name-list li {
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s;
}

.name-list li:hover:not(.empty-hint) {
  background: var(--primary-light);
  color: var(--primary);
}

.name-list .empty-hint {
  color: var(--text-muted);
  cursor: default;
  font-size: 0.85rem;
}

.result-card.hidden {
  display: none;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.summary-item {
  text-align: center;
  padding: 0.875rem;
  background: var(--bg);
  border-radius: 8px;
}

.summary-item .num {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
}

.summary-item .label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.result-table-wrap {
  overflow-x: auto;
  margin-bottom: 1.5rem;
}

.result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.result-table th,
.result-table td {
  padding: 0.65rem 0.875rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  word-break: break-word;
  max-width: 280px;
}

.result-table th {
  background: var(--bg);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.rank-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.rank-badge.r1 { background: #fef3c7; color: #b45309; }
.rank-badge.r2 { background: #e0e7ff; color: #4338ca; }
.rank-badge.r3 { background: #dbeafe; color: #1d4ed8; }
.rank-badge.r4,
.rank-badge.r5,
.rank-badge.r6 { background: var(--bg); color: var(--text-muted); }

.prefs-inline {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.topic-stats h3 {
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
}

.topic-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
}

.topic-stat-item {
  padding: 0.875rem;
  background: var(--bg);
  border-radius: 8px;
  font-size: 0.85rem;
}

.topic-stat-item .topic-name {
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.topic-stat-item .members {
  color: var(--text-muted);
  line-height: 1.5;
}

.topic-stat-item .rank-detail {
  margin-top: 0.35rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.locked-overlay {
  opacity: 0.6;
  pointer-events: none;
}

.preference-row select:disabled {
  background: var(--bg);
  color: var(--text-muted);
  cursor: not-allowed;
}

.btn-warning {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1.5px solid #fcd34d;
}

.btn-warning:hover:not(:disabled) {
  background: #fde68a;
}

.btn-warning:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.my-result-lookup {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.my-result-lookup .form-group {
  flex: 1;
  min-width: 200px;
  margin-bottom: 0;
}

.my-result {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.my-result.hidden {
  display: none;
}

.my-result-item {
  padding: 1rem 1.25rem;
  background: var(--bg);
  border-radius: 8px;
}

.my-result-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.my-result-value {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.5;
  word-break: break-word;
}

.admin-panel {
  margin-top: 1.5rem;
  padding: 0;
  overflow: hidden;
}

.admin-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border: none;
  background: var(--surface);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.admin-toggle:hover {
  color: var(--text);
  background: var(--bg);
}

.admin-chevron {
  font-size: 0.75rem;
}

.admin-content {
  display: none;
  padding: 0 1.5rem 1.5rem;
  border-top: 1px solid var(--border);
}

.admin-content.open {
  display: block;
}

.admin-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 1rem 0;
}

.admin-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}
