:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #e0e7ff;
  --secondary: #0ea5e9;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --border-focus: #818cf8;
  --radius: 12px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.04);
  --shadow-lg: 0 12px 24px -4px rgba(0,0,0,0.12), 0 8px 12px -6px rgba(0,0,0,0.08);
  --shadow-xl: 0 20px 30px -6px rgba(0,0,0,0.2);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
}

.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: relative;
}

/* Header */
.app-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  z-index: 10;
  flex-wrap: wrap;
  gap: 1rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.85rem;
  background: #f1f5f9;
  color: #334155;
  border-radius: 8px;
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 600;
  border: 1px solid #cbd5e1;
  transition: all 0.2s ease;
}

.btn-back:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.header-icon {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

.header-left h1 {
  font-size: 1.25rem;
  font-weight: 800;
  color: #1e1b4b;
}

.header-left .subtitle {
  font-size: 0.825rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.85rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #334155;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.85rem;
  background: var(--primary-light);
  border: 1px solid #c7d2fe;
  color: var(--primary);
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-action:hover {
  background: #c7d2fe;
}

/* Main Layout */
.main-content {
  flex: 1;
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 1.5rem;
  padding: 1.5rem;
  max-width: 1440px;
  margin: 0 auto;
  width: 100%;
}

@media (max-width: 960px) {
  .main-content {
    grid-template-columns: 1fr;
  }
}

/* Sidebar panel */
.sidebar-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-header h3 {
  font-size: 1rem;
  font-weight: 700;
  color: #1e293b;
}

.panel-header-buttons {
  display: flex;
  gap: 0.4rem;
}

.btn-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #f8fafc;
  color: #475569;
  cursor: pointer;
}

.btn-badge:hover {
  background: #f1f5f9;
  color: #1e293b;
}

.btn-badge-danger {
  color: #dc2626;
  border-color: #fecaca;
  background: #fef2f2;
}

.btn-badge-danger:hover {
  background: #fee2e2;
}

.textarea-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.textarea-wrapper label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

textarea#names-input {
  width: 100%;
  height: 200px;
  padding: 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.875rem;
  line-height: 1.5;
  resize: vertical;
  background: #ffffff;
  color: var(--text-main);
  outline: none;
  transition: border-color 0.2s;
}

textarea#names-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.options-group {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.toggle-control {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  font-size: 0.825rem;
  font-weight: 500;
  user-select: none;
}

.toggle-control input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

.spin-duration-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.spin-duration-control label {
  font-size: 0.825rem;
  font-weight: 600;
  color: #475569;
}

.spin-duration-control select {
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 0.825rem;
  outline: none;
  background: #f8fafc;
  cursor: pointer;
}

.history-section {
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.history-header h4 {
  font-size: 0.85rem;
  font-weight: 700;
  color: #334155;
}

.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.btn-link:hover {
  text-decoration: underline;
}

.history-list {
  list-style: none;
  max-height: 160px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.6rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #1e293b;
}

.history-item .order-badge {
  display: inline-block;
  width: 20px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  border-radius: 50%;
  background: #e2e8f0;
  color: #475569;
  font-size: 0.7rem;
  margin-right: 0.4rem;
}

.empty-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
  padding: 0.5rem 0;
}

/* Wheel Panel */
.wheel-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.wheel-container-wrapper {
  position: relative;
  width: 100%;
  max-width: 580px;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wheel-stage {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

canvas#wheel-canvas {
  width: 100%;
  height: 100%;
  max-width: 560px;
  max-height: 560px;
  border-radius: 50%;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15), 0 0 0 8px #ffffff, 0 0 0 12px #e2e8f0;
  background: #ffffff;
  display: block;
}

/* Pointer Indicator (Mũi tên chỉ ô) */
.wheel-pointer {
  position: absolute;
  right: -14px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 15;
  filter: drop-shadow(-3px 2px 4px rgba(0, 0, 0, 0.3));
}

.pointer-arrow {
  width: 0;
  height: 0;
  border-top: 18px solid transparent;
  border-bottom: 18px solid transparent;
  border-right: 44px solid #ef4444;
}

/* Center spin button */
.center-spin-btn {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  border: 5px solid #ffffff;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  font-weight: 900;
  font-size: 1.05rem;
  color: #78350f;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  user-select: none;
}

.center-spin-btn:hover {
  transform: translate(-50%, -50%) scale(1.08);
  box-shadow: 0 6px 20px rgba(245, 158, 11, 0.4);
}

.center-spin-btn:active {
  transform: translate(-50%, -50%) scale(0.95);
}

.center-spin-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: translate(-50%, -50%);
}

/* Control buttons bar */
.wheel-controls-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-primary-big {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.85rem 2rem;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: #ffffff;
  font-size: 1.1rem;
  font-weight: 800;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.35);
  transition: all 0.2s ease;
  user-select: none;
}

.btn-primary-big:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 22px rgba(79, 70, 229, 0.45);
}

.btn-primary-big:active {
  transform: translateY(1px);
}

.btn-primary-big:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-secondary-big {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.85rem 1.4rem;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #334155;
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-secondary-big:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.btn-secondary-big:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Modal Popup chúc mừng */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  padding: 1.5rem;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: #ffffff;
  border-radius: 20px;
  width: 100%;
  max-width: 480px;
  padding: 2.5rem 2rem;
  text-align: center;
  box-shadow: var(--shadow-xl);
  transform: scale(0.85);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  border: 4px solid #fef08a;
  position: relative;
  overflow: hidden;
}

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

.celebration-badge {
  display: inline-block;
  background: #fef08a;
  color: #854d0e;
  font-size: 0.9rem;
  font-weight: 800;
  padding: 0.4rem 1.2rem;
  border-radius: 50px;
  letter-spacing: 1px;
  margin-bottom: 1rem;
}

.winner-title {
  font-size: 1.1rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.winner-name {
  font-size: 2.25rem;
  font-weight: 900;
  color: #4f46e5;
  margin-bottom: 1.8rem;
  line-height: 1.2;
  word-break: break-word;
  text-shadow: 0 2px 4px rgba(79, 70, 229, 0.15);
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.btn-modal-remove {
  width: 100%;
  padding: 0.85rem;
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #ffffff;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-modal-remove:hover {
  opacity: 0.92;
}

.btn-modal-keep {
  width: 100%;
  padding: 0.85rem;
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-modal-keep:hover {
  opacity: 0.92;
}

.btn-modal-close {
  width: 100%;
  padding: 0.75rem;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #475569;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-modal-close:hover {
  background: #e2e8f0;
}

/* Canvas Confetti */
canvas#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 998;
}

/* Animations */
@keyframes pulseButton {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}
