:root {
  --bg: #0f0f1a;
  --accent: #0ea5e9;
  --accent2: #38bdf8;
  --text: #e0e0f0;
  --text2: #8888aa;
  --gold: #fbbf24;
  --purple: #8b5cf6;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

header {
  text-align: center;
  padding: 8px 16px 6px;
}

header h1 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 6px;
  background: linear-gradient(135deg, var(--accent2), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.name-count {
  font-size: 12px;
  color: var(--text2);
}

/* Buttons */
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
}

#flipBtn {
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: white;
  padding: 10px 24px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  transition: transform 0.15s;
  box-shadow: 0 4px 20px rgba(14, 165, 233, 0.3);
}
#flipBtn:active { transform: scale(0.95); }
#flipBtn:disabled { opacity: 0.4; cursor: default; }

.btn-pick {
  background: linear-gradient(135deg, var(--purple), #ec4899);
  color: white;
  padding: 10px 20px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  transition: transform 0.15s;
  box-shadow: 0 4px 20px rgba(139, 92, 246, 0.3);
}
.btn-pick:active { transform: scale(0.95); }
.btn-pick:disabled { opacity: 0.4; cursor: default; }

.btn-icon {
  background: rgba(255,255,255,0.08);
  color: var(--text2);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 14px;
  transition: background 0.2s;
}
.btn-icon:hover { background: rgba(255,255,255,0.14); }

/* Config panel */
.config-panel {
  max-width: 400px;
  margin: 8px auto;
  padding: 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
}
.config-panel label {
  display: block;
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 6px;
}
.config-panel textarea {
  width: 100%;
  background: rgba(0,0,0,0.3);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}
.config-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.btn-save {
  background: var(--accent);
  color: white;
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
}
.btn-reset {
  background: rgba(255,255,255,0.08);
  color: var(--text2);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
}
.btn-clear {
  background: rgba(239,68,68,0.15);
  color: #f87171;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-left: auto;
}

/* Slot machine display */
.slot-display {
  text-align: center;
  padding: 10px;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.slot-name {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  transition: color 0.3s;
  font-variant-numeric: tabular-nums;
}
.slot-name.winner {
  color: var(--gold);
  text-shadow: 0 0 20px rgba(251, 191, 36, 0.4);
  animation: popIn 0.4s ease;
}
@keyframes popIn {
  0% { transform: scale(1.4); }
  50% { transform: scale(0.95); }
  100% { transform: scale(1); }
}

/* Grid */
#grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  padding: 6px 12px;
  max-width: 1100px;
  margin: 0 auto;
}

@media (max-width: 600px) {
  #grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 10px;
    max-width: 500px;
  }
  header { padding: 14px 16px 10px; }
  header h1 { font-size: 22px; margin-bottom: 8px; }
  #flipBtn { padding: 12px 28px; font-size: 17px; }
  .btn-pick { padding: 12px 20px; font-size: 17px; }
}

/* Cards */
.card {
  aspect-ratio: 4 / 5;
  perspective: 800px;
  cursor: default;
}
@media (max-width: 600px) {
  .card { aspect-ratio: 3 / 4; }
}

.card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transition: transform 0.6s ease;
  transform-style: preserve-3d;
}
.card.flipped .card-inner { transform: rotateY(180deg); }
.card.flipping .card-inner { animation: popFlip 0.7s ease; }

@keyframes popFlip {
  0% { transform: rotateY(0deg) scale(1); }
  30% { transform: rotateY(90deg) scale(1.08); }
  100% { transform: rotateY(180deg) scale(1); }
}

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
}
.card-back {
  background: linear-gradient(145deg, #1e2a4a, #162040);
  border: 2px solid #2a3a5e;
}
.card-back::after { content: '❄️'; font-size: 20px; opacity: 0.5; }

.card-front {
  background: linear-gradient(145deg, #1a1a3e, #0f1629);
  border: 2px solid var(--accent);
  transform: rotateY(180deg);
  text-align: center;
  font-size: 11px;
  line-height: 1.25;
  color: var(--text);
  box-shadow: 0 0 15px rgba(14, 165, 233, 0.15);
  overflow: hidden;
}
@media (min-width: 800px) { .card-front { font-size: 12px; } }
@media (max-width: 600px) { .card-front { font-size: 12px; line-height: 1.3; } }

.card.highlight { z-index: 10; }
.card.highlight .card-front {
  border-color: var(--gold);
  box-shadow: 0 0 25px rgba(251, 191, 36, 0.3);
}

/* Card modal */
.card-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.3s;
  cursor: pointer;
}
.card-modal.active { opacity: 1; }

.modal-content {
  background: linear-gradient(145deg, #1a1a3e, #0f1629);
  border: 3px solid var(--accent);
  border-radius: 20px;
  padding: 36px 32px;
  max-width: 500px;
  width: 90%;
  text-align: center;
  animation: modalPop 0.4s ease;
  box-shadow: 0 0 60px rgba(14, 165, 233, 0.2);
}
@keyframes modalPop {
  0% { transform: scale(0.5); opacity: 0; }
  70% { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}

.modal-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--gold);
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: 2px;
}
.modal-question {
  font-size: 22px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text);
}
.modal-hint {
  margin-top: 20px;
  font-size: 12px;
  color: var(--text2);
}

/* Done */
.done {
  text-align: center;
  padding: 16px;
  font-size: 18px;
  color: var(--gold);
}
.done button {
  margin-top: 8px;
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 24px;
  border-radius: 10px;
  font-size: 16px;
  cursor: pointer;
}

.hidden { display: none; }
