/* === CSS Variables === */
:root {
  --bg-start: #667eea;
  --bg-end: #764ba2;
  --card-bg: #ffffff;
  --card-radius: 16px;
  --card-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  --primary: #667eea;
  --primary-hover: #5a6fd6;
  --primary-light: rgba(102, 126, 234, 0.1);
  --danger: #ff6b6b;
  --danger-hover: #ee5a5a;
  --text-primary: #2d3436;
  --text-secondary: #636e72;
  --border: #e2e8f0;
  --bg-light: #f7f8fc;
  --transition-fast: 0.2s ease;
  --transition-normal: 0.3s ease;
}

/* === Reset === */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* === Body & App === */
body {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--bg-start), var(--bg-end));
  font-family: -apple-system, 'PingFang SC', 'Microsoft YaHei', 'Segoe UI', sans-serif;
  color: var(--text-primary);
  line-height: 1.6;
}

.app-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px 48px;
}

/* === Header === */
.app-header {
  text-align: center;
  margin-bottom: 36px;
  color: #fff;
}

.app-header h1 {
  font-size: 36px;
  font-weight: 700;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.app-header .subtitle {
  font-size: 16px;
  opacity: 0.85;
  margin-top: 6px;
}

/* === Main Layout === */
.main-layout {
  display: flex;
  gap: 36px;
  align-items: flex-start;
}

/* === Wheel Section === */
.wheel-section {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.wheel-container {
  position: relative;
  width: 400px;
  height: 400px;
}

#wheelCanvas {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  box-shadow: 0 0 0 8px rgba(255, 255, 255, 0.3), 0 8px 32px rgba(0, 0, 0, 0.2);
}

.pointer {
  position: absolute;
  top: -14px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 16px solid transparent;
  border-right: 16px solid transparent;
  border-top: 32px solid var(--danger);
  z-index: 10;
  filter: drop-shadow(0 3px 6px rgba(255, 107, 107, 0.5));
}

.pointer::after {
  content: '';
  position: absolute;
  top: -38px;
  left: -8px;
  width: 16px;
  height: 16px;
  background: var(--danger);
  border-radius: 50%;
}

#spinBtn {
  width: 200px;
  height: 52px;
  border-radius: 26px;
  background: linear-gradient(135deg, var(--primary), #764ba2);
  color: #fff;
  font-size: 18px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(102, 126, 234, 0.45);
  transition: all var(--transition-fast);
  letter-spacing: 2px;
}

#spinBtn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(102, 126, 234, 0.55);
}

#spinBtn:active:not(:disabled) {
  transform: translateY(0);
}

#spinBtn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.spin-hint {
  color: rgba(255, 255, 255, 0.7);
  font-size: 13px;
  text-align: center;
}

/* === Controls Section === */
.controls-section {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* === Card === */
.card {
  background: var(--card-bg);
  border-radius: var(--card-radius);
  padding: 24px;
  box-shadow: var(--card-shadow);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.card-header h2 {
  font-size: 18px;
  font-weight: 600;
}

/* === Buttons === */
.btn-primary {
  height: 42px;
  padding: 0 22px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

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

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-sm {
  height: 34px;
  padding: 0 16px;
  font-size: 13px;
}

.btn-text {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background var(--transition-fast);
}

.btn-text:hover {
  background: var(--primary-light);
}

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

.btn-danger:hover {
  background: rgba(255, 107, 107, 0.1);
}

/* === Input Group === */
.input-group {
  display: flex;
  gap: 8px;
}

#optionInput {
  flex: 1;
  height: 42px;
  border-radius: 10px;
  border: 2px solid var(--border);
  padding: 0 14px;
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition-fast);
  color: var(--text-primary);
}

#optionInput:focus {
  border-color: var(--primary);
}

#optionInput::placeholder {
  color: #b2bec3;
}

/* === Batch Group === */
.batch-group {
  margin-top: 10px;
}

.batch-content {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#batchInput {
  width: 100%;
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  resize: vertical;
  transition: border-color var(--transition-fast);
  color: var(--text-primary);
}

#batchInput:focus {
  border-color: var(--primary);
}

#batchInput::placeholder {
  color: #b2bec3;
}

/* === Options Count === */
.options-count {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 12px;
  margin-bottom: 4px;
}

/* === Options List === */
.options-list {
  list-style: none;
  max-height: 360px;
  overflow-y: auto;
}

.options-list::-webkit-scrollbar {
  width: 5px;
}

.options-list::-webkit-scrollbar-thumb {
  background: #ddd;
  border-radius: 3px;
}

.options-empty {
  text-align: center;
  color: var(--text-secondary);
  padding: 24px 0;
  font-size: 14px;
}

.option-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg-light);
  margin-bottom: 8px;
  gap: 10px;
  transition: all var(--transition-fast);
  animation: fadeInUp 0.3s ease;
}

.option-item:hover {
  background: #eef0f8;
}

.option-item.removing {
  animation: fadeOut 0.25s ease forwards;
}

.option-color {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.option-name {
  flex: 1;
  font-size: 14px;
  cursor: default;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  padding: 2px 4px;
  border-radius: 4px;
  transition: background var(--transition-fast);
}

.option-name[contenteditable="true"] {
  background: #fff;
  outline: 2px solid var(--primary);
  cursor: text;
}

.option-weight {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.option-weight input {
  width: 48px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-align: center;
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition-fast);
}

.option-weight input:focus {
  border-color: var(--primary);
}

.option-delete {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: 18px;
  flex-shrink: 0;
  border: none;
  background: none;
  line-height: 1;
}

.option-delete:hover {
  color: var(--danger);
  background: rgba(255, 107, 107, 0.12);
}

/* === History === */
.history-list {
  list-style: none;
  max-height: 240px;
  overflow-y: auto;
}

.history-empty {
  text-align: center;
  color: var(--text-secondary);
  padding: 20px 0;
  font-size: 14px;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  animation: fadeInUp 0.3s ease;
}

.history-item:last-child {
  border-bottom: none;
}

.history-name {
  font-weight: 500;
}

.history-time {
  color: var(--text-secondary);
  font-size: 12px;
  flex-shrink: 0;
  margin-left: 12px;
}

/* === Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-normal), visibility var(--transition-normal);
  backdrop-filter: blur(4px);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background: #fff;
  border-radius: 24px;
  padding: 48px 40px;
  text-align: center;
  transform: scale(0.75);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 380px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

.modal-overlay.active .modal-content {
  transform: scale(1);
}

.modal-icon {
  font-size: 56px;
  margin-bottom: 12px;
  animation: bounce 0.6s ease;
}

.modal-content h2 {
  font-size: 22px;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.result-text {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
  margin: 12px 0 28px;
  word-break: break-all;
}

.btn-modal {
  width: 140px;
  height: 46px;
  font-size: 16px;
  border-radius: 23px;
}

/* === Confetti Canvas === */
#confettiCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 999;
  display: none;
}

/* === Toast === */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(45, 52, 54, 0.9);
  color: #fff;
  padding: 10px 28px;
  border-radius: 24px;
  font-size: 14px;
  z-index: 2000;
  opacity: 0;
  transition: all var(--transition-normal);
  pointer-events: none;
  white-space: nowrap;
}

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

/* === Animations === */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-8px);
  }
}

@keyframes bounce {
  0% { transform: scale(0); }
  50% { transform: scale(1.2); }
  70% { transform: scale(0.95); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

.shake {
  animation: shake 0.4s ease;
}

/* === Responsive === */
@media (max-width: 850px) {
  .main-layout {
    flex-direction: column;
    align-items: center;
  }

  .wheel-section {
    width: 100%;
  }

  .controls-section {
    width: 100%;
  }

  .wheel-container {
    width: 340px;
    height: 340px;
    margin: 0 auto;
  }

  .app-header h1 {
    font-size: 28px;
  }
}

@media (max-width: 480px) {
  .app-container {
    padding: 20px 12px 32px;
  }

  .wheel-container {
    width: 280px;
    height: 280px;
  }

  #spinBtn {
    width: 170px;
    height: 46px;
    font-size: 16px;
  }

  .card {
    padding: 18px;
  }

  .app-header h1 {
    font-size: 24px;
  }

  .result-text {
    font-size: 26px;
  }
}
