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

:root {
  --bg:           #060f08;
  --surface:      #0a1a0d;
  --surface-alt:  #0c1f10;
  --border:       rgba(255, 255, 255, 0.07);
  --text:         #e2f0e6;
  --muted:        #4a6b52;
  --accent:       #22c55e;
  --accent-glow:  rgba(34, 197, 94, 0.3);
  --gold:         #f59e0b;
  --gold-glow:    rgba(245, 158, 11, 0.28);
  --red:          #f87171;
  --red-glow:     rgba(248, 113, 113, 0.28);
  --green:        #4ade80;
  --green-glow:   rgba(74, 222, 128, 0.28);
  --purple:       #c084fc;
  --purple-glow:  rgba(192, 132, 252, 0.28);
}

/* ── Base ────────────────────────────────────────────────────── */

body {
  min-height: 100vh;
  background: radial-gradient(ellipse at 50% -10%, #0d3018 0%, #060f08 60%);
  font-family: 'Inter', sans-serif;
  color: var(--text);
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 860px;
  padding: 2.5rem 1.25rem 4rem;
}

/* ── Header ──────────────────────────────────────────────────── */

header {
  text-align: center;
  margin-bottom: 2.5rem;
}

h1 {
  font-size: clamp(1.9rem, 5vw, 3rem);
  font-weight: 900;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #86efac 0%, #4ade80 45%, #16a34a 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  margin-top: 0.4rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--muted);
}

/* ── Game Table ──────────────────────────────────────────────── */

#game-table {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

/* ── Opponents Row ───────────────────────────────────────────── */

#opponents {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  width: 100%;
}

/* ── Player Areas ────────────────────────────────────────────── */

.player-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
  padding: 1.1rem 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  transition: border-color 0.22s ease, box-shadow 0.22s ease, opacity 0.25s ease;
}

.player-area.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 28px var(--accent-glow);
}

.player-area.inactive {
  opacity: 0.3;
  pointer-events: none;
}

.player-area.human {
  width: min(320px, 100%);
  padding: 1.1rem 1.75rem 1.25rem;
  background: var(--surface-alt);
  border-radius: 18px;
}

.player-name {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--muted);
}

/* ── Score ───────────────────────────────────────────────────── */

.score {
  font-size: 1.35rem;
  font-weight: 800;
  min-height: 1.7rem;
  line-height: 1;
}

.score.large { font-size: 2rem; }

/* ── Badge ───────────────────────────────────────────────────── */

.badge {
  height: 1.5rem;
  min-width: 1rem;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0 0.75rem;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.badge.win {
  background: rgba(245, 158, 11, 0.14);
  color: var(--gold);
  border: 1px solid rgba(245, 158, 11, 0.4);
  box-shadow: 0 0 12px var(--gold-glow);
}

.badge.lost {
  background: rgba(74, 107, 82, 0.1);
  color: var(--muted);
  border: 1px solid rgba(74, 107, 82, 0.3);
}

.badge.bust {
  background: rgba(248, 113, 113, 0.1);
  color: var(--red);
  border: 1px solid rgba(248, 113, 113, 0.35);
}

/* ── Card Slot ───────────────────────────────────────────────── */

.card-slot {
  width: 72px;
  height: 100px;
}

/* ── Playing Card ────────────────────────────────────────────── */

.playing-card {
  width: 72px;
  height: 100px;
  background: #ffffff;
  border-radius: 8px;
  padding: 5px 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  user-select: none;
  animation: cardIn 0.22s ease-out;
}

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

.playing-card.red   { color: #dc2626; }
.playing-card.black { color: #111827; }

.card-corner {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
}

.card-corner.br {
  transform: rotate(180deg);
  align-self: flex-end;
}

.card-rank    { font-size: 0.9rem;  font-weight: 800; }
.card-suit-sm { font-size: 0.72rem; }

.card-center-big {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.9rem;
  pointer-events: none;
}

/* ── Card Back ───────────────────────────────────────────────── */

.card-back {
  width: 72px;
  height: 100px;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  background: linear-gradient(150deg, #14532d 0%, #052e16 100%);
  position: relative;
  overflow: hidden;
  animation: cardIn 0.22s ease-out;
}

.card-back::after {
  content: '';
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 4px;
  background: repeating-linear-gradient(
    45deg, transparent, transparent 5px,
    rgba(255, 255, 255, 0.04) 5px, rgba(255, 255, 255, 0.04) 10px
  );
}

/* ── Card Empty ──────────────────────────────────────────────── */

.card-empty {
  width: 72px;
  height: 100px;
  border-radius: 8px;
  border: 2px dashed rgba(255, 255, 255, 0.09);
}

/* ── Center Zone ─────────────────────────────────────────────── */

#center-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
  padding: 1.75rem 2.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  width: 100%;
}

/* ── Dice ────────────────────────────────────────────────────── */

#dice-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

#dice-scene {
  width: 84px;
  height: 84px;
  perspective: 420px;
  perspective-origin: 50% 50%;
  filter: drop-shadow(0 14px 22px rgba(0, 0, 0, 0.7));
}

#dice-cube {
  width: 84px;
  height: 84px;
  position: relative;
  transform-style: preserve-3d;
  transform: rotateX(-15deg) rotateY(20deg);
}

.face {
  position: absolute;
  inset: 0;
  background: #f8fafc;
  border-radius: 10px;
  border: 1.5px solid #94a3b8;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 11px;
  gap: 5px;
  backface-visibility: hidden;
}

.face .dot {
  background: #1e293b;
  border-radius: 50%;
  width: 100%;
  height: 100%;
}

.face-1 { transform: translateZ(42px); }
.face-2 { transform: rotateY(90deg)   translateZ(42px); }
.face-3 { transform: rotateX(90deg)   translateZ(42px); }
.face-4 { transform: rotateX(-90deg)  translateZ(42px); }
.face-5 { transform: rotateY(-90deg)  translateZ(42px); }
.face-6 { transform: rotateY(180deg)  translateZ(42px); }

#die-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

/* ── Message Box ─────────────────────────────────────────────── */

#message-box {
  min-height: 2.2rem;
  font-size: 1.55rem;
  font-weight: 900;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
}

#message-box.perfect { color: var(--green);  text-shadow: 0 0 28px var(--green-glow);  }
#message-box.bust    { color: var(--red);    text-shadow: 0 0 28px var(--red-glow);    }
#message-box.win     { color: var(--gold);   text-shadow: 0 0 28px var(--gold-glow);   }
#message-box.headsup { color: var(--purple); text-shadow: 0 0 28px var(--purple-glow); }
#message-box.neutral { color: var(--text);   }

/* ── Buttons ─────────────────────────────────────────────────── */

#controls {
  display: flex;
  gap: 0.75rem;
}

.btn {
  padding: 0.65rem 2.1rem;
  border: none;
  border-radius: 10px;
  font-family: 'Inter', sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s, background 0.15s;
}

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

.btn.primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 16px rgba(34, 197, 94, 0.4);
}

.btn.primary:hover {
  background: #4ade80;
  box-shadow: 0 4px 22px rgba(34, 197, 94, 0.55);
}

.btn.secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.btn.secondary:hover { background: rgba(255, 255, 255, 0.11); }

.hidden { display: none !important; }

/* ── Scratch Card Overlay ────────────────────────────────────── */

#scratch-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

#scratch-card {
  width: min(440px, 100%);
  background: linear-gradient(160deg, #fef08a 0%, #fbbf24 55%, #f97316 100%);
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.75);
  animation: cardPopIn 0.38s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  flex-direction: column;
  gap: 0;
}

@keyframes cardPopIn {
  from { transform: scale(0.72) translateY(24px); opacity: 0; }
  to   { transform: scale(1)    translateY(0);    opacity: 1; }
}

/* Header */
#scratch-header {
  background: #7c2d12;
  padding: 1.1rem 1.5rem 1rem;
  text-align: center;
  color: white;
}

.scratch-logo  { font-size: 1.7rem; line-height: 1; margin-bottom: 0.2rem; }
.scratch-title { font-size: 1.25rem; font-weight: 900; letter-spacing: -0.02em; }
.scratch-sub   { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.12em; opacity: 0.65; margin-top: 0.15rem; }

/* Instructions */
.scratch-instructions {
  font-size: 0.73rem;
  font-weight: 600;
  text-align: center;
  color: #7c2d12;
  padding: 0.65rem 1.5rem 0.1rem;
  line-height: 1.5;
}

/* Grid */
#scratch-grid {
  padding: 0.75rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.scratch-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.45rem;
  padding: 0.4rem 0.5rem;
  background: rgba(124, 45, 18, 0.12);
  border-radius: 10px;
  border: 1.5px solid transparent;
  transition: border-color 0.3s, box-shadow 0.3s, background 0.3s;
}

.scratch-row.winning-row {
  background: rgba(245, 158, 11, 0.22);
  border-color: #f59e0b;
  box-shadow: 0 0 16px rgba(245, 158, 11, 0.4);
  animation: rowPulse 0.55s ease-out;
}

@keyframes rowPulse {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.03); }
  100% { transform: scale(1); }
}

/* Cells */
.scratch-cell {
  aspect-ratio: 1;
  background: white;
  border-radius: 8px;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(124, 45, 18, 0.18);
  transition: border-color 0.15s;
}

.scratch-cell:hover:not(.revealed) { border-color: #7c2d12; }

.scratch-symbol {
  font-size: clamp(1.25rem, 5vw, 1.9rem);
  line-height: 1;
  user-select: none;
}

/* Scratch-off cover */
.scratch-cover {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, #9ca3af 0%, #6b7280 45%, #94a3b8 100%);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.3);
  transition: transform 0.32s cubic-bezier(0.34, 1.4, 0.64, 1), opacity 0.25s ease;
}

.scratch-cell.revealed .scratch-cover {
  transform: scale(0.05) rotate(40deg);
  opacity: 0;
  pointer-events: none;
}

/* Result */
#scratch-result {
  margin: 0 1.1rem;
  padding: 0.85rem 1rem;
  border-radius: 10px;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1.45;
  animation: fadeInUp 0.4s ease;
}

#scratch-result.won {
  background: #052e16;
  color: #4ade80;
  border: 2px solid #22c55e;
}

#scratch-result.lost {
  background: #3b0a0a;
  color: #f87171;
  border: 2px solid #ef4444;
}

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

/* Scratch Buttons */
#scratch-actions {
  padding: 0.75rem 1.1rem 1.25rem;
  display: flex;
  justify-content: center;
  gap: 0.75rem;
}

.scratch-btn {
  background: #7c2d12;
  color: white;
  box-shadow: 0 4px 12px rgba(124, 45, 18, 0.45);
}

.scratch-btn:hover {
  background: #9a3412;
  box-shadow: 0 4px 18px rgba(124, 45, 18, 0.6);
}

/* ── Responsive ──────────────────────────────────────────────── */

@media (max-width: 560px) {
  #opponents { gap: 0.5rem; }
  .player-area { padding: 0.75rem 0.4rem; border-radius: 12px; }
  .card-slot, .playing-card, .card-back, .card-empty { width: 56px; height: 78px; }
  .card-rank       { font-size: 0.75rem; }
  .card-center-big { font-size: 1.5rem; }
  .card-back       { width: 56px; height: 78px; }
  .score           { font-size: 1.1rem; }
  .score.large     { font-size: 1.5rem; }
  h1               { font-size: 1.65rem; }
  #message-box     { font-size: 1.2rem; }
  #center-zone     { padding: 1.25rem 1rem; }
  .btn             { padding: 0.6rem 1.4rem; font-size: 0.88rem; }
}
