/* ===== 全局样式 ===== */
:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --bg: #0f172a;
  --card-bg: #1e293b;
  --card-hover: #334155;
  --text: #f1f5f9;
  --text-light: #94a3b8;
  --border: #334155;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --good-faction: #22c55e;
  --bad-faction: #ef4444;
  --neutral-faction: #f59e0b;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== 布局 ===== */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1rem;
  min-height: 100vh;
}

/* ===== 头部 ===== */
.header {
  text-align: center;
  margin-bottom: 2rem;
  position: relative;
}

.header h1 {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-light);
  font-size: 1.1rem;
}

.admin-toggle {
  position: absolute;
  top: 0;
  right: 0;
  padding: 0.5rem 1rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-light);
  cursor: pointer;
  transition: all 0.2s;
}

.admin-toggle:hover {
  border-color: var(--primary);
  color: var(--text);
}

.admin-toggle.unlocked {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* ===== 主菜单网格 ===== */
.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin: 2rem 0;
}

.menu-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 200px;
}

.menu-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), #8b5cf6);
  transform: scaleX(0);
  transition: transform 0.3s;
}

.menu-card:hover {
  transform: translateY(-4px);
  border-color: var(--primary);
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.2);
}

.menu-card:hover::before {
  transform: scaleX(1);
}

.menu-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.menu-card h2 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
  font-weight: 600;
}

.menu-card p {
  color: var(--text-light);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
  line-height: 1.4;
}

.menu-card .btn-small {
  margin-top: auto;
}

/* ===== 按钮样式 ===== */
.btn-small, .btn-primary, .btn-secondary, .btn-success, .btn-danger, .btn-warning, .btn-admin {
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
  white-space: nowrap;
}

.btn-small {
  background: var(--card-hover);
  color: var(--text);
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
}

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

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-secondary {
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text);
}

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

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover {
  background: #16a34a;
  transform: translateY(-1px);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
  transform: translateY(-1px);
}

.btn-warning {
  background: var(--warning);
  color: #000;
}

.btn-warning:hover {
  background: #d97706;
  transform: translateY(-1px);
}

.btn-admin {
  background: var(--card-bg);
  border: 1px solid var(--primary);
  color: var(--primary);
}

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

/* ===== 弹窗 ===== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
  padding: 1rem;
}

.modal-content {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 90%;
  max-width: 500px;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-large {
  max-width: 700px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--card-hover);
}

.modal-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-light);
  font-size: 1.5rem;
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: all 0.2s;
}

.close-btn:hover {
  background: var(--danger);
  color: white;
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

/* ===== 表单 ===== */
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
  transition: border-color 0.2s;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.form-row {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
  font-family: inherit;
  line-height: 1.5;
  overflow-wrap: anywhere; /* 长串连续无空格字符也能在任意处折行，避免输入溢出文本框右边缘 */
  word-break: break-word;
}

/* 表单字段前的文字标识（如「获胜得分」），新增/编辑角色等弹窗用 */
.form-field-label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-light);
  margin: 0.4rem 0 0.25rem;
}
.form-field-label:first-child {
  margin-top: 0;
}

/* ===== 列表容器 ===== */
.list-container {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.875rem 1rem;
  background: var(--bg);
  border-radius: 8px;
  margin-bottom: 0.5rem;
  transition: all 0.2s;
}

.list-item:hover {
  background: var(--card-hover);
  transform: translateX(2px);
}

.list-item-info {
  flex: 1;
  margin-right: 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.list-item-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--card-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  overflow: hidden;
  flex-shrink: 0;
}

.list-item-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.list-item-name {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.25rem;
}

.list-item-detail {
  font-size: 0.85rem;
  color: var(--text-light);
  line-height: 1.4;
}

.list-item-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.btn-icon {
  padding: 0.25rem 0.5rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-light);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-icon:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* ===== 排行榜 ===== */
.score-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.score-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: var(--bg);
  border-radius: 10px;
  border: 1px solid var(--border);
  transition: all 0.2s;
}

.score-item:hover {
  border-color: var(--primary);
  transform: translateX(4px);
}

.score-rank {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 0.9rem;
  border-radius: 50%;
  flex-shrink: 0;
}

.score-rank.rank-1 {
  background: linear-gradient(135deg, #ffd700, #ffed4e);
  color: #000;
  box-shadow: 0 2px 8px rgba(255, 215, 0, 0.4);
}

.score-rank.rank-2 {
  background: linear-gradient(135deg, #c0c0c0, #e8e8e8);
  color: #000;
}

.score-rank.rank-3 {
  background: linear-gradient(135deg, #cd7f32, #e8a868);
  color: #000;
}

.score-rank.rank-other {
  background: var(--card-hover);
  color: var(--text-light);
}

.score-player {
  flex: 1;
  min-width: 0;
}

.score-name {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

.score-stats {
  font-size: 0.8rem;
  color: var(--text-light);
}

.score-value {
  font-size: 1.25rem;
  font-weight: bold;
  color: var(--success);
  flex-shrink: 0;
}

/* ===== 页脚 ===== */
.footer {
  text-align: center;
  color: var(--text-light);
  font-size: 0.875rem;
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* ===== 空状态 ===== */
.empty-state {
  text-align: center;
  color: var(--text-light);
  padding: 2rem;
}

/* ===== 头像上传 ===== */
.avatar-upload {
  margin-bottom: 1.25rem;
}

.avatar-label {
  font-size: 0.9rem;
  color: var(--text-light);
  margin-bottom: 0.75rem;
}

.avatar-preview-row {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.avatar-preview {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--card-hover);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  overflow: hidden;
}

.avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-upload-btn {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.avatar-fields {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.avatar-text-input {
  width: 80px;
  text-align: center;
  font-size: 1.25rem;
}

/* 文字头像（1-2 个字）：2 字时缩小字号，避免圆形容器裁切 */
.list-item-avatar .avatar-text.is-2 { font-size: 1rem; }
.avatar-preview .avatar-text.is-2 { font-size: 1.5rem; }

/* ===== 管理员可见元素 ===== */
.admin-only {
  display: none !important;
}

body.is-admin .admin-only {
  display: flex !important;
}

body.is-admin td.admin-only,
body.is-admin th.admin-only {
  display: table-cell !important;
}

/* ===== 标签 ===== */
.tag {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.tag-good {
  background: rgba(34, 197, 94, 0.2);
  color: var(--good-faction);
}

.tag-bad {
  background: rgba(239, 68, 68, 0.2);
  color: var(--bad-faction);
}

.tag-neutral {
  background: rgba(245, 158, 11, 0.2);
  color: var(--neutral-faction);
}
