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

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #a5b4fc;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --card-bg: rgba(255, 255, 255, 0.95);
  --text-primary: #1f2937;
  --text-secondary: #6b7280;
  --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.15);
  --shadow-md: 0 8px 20px rgba(0, 0, 0, 0.1);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
  --radius-lg: 20px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg-gradient);
  min-height: 100vh;
  padding: 20px;
  color: var(--text-primary);
}

.container {
  max-width: 600px;
  margin: 0 auto;
}

/* Header */
.header {
  text-align: center;
  color: white;
  margin-bottom: 30px;
  padding-top: 20px;
}

.title {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 8px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.subtitle {
  font-size: 0.95rem;
  opacity: 0.85;
}

/* Main card */
.main {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 30px;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(20px);
}

/* Settings panel */
.settings-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  padding: 16px;
  background: #f9fafb;
  border-radius: var(--radius-md);
  margin-bottom: 24px;
}

.setting-item {
  display: flex;
  align-items: center;
  gap: 10px;
}

.setting-item label {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.counter {
  display: flex;
  align-items: center;
  gap: 8px;
}

.count-value {
  width: 32px;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--primary);
}

.btn-mini {
  width: 28px;
  height: 28px;
  border: none;
  background: var(--primary);
  color: white;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-mini:hover {
  background: var(--primary-dark);
  transform: scale(1.05);
}

.btn-mini:active {
  transform: scale(0.95);
}

/* Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #d1d5db;
  transition: 0.3s;
  border-radius: 26px;
}

.slider:before {
  content: "";
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

input:checked + .slider {
  background-color: var(--primary);
}

input:checked + .slider:before {
  transform: translateX(22px);
}

/* Display card */
.roll-display {
  margin-bottom: 24px;
}

.display-card {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: var(--radius-lg);
  padding: 50px 30px;
  text-align: center;
  color: white;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  box-shadow: var(--shadow-lg);
  transition: transform 0.3s;
  position: relative;
  overflow: hidden;
}

.display-card::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
  pointer-events: none;
}

.display-card.rolling {
  /* 卡片不再抖动 */
}

.student-name {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: 4px;
  margin-bottom: 12px;
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.2);
  transition: all 0.2s;
}

.rolling .student-name {
  animation: nameFlicker 0.08s infinite;
}

@keyframes nameFlicker {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.student-info {
  font-size: 1rem;
  opacity: 0.9;
}

/* Controls */
.controls {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.btn-primary, .btn-danger, .btn-secondary, .btn-ghost {
  padding: 14px 28px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-danger {
  background: var(--danger);
  color: white;
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.4);
}

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

.btn-secondary {
  background: #f3f4f6;
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: #e5e7eb;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 2px solid #e5e7eb;
}

.btn-ghost:hover {
  background: #f9fafb;
  color: var(--text-primary);
}

/* Stats */
.stats-bar {
  display: flex;
  justify-content: space-around;
  padding: 16px;
  background: #f9fafb;
  border-radius: var(--radius-md);
  margin-bottom: 24px;
}

.stat {
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
}

/* History */
.history-section {
  border-top: 2px solid #f3f4f6;
  padding-top: 20px;
}

.history-title {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
  font-weight: 500;
}

.history-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 40px;
}

.empty-hint {
  width: 100%;
  text-align: center;
  color: #9ca3af;
  font-size: 0.9rem;
  padding: 20px;
}

.history-item {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  background: linear-gradient(135deg, #ede9fe 0%, #ddd6fe 100%);
  color: var(--primary-dark);
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  animation: popIn 0.3s ease-out;
}

@keyframes popIn {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Footer */
.footer {
  text-align: center;
  margin-top: 24px;
}

.feishu-link {
  color: white;
  text-decoration: none;
  opacity: 0.85;
  font-size: 0.9rem;
  transition: opacity 0.2s;
}

.feishu-link:hover {
  opacity: 1;
  text-decoration: underline;
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  animation: fadeIn 0.3s;
}

.modal-overlay.active {
  display: flex;
}

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

.modal-content {
  background: white;
  border-radius: var(--radius-lg);
  padding: 40px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  animation: slideUp 0.4s ease-out;
}

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

.modal-animation {
  font-size: 4rem;
  margin-bottom: 16px;
  animation: bounce 0.6s ease-out;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-20px); }
}

.modal-title {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.modal-names {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 24px;
  line-height: 1.6;
}

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

/* Responsive */
@media (max-width: 480px) {
  body {
    padding: 12px;
  }

  .title {
    font-size: 1.5rem;
  }

  .main {
    padding: 20px;
  }

  .student-name {
    font-size: 2rem;
  }

  .btn-primary, .btn-danger, .btn-secondary, .btn-ghost {
    padding: 12px 20px;
    font-size: 0.95rem;
  }

  .settings-panel {
    flex-direction: column;
    align-items: stretch;
  }
}

/* ===== 管理模式样式 ===== */
.btn-manage {
  background: #ede9fe;
  color: var(--primary-dark);
}

.btn-manage:hover {
  background: #ddd6fe;
}

.manage-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 2px solid #f3f4f6;
}

.btn-back {
  font-size: 0.9rem;
  padding: 8px 16px;
}

.manage-tip {
  font-size: 0.8rem;
  color: #10b981;
  background: #d1fae5;
  padding: 4px 12px;
  border-radius: 12px;
}

.add-form {
  background: #f9fafb;
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 24px;
}

.form-title {
  font-size: 1rem;
  color: var(--text-primary);
  margin-bottom: 16px;
  font-weight: 600;
}

.form-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.form-input {
  padding: 10px 14px;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.2s;
  flex: 1;
  min-width: 0;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary);
}

.form-select {
  flex: none;
  width: 80px;
}

.btn-add {
  flex: none;
  padding: 10px 20px;
  white-space: nowrap;
}

.student-list-section {
  margin-bottom: 16px;
}

.student-table-wrap {
  border: 1px solid #e5e7eb;
  border-radius: var(--radius-md);
  overflow: hidden;
  max-height: 400px;
  overflow-y: auto;
}

.student-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.student-table thead {
  background: #f3f4f6;
  position: sticky;
  top: 0;
  z-index: 1;
}

.student-table th,
.student-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid #f3f4f6;
}

.student-table th {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.student-table tbody tr {
  transition: background 0.15s;
}

.student-table tbody tr:hover {
  background: #f9fafb;
}

.student-table input,
.student-table select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  background: transparent;
}

.student-table input:focus,
.student-table select:focus {
  outline: none;
  border-color: var(--primary);
  background: white;
}

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

.btn-row {
  padding: 4px 10px;
  border: none;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

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

.btn-save:hover {
  background: var(--primary-dark);
}

.btn-edit {
  background: #dbeafe;
  color: #1d4ed8;
}

.btn-edit:hover {
  background: #bfdbfe;
}

.btn-delete {
  background: #fee2e2;
  color: #dc2626;
}

.btn-delete:hover {
  background: #fecaca;
}

.btn-cancel {
  background: #f3f4f6;
  color: var(--text-secondary);
}

.btn-cancel:hover {
  background: #e5e7eb;
}

/* Toast */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: #1f2937;
  color: white;
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 0.9rem;
  z-index: 2000;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.success {
  background: #10b981;
}

.toast.error {
  background: #ef4444;
}

/* 编辑态行 */
tr.editing {
  background: #fef3c7 !important;
}

tr.editing input,
tr.editing select {
  background: white;
  border-color: #f59e0b;
}

@media (max-width: 480px) {
  .form-row {
    flex-wrap: wrap;
  }
  .form-input {
    min-width: 120px;
  }
  .btn-add {
    width: 100%;
  }
  .student-table th,
  .student-table td {
    padding: 8px;
    font-size: 0.85rem;
  }
}

/* ===== 元素筛选面板 ===== */
.filter-panel {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: linear-gradient(135deg, #faf5ff 0%, #f0fdfa 100%);
  border-radius: var(--radius-md);
  margin-bottom: 20px;
  border: 1px solid #e9d5ff;
}

.filter-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 600;
  margin-right: 4px;
}

.filter-btn {
  padding: 6px 14px;
  border: 2px solid #e5e7eb;
  background: white;
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  color: var(--text-primary);
  font-weight: 500;
}

.filter-btn:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}

.filter-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

/* ===== 元素颜色主题 ===== */
/* 火象 - 橙红 */
.elem-fire {
  background: linear-gradient(135deg, #fee2e2, #ffedd5);
  color: #c2410c;
  border: 1px solid #fecaca;
}

/* 土象 - 棕黄 */
.elem-earth {
  background: linear-gradient(135deg, #fef3c7, #fef9c3);
  color: #a16207;
  border: 1px solid #fde68a;
}

/* 风象 - 青绿 */
.elem-air {
  background: linear-gradient(135deg, #d1fae5, #e0f2fe);
  color: #047857;
  border: 1px solid #a7f3d0;
}

/* 水象 - 蓝紫 */
.elem-water {
  background: linear-gradient(135deg, #e0e7ff, #ede9fe);
  color: #6d28d9;
  border: 1px solid #c7d2fe;
}

/* 元素标签 */
.elem-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
}

/* 历史记录里的元素小标签 */
.history-item .elem-tag {
  padding: 0 4px;
  font-size: 0.65rem;
  border-radius: 8px;
  margin-left: 2px;
}

/* ===== 日期输入框 ===== */
.form-date {
  flex: none;
  width: 150px;
}

/* 管理列表中星座列 */
.cell-zodiac {
  white-space: nowrap;
}
