/* Lucky Draw — tối ưu touch màn LED standee ~49" */
:root {
  --bg-deep: #0b1220;
  --panel-bg: #ffffff;
  --panel-border: #e8edf5;
  --text: #1a2332;
  --text-muted: #6b7a90;
  --accent: #2563eb;
  --danger: #e11d48;
  --spin-red: #e53935;
  --rim: #f59e0b;
  --rim-light: #fde047;
  --seg-1: #ef4444;
  --seg-2: #3b82f6;
  --seg-3: #22c55e;
  --seg-4: #f97316;
  --touch-min: 56px;
  --radius: 16px;
  --font: "Be Vietnam Pro", "Segoe UI", sans-serif;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-deep);
  touch-action: manipulation;
  user-select: none;
}

button,
input {
  font-family: inherit;
}

.app {
  display: grid;
  grid-template-columns: 1fr min(420px, 34vw);
  height: 100%;
  width: 100%;
}

/* ===== Stage / Wheel ===== */
.stage {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  min-height: 0;
}

.stage-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 70% at 50% 45%, rgba(59, 130, 246, 0.25), transparent 60%),
    radial-gradient(ellipse 50% 40% at 20% 80%, rgba(239, 68, 68, 0.2), transparent 50%),
    radial-gradient(ellipse 50% 40% at 80% 20%, rgba(34, 197, 94, 0.18), transparent 50%),
    linear-gradient(160deg, #0f172a 0%, #1e293b 45%, #0f172a 100%);
}

.stage-bg::before {
  content: "";
  position: absolute;
  inset: -20%;
  background:
    repeating-conic-gradient(
      from 0deg at 50% 50%,
      transparent 0deg 8deg,
      rgba(255, 255, 255, 0.03) 8deg 9deg
    );
  opacity: 0.7;
  animation: bg-spin 120s linear infinite;
}

@keyframes bg-spin {
  to { transform: rotate(360deg); }
}

.wheel-wrap {
  position: relative;
  width: min(78vmin, 820px);
  height: min(78vmin, 820px);
  z-index: 1;
}

#wheelCanvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 50%;
  filter: drop-shadow(0 12px 40px rgba(0, 0, 0, 0.45));
}

.pointer {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 22px solid transparent;
  border-right: 22px solid transparent;
  border-top: 48px solid #fff;
  z-index: 5;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.4));
}

.pointer::after {
  content: "";
  position: absolute;
  top: -48px;
  left: -10px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.5);
}

.spin-btn {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 6;
  width: clamp(88px, 14vmin, 128px);
  height: clamp(88px, 14vmin, 128px);
  border: 6px solid #fff;
  border-radius: 50%;
  background: linear-gradient(180deg, #ef5350, var(--spin-red) 55%, #b71c1c);
  color: #fff;
  font-size: clamp(1.25rem, 3.2vmin, 2rem);
  font-weight: 800;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow:
    0 8px 0 #8b1a18,
    0 14px 28px rgba(0, 0, 0, 0.4),
    inset 0 2px 0 rgba(255, 255, 255, 0.35);
  transition: transform 0.12s ease, filter 0.12s ease;
}

.spin-btn:active:not(:disabled) {
  transform: translate(-50%, -50%) scale(0.94);
  box-shadow:
    0 3px 0 #8b1a18,
    0 8px 16px rgba(0, 0, 0, 0.35);
}

.spin-btn:disabled {
  filter: grayscale(0.35) brightness(0.9);
  cursor: not-allowed;
}

.spin-btn.spinning {
  animation: pulse-spin 0.8s ease-in-out infinite;
}

@keyframes pulse-spin {
  50% { filter: brightness(1.15); }
}

.rim-lights {
  pointer-events: none;
  position: absolute;
  inset: 0;
  border-radius: 50%;
}

.panel-toggle {
  display: none;
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 10;
  width: var(--touch-min);
  height: var(--touch-min);
  border: none;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

/* ===== Panel ===== */
.panel {
  background: var(--panel-bg);
  border-left: 1px solid var(--panel-border);
  min-height: 0;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.12);
  z-index: 20;
}

.panel-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  padding: 16px 16px 12px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.tab {
  flex: 1;
  min-height: var(--touch-min);
  border: none;
  border-radius: 12px;
  background: #f1f5f9;
  color: var(--text-muted);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s, color 0.15s;
}

.tab.active {
  background: #eff6ff;
  color: var(--accent);
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
}

.tab-pane {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.tab-pane.active {
  display: flex;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.tool-btn {
  min-height: var(--touch-min);
  border: 1.5px solid #dbe3ef;
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 4px;
  transition: background 0.15s, border-color 0.15s;
}

.tool-btn:active {
  background: #f8fafc;
}

.tool-btn.danger {
  color: var(--danger);
  border-color: #fecdd3;
}

.advanced-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  margin-bottom: 8px;
}

.advanced-row input {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}

.advanced-box {
  background: #f8fafc;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
}

.advanced-box[hidden] {
  display: none !important;
}

.field {
  margin-bottom: 10px;
}

.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.field input[type="text"] {
  width: 100%;
  min-height: 48px;
  border: 1.5px solid #dbe3ef;
  border-radius: 10px;
  padding: 0 14px;
  font-size: 1rem;
  outline: none;
  user-select: text;
}

.field input:focus {
  border-color: var(--accent);
}

.field-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  font-size: 0.92rem;
  cursor: pointer;
}

.check-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: #fff;
}

.item-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px 14px;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  font-weight: 600;
  font-size: 1.05rem;
}

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

.item-list li.selected {
  background: #eff6ff;
}

.item-list li .dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #cbd5e1;
  flex-shrink: 0;
  background: #fff;
}

.item-list li.selected .dot {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: inset 0 0 0 3px #fff;
}

.item-list li .thumb {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  background: #e2e8f0;
  flex-shrink: 0;
}

.item-list li .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-list li .stock-badge {
  flex-shrink: 0;
  min-width: 44px;
  height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 0.9rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.item-list li .stock-badge.low {
  background: #fff7ed;
  color: #c2410c;
}

.item-list li .stock-badge.empty {
  background: #ffe4e6;
  color: #be123c;
}

.field input[type="number"] {
  width: 100%;
  min-height: 48px;
  border: 1.5px solid #dbe3ef;
  border-radius: 10px;
  padding: 0 14px;
  font-size: 1.1rem;
  font-weight: 700;
  outline: none;
  user-select: text;
}

.field input[type="number"]:focus {
  border-color: var(--accent);
}

.item-list.results li {
  cursor: default;
}

.item-list.results .rank {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  font-weight: 800;
  flex-shrink: 0;
}

.empty-hint {
  text-align: center;
  color: var(--text-muted);
  padding: 32px 16px;
  margin: 0;
}

.panel-footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding-top: 12px;
}

.panel-footer:has(.btn-danger-solid:only-child) {
  grid-template-columns: 1fr;
}

.panel-footer-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 12px;
}

.panel-footer-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn-export {
  background: #0f766e;
  color: #fff;
}

.btn-import {
  background: #1d4ed8;
  color: #fff;
}

.btn-danger-solid {
  background: #e11d48;
  color: #fff;
  width: 100%;
  min-height: 60px;
  font-size: 1.1rem;
}

.btn {
  min-height: var(--touch-min);
  border: none;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  transition: transform 0.1s, filter 0.1s;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  flex: 1;
}

.btn-ghost {
  background: #e2e8f0;
  color: var(--text);
  flex: 1;
}

.btn-dark {
  background: #334155;
  color: #fff;
}

.btn-muted {
  background: #94a3b8;
  color: #fff;
}

.btn-celebrate {
  background: linear-gradient(180deg, #fbbf24, #f59e0b);
  color: #1a2332;
  min-width: 200px;
  min-height: 64px;
  font-size: 1.25rem;
  box-shadow: 0 8px 24px rgba(245, 158, 11, 0.45);
}

/* ===== Winner overlay ===== */
.winner-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: rgba(5, 10, 25, 0.72);
  backdrop-filter: blur(6px);
  padding: 24px;
}

.winner-overlay[hidden] {
  display: none !important;
}

#confettiCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.winner-card {
  position: relative;
  z-index: 2;
  width: min(720px, 92vw);
  background: #fff;
  border-radius: 28px;
  padding: clamp(24px, 4vmin, 48px);
  text-align: center;
  box-shadow: var(--shadow);
  animation: pop-in 0.55s cubic-bezier(0.22, 1.4, 0.36, 1) both;
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.55) translateY(40px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.winner-label {
  margin: 0 0 12px;
  font-size: clamp(1.1rem, 2.5vmin, 1.5rem);
  font-weight: 800;
  color: var(--spin-red);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  animation: glow-text 1.2s ease-in-out infinite alternate;
}

@keyframes glow-text {
  from { text-shadow: 0 0 0 transparent; }
  to { text-shadow: 0 0 18px rgba(229, 57, 53, 0.45); }
}

.winner-image-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1.2 / 1;
  max-height: 48vh;
  margin: 0 auto 16px;
  border-radius: 20px;
  overflow: hidden;
  background: linear-gradient(135deg, #fef3c7, #fecaca, #bfdbfe);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
}

.winner-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
  animation: image-burst 0.7s cubic-bezier(0.22, 1.3, 0.36, 1) both;
}

@keyframes image-burst {
  from {
    opacity: 0;
    transform: scale(0.4);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.winner-image-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(4rem, 12vmin, 8rem);
  font-weight: 800;
  color: #fff;
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

.winner-name {
  margin: 0 0 6px;
  font-size: clamp(1.75rem, 5vmin, 3rem);
  font-weight: 800;
  line-height: 1.2;
  color: var(--text);
}

.winner-sub {
  margin: 0 0 24px;
  color: var(--text-muted);
  font-size: 1.1rem;
}

/* ===== Responsive: portrait standee / hẹp ===== */
@media (max-width: 900px), (orientation: portrait) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }

  .panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(420px, 92vw);
    transform: translateX(105%);
    transition: transform 0.28s ease;
    border-left: none;
    border-radius: 20px 0 0 20px;
  }

  .app.panel-open .panel {
    transform: translateX(0);
  }

  .panel-toggle {
    display: grid;
    place-items: center;
  }

  .wheel-wrap {
    width: min(88vmin, 720px);
    height: min(88vmin, 720px);
  }
}

@media (min-width: 1600px) {
  .app {
    grid-template-columns: 1fr min(480px, 28vw);
  }

  .tool-btn {
    font-size: 0.9rem;
  }

  .item-list li {
    min-height: 64px;
    font-size: 1.15rem;
  }
}

/* Kiosk: ẩn panel khi quay fullscreen cảm giác sân khấu */
body.kiosk-spin .panel,
body.kiosk-spin .panel-toggle {
  opacity: 0.15;
  pointer-events: none;
}
