/* ===== CSS 變數 ===== */
:root {
  --primary-color: #4f46e5;
  --primary-hover: #4338ca;
  --secondary-color: #64748b;
  --secondary-hover: #475569;
  --success-color: #10b981;
  --danger-color: #ef4444;
  --background-color: #f8fafc;
  --card-background: #ffffff;
  --text-color: #1e293b;
  --text-secondary: #64748b;
  --border-color: #e2e8f0;
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-lg:
    0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius: 0.5rem;
  --spacing: 1rem;
}

/* ===== 深色模式 ===== */
@media (prefers-color-scheme: dark) {
  :root {
    --background-color: #0f172a;
    --card-background: #1e293b;
    --text-color: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
  }
}

/* ===== 基礎樣式 ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

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

/* ===== 容器 ===== */
.container {
  max-width: 800px;
  margin: 0 auto;
  padding: var(--spacing);
  width: 100%;
}

/* ===== 標題 ===== */
header {
  text-align: center;
  padding: 2rem 0;
}

header h1 {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
  color: var(--primary-color);
}

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

/* ===== 區塊 ===== */
section {
  background: var(--card-background);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

section h2 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
  color: var(--text-color);
}

/* ===== 輸入區域 ===== */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.input-group label {
  font-weight: 500;
  color: var(--text-color);
}

textarea {
  width: 100%;
  padding: 0.75rem;
  border: 2px solid var(--border-color);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
  background: var(--card-background);
  color: var(--text-color);
  transition: border-color 0.2s;
}

textarea:focus {
  outline: none;
  border-color: var(--primary-color);
}

.input-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.participant-count {
  color: var(--text-secondary);
}

.participant-count strong {
  color: var(--primary-color);
  font-size: 1.2rem;
}

/* ===== 設定區域 ===== */
.settings-group {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1.5rem;
}

.settings-group label {
  font-weight: 500;
}

.settings-group input[type="text"],
.settings-group input[type="number"] {
  padding: 0.5rem;
  border: 2px solid var(--border-color);
  border-radius: var(--radius);
  font-size: 1rem;
  background: var(--card-background);
  color: var(--text-color);
}

.settings-group input[type="text"] {
  width: 100%;
}

.settings-group input[type="number"] {
  width: 100px;
}

.settings-group input[type="text"]:focus,
.settings-group input[type="number"]:focus {
  outline: none;
  border-color: var(--primary-color);
}

.checkbox-label {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
}

.checkbox-label input[type="checkbox"] {
  width: 1.2rem;
  height: 1.2rem;
  cursor: pointer;
}

/* ===== 按鈕 ===== */
.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

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

.btn-primary {
  background-color: var(--primary-color);
  color: white;
  width: 100%;
  font-size: 1.2rem;
  padding: 1rem;
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

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

.btn-secondary:hover:not(:disabled) {
  background-color: var(--secondary-hover);
}

/* ===== 結果顯示 ===== */
.result-display {
  min-height: 100px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.empty-state {
  color: var(--text-secondary);
  text-align: center;
  padding: 2rem;
  font-style: italic;
}

.result-title {
  padding: 1rem;
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary-color);
  margin-bottom: 0.5rem;
  animation: slideIn 0.3s ease-out;
}

.result-item {
  padding: 1rem;
  background: var(--background-color);
  border-radius: var(--radius);
  border-left: 4px solid var(--success-color);
  font-size: 1.2rem;
  font-weight: 600;
  animation: slideIn 0.3s ease-out;
}

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

.rolling-animation {
  padding: 2rem;
  text-align: center;
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary-color);
  animation: pulse 0.5s ease-in-out infinite;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.result-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
  display: none;
}

.result-actions.show {
  display: flex;
}

/* ===== 歷史記錄 ===== */
.history-list {
  max-height: 300px;
  overflow-y: auto;
  margin-bottom: 1rem;
}

.history-item {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.9rem;
}

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

.history-time {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-bottom: 0.25rem;
}

.history-winners {
  color: var(--text-color);
  font-weight: 500;
}

#history-section.hidden {
  display: none;
}

/* ===== 頁尾 ===== */
footer {
  text-align: center;
  padding: 2rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: auto;
}

footer a {
  color: var(--primary-color);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* ===== 響應式設計 ===== */
@media (max-width: 640px) {
  header h1 {
    font-size: 2rem;
  }

  .subtitle {
    font-size: 1rem;
  }

  section {
    padding: 1rem;
  }

  .settings-group {
    grid-template-columns: 1fr;
  }

  .settings-group label {
    grid-column: 1;
  }

  .settings-group input[type="number"] {
    width: 100%;
  }

  .input-info {
    flex-direction: column;
    align-items: flex-start;
  }

  .result-actions {
    flex-direction: column;
  }
}

/* ===== 無障礙性 ===== */
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none;
    transition: none;
  }
}

/* 聚焦樣式 */
*:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}
