/* ── Reset & base ────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
}

body {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  background: radial-gradient(ellipse at 50% 25%, #236b32 0%, #0f3d1a 65%, #07220f 100%);
  font-family: Georgia, 'Times New Roman', serif;
  color: #fff;
  touch-action: manipulation; /* removes 300ms tap delay on iOS */
  user-select: none;
  -webkit-user-select: none;
  overflow-x: hidden;
}

/* ── Fixed header ─────────────────────────────────────────────────────────── */
#header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  /* Extend behind notch/dynamic island */
  padding-top: env(safe-area-inset-top, 0px);
  height: calc(60px + env(safe-area-inset-top, 0px));
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding-left: 16px;
  padding-right: 16px;
  padding-bottom: 10px;
  z-index: 100;
  border-bottom: 1px solid rgba(255, 215, 0, 0.25);
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 72px;
}

.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: rgba(255, 255, 255, 0.5);
  line-height: 1;
  margin-bottom: 2px;
}

.stat-value {
  font-size: 24px;
  font-weight: bold;
  color: #ffd700;
  line-height: 1;
}

.stat-unit {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.4);
  line-height: 1;
  margin-top: 1px;
}

.header-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

#new-game-btn {
  background: transparent;
  border: 1px solid rgba(255, 215, 0, 0.6);
  color: #ffd700;
  font-family: Georgia, serif;
  font-size: 14px;
  letter-spacing: 0.5px;
  padding: 0 18px;
  min-height: 32px;
  border-radius: 6px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, border-color 0.15s;
}

#new-game-btn:active {
  background: rgba(255, 215, 0, 0.15);
  border-color: #ffd700;
}

#scores-btn {
  background: transparent;
  border: none;
  color: rgba(255, 215, 0, 0.7);
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
}

#scores-btn:active {
  color: #ffd700;
}

/* ── Main table area ──────────────────────────────────────────────────────── */
#table {
  padding-top: calc(60px + env(safe-area-inset-top, 0px));
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-bottom: 32px;
}

/* ── Game title and belt label ───────────────────────────────────────────── */
.game-title {
  font-size: 11px;
  letter-spacing: 5px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.25);
  margin-bottom: 4px;
  margin-top: 16px;
}

.belt-label {
  font-size: 12px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: rgba(255, 215, 0, 0.5);
  margin-bottom: 20px;
}

/* ── Card row (the asteroid belt) ────────────────────────────────────────── */
#card-row-wrapper {
  width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  padding: 16px 20px 28px;
  scrollbar-width: none;
}

#card-row-wrapper::-webkit-scrollbar {
  display: none;
}

#card-row {
  display: flex;
  flex-direction: row;
  gap: 10px;
  /* min-width: 100% centres cards when few; width auto expands when many */
  min-width: 100%;
  width: max-content;
  justify-content: center;
}

/* ── Belt info ───────────────────────────────────────────────────────────── */
.belt-info {
  font-size: 11px;
  letter-spacing: 1px;
  color: rgba(255, 255, 255, 0.3);
  margin-top: 4px;
  text-align: center;
  min-height: 16px;
}

/* ── Card ────────────────────────────────────────────────────────────────── */
.card {
  width: 72px;
  height: 108px;
  border-radius: 8px;
  cursor: pointer;
  perspective: 800px;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

/* Active card — the one to flip next */
.card.active {
  transform: translateY(-10px);
  animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% {
    box-shadow:
      0 0 0 2px #ffd700,
      0 0 14px rgba(255, 215, 0, 0.45),
      0 10px 24px rgba(0, 0, 0, 0.45);
  }
  50% {
    box-shadow:
      0 0 0 2px #ffd700,
      0 0 26px rgba(255, 215, 0, 0.75),
      0 10px 24px rgba(0, 0, 0, 0.45);
  }
}

/* Future face-down cards — not yet tappable */
.card:not(.face-up):not(.active) {
  opacity: 0.6;
  pointer-events: none;
  cursor: default;
  transform: none;
}

/* Already-flipped cards — no interaction */
.card.face-up {
  pointer-events: none;
  cursor: default;
  transform: none;
}

/* ── 3D flip ─────────────────────────────────────────────────────────────── */
.card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 8px;
}

.card.face-up .card-inner {
  transform: rotateY(180deg);
}

.card-front,
.card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  /* Critical for Safari — prevents ghosting during 3D transforms */
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}

/* ── Card front face ─────────────────────────────────────────────────────── */
.card-front {
  background: #ffffff;
  /* Start rotated so it's hidden; .face-up rotates card-inner to show it */
  transform: rotateY(180deg);
  position: relative;
}

.corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  gap: 1px;
}

.corner.top-left {
  top: 4px;
  left: 5px;
}

.corner.bottom-right {
  bottom: 4px;
  right: 5px;
  transform: rotate(180deg);
}

.corner .rank {
  font-size: 13px;
  font-weight: bold;
  color: #1a1a1a;
  line-height: 1;
}

.corner .suit {
  font-size: 10px;
  line-height: 1;
}

.center-pip {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.center-pip .suit {
  font-size: 32px;
  line-height: 1;
}

/* Suit colours */
.suit.hearts,
.suit.diamonds {
  color: #cc0000;
}

.suit.clubs,
.suit.spades {
  color: #1a1a1a;
}

/* ── Card back face ──────────────────────────────────────────────────────── */
.card-back {
  background-color: #1a2a6c;
  background-image:
    repeating-linear-gradient(
      45deg,
      rgba(255, 255, 255, 0.07) 0px,
      rgba(255, 255, 255, 0.07) 2px,
      transparent 2px,
      transparent 9px
    ),
    repeating-linear-gradient(
      -45deg,
      rgba(255, 255, 255, 0.07) 0px,
      rgba(255, 255, 255, 0.07) 2px,
      transparent 2px,
      transparent 9px
    );
  border: 3px solid rgba(255, 215, 0, 0.5);
  box-shadow: inset 0 0 0 2px rgba(255, 215, 0, 0.12);
}

/* ── Modal overlay (scoring card) ────────────────────────────────────────── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

#modal-box {
  background: linear-gradient(150deg, #1a1a2e 0%, #12122a 100%);
  border: 2px solid #ffd700;
  border-radius: 20px;
  padding: 36px 28px 28px;
  text-align: center;
  max-width: 320px;
  width: 100%;
  box-shadow:
    0 0 50px rgba(255, 215, 0, 0.2),
    0 20px 60px rgba(0, 0, 0, 0.6);
  animation: modal-in 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.85) translateY(20px); }
  to   { opacity: 1; transform: scale(1)    translateY(0);    }
}

#modal-message {
  font-size: 19px;
  font-weight: bold;
  color: #ffd700;
  margin-bottom: 10px;
  line-height: 1.35;
}

#modal-sub {
  font-size: 15px;
  color: rgba(255, 255, 255, 0.65);
  margin-bottom: 28px;
  line-height: 1.4;
}

#modal-confirm {
  display: block;
  width: 100%;
  min-height: 52px;
  background: #ffd700;
  color: #111;
  border: none;
  border-radius: 10px;
  font-family: Georgia, serif;
  font-size: 17px;
  font-weight: bold;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s, background 0.1s;
}

#modal-confirm:active {
  transform: scale(0.97);
  background: #e6c200;
}

/* ── Win overlay ─────────────────────────────────────────────────────────── */
#win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

#win-box {
  background: linear-gradient(150deg, #1a3a1a 0%, #0f2d0f 100%);
  border: 2px solid #ffd700;
  border-radius: 20px;
  padding: 40px 28px 32px;
  text-align: center;
  max-width: 320px;
  width: 100%;
  box-shadow:
    0 0 60px rgba(255, 215, 0, 0.3),
    0 20px 60px rgba(0, 0, 0, 0.6);
  animation: pop-in 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.7); }
  to   { opacity: 1; transform: scale(1);   }
}

#win-box h1 {
  font-size: 44px;
  color: #ffd700;
  margin-bottom: 8px;
  text-shadow: 0 0 30px rgba(255, 215, 0, 0.5);
}

.win-subtitle {
  font-size: 17px;
  color: rgba(255, 255, 255, 0.8);
  margin-bottom: 6px;
  line-height: 1.4;
}

#win-drink-count {
  color: #ffd700;
  font-weight: bold;
}

.win-encouragement {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.4);
  margin-bottom: 28px;
  margin-top: 4px;
  font-style: italic;
}

.win-buttons {
  display: flex;
  gap: 10px;
}

#win-new-game,
#win-view-scores {
  flex: 1;
  min-height: 52px;
  border-radius: 10px;
  font-family: Georgia, serif;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s, background 0.1s;
  border: none;
}

#win-new-game {
  background: #ffd700;
  color: #111;
}

#win-new-game:active {
  transform: scale(0.97);
  background: #e6c200;
}

#win-view-scores {
  background: transparent;
  border: 1px solid rgba(255, 215, 0, 0.6) !important;
  color: #ffd700;
}

#win-view-scores:active {
  transform: scale(0.97);
  background: rgba(255, 215, 0, 0.1);
}

/* ── Name entry modal ────────────────────────────────────────────────────── */
#name-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 20px;
}

#name-box {
  background: linear-gradient(150deg, #1a1a2e 0%, #12122a 100%);
  border: 2px solid #ffd700;
  border-radius: 20px;
  padding: 36px 28px 28px;
  text-align: center;
  max-width: 320px;
  width: 100%;
  box-shadow:
    0 0 50px rgba(255, 215, 0, 0.2),
    0 20px 60px rgba(0, 0, 0, 0.6);
  animation: modal-in 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

#name-box h2 {
  font-size: 26px;
  color: #ffd700;
  margin-bottom: 8px;
}

.name-sub {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.55);
  margin-bottom: 22px;
  line-height: 1.4;
}

#name-input {
  display: block;
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 16px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 215, 0, 0.4);
  border-radius: 8px;
  color: #fff;
  font-family: Georgia, serif;
  font-size: 18px;
  text-align: center;
  outline: none;
  -webkit-appearance: none;
  transition: border-color 0.15s;
}

#name-input:focus {
  border-color: #ffd700;
}

#name-input::placeholder {
  color: rgba(255, 255, 255, 0.3);
}

#name-confirm {
  display: block;
  width: 100%;
  min-height: 52px;
  background: #ffd700;
  color: #111;
  border: none;
  border-radius: 10px;
  font-family: Georgia, serif;
  font-size: 17px;
  font-weight: bold;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s, background 0.1s;
}

#name-confirm:active {
  transform: scale(0.97);
  background: #e6c200;
}

/* ── High scores overlay ─────────────────────────────────────────────────── */
#scores-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 16px;
  overflow-y: auto;
}

#scores-box {
  background: linear-gradient(150deg, #1a1a2e 0%, #12122a 100%);
  border: 2px solid #ffd700;
  border-radius: 20px;
  padding: 28px 20px 24px;
  text-align: center;
  max-width: 680px;
  width: 100%;
  box-shadow:
    0 0 50px rgba(255, 215, 0, 0.2),
    0 20px 60px rgba(0, 0, 0, 0.6);
  animation: modal-in 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

#scores-box h2 {
  font-size: 28px;
  color: #ffd700;
  margin-bottom: 18px;
  letter-spacing: 2px;
}

.scores-tables {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.scores-col {
  flex: 1;
  min-width: 0;
}

.scores-title {
  font-size: 13px;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
  line-height: 1.3;
}

.scores-title.lucky  { color: #6edf6e; }
.scores-title.wasted { color: #ff8c66; }

.scores-subtitle {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.35);
  margin-bottom: 8px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.score-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.score-table th {
  color: rgba(255, 215, 0, 0.6);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 4px 6px;
  border-bottom: 1px solid rgba(255, 215, 0, 0.2);
  font-weight: normal;
}

.score-table td {
  padding: 5px 6px;
  color: rgba(255, 255, 255, 0.85);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 80px;
}

.score-table td:first-child {
  color: rgba(255, 215, 0, 0.5);
  width: 22px;
  font-size: 11px;
}

.no-scores {
  color: rgba(255, 255, 255, 0.3) !important;
  font-style: italic;
  text-align: center;
  padding: 12px 0 !important;
}

.scores-note {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.25);
  margin-bottom: 18px;
  font-style: italic;
}

#scores-close {
  display: block;
  width: 100%;
  max-width: 240px;
  margin: 0 auto;
  min-height: 48px;
  background: transparent;
  border: 1px solid rgba(255, 215, 0, 0.5);
  color: #ffd700;
  font-family: Georgia, serif;
  font-size: 16px;
  border-radius: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}

#scores-close:active {
  background: rgba(255, 215, 0, 0.1);
}

@media (max-width: 480px) {
  .scores-tables {
    flex-direction: column;
  }
  #scores-box h2 {
    font-size: 22px;
  }
}

/* ── Age gate ────────────────────────────────────────────────────────────── */
#age-gate-overlay,
#age-blocked-overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at 50% 25%, #236b32 0%, #0f3d1a 65%, #07220f 100%);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#age-gate-box,
#age-blocked-box {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  padding: 40px 32px;
  max-width: 380px;
  width: 100%;
  text-align: center;
}

.age-gate-rocket {
  font-size: 48px;
  margin-bottom: 8px;
}

#age-gate-box h1 {
  font-size: 2rem;
  color: #ffd700;
  letter-spacing: 2px;
  margin-bottom: 4px;
}

.age-gate-sub {
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.9rem;
  margin-bottom: 20px;
}

.age-gate-rule {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  margin: 0 0 20px;
}

.age-gate-notice {
  font-size: 1rem;
  color: #fff;
  line-height: 1.55;
  margin-bottom: 24px;
}

.age-gate-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

#age-gate-yes {
  background: #2d8a4e;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 14px 24px;
  font-size: 1rem;
  font-family: Georgia, serif;
  cursor: pointer;
  transition: background 0.15s;
}

#age-gate-yes:hover,
#age-gate-yes:active {
  background: #37a860;
}

#age-gate-no {
  background: transparent;
  color: rgba(255, 255, 255, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  padding: 12px 24px;
  font-size: 0.875rem;
  font-family: Georgia, serif;
  cursor: pointer;
  transition: background 0.15s;
}

#age-gate-no:hover,
#age-gate-no:active {
  background: rgba(255, 255, 255, 0.06);
}

.age-gate-legal {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.35);
  line-height: 1.5;
}

/* ── Under-age blocked screen ────────────────────────────────────────────── */
.blocked-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

#age-blocked-box h2 {
  font-size: 1.3rem;
  margin-bottom: 12px;
  color: #fff;
}

#age-blocked-box p:last-child {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.65);
  line-height: 1.5;
}

/* ── Responsible drinking footer ─────────────────────────────────────────── */
#responsible-footer {
  text-align: center;
  padding: 14px 20px;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.3);
  line-height: 1.5;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  margin-top: 8px;
}

#responsible-footer a {
  color: rgba(255, 255, 255, 0.45);
  text-decoration: underline;
}

/* ── Win screen responsible note ─────────────────────────────────────────── */
.win-responsible {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.35);
  margin-bottom: 20px;
}

.win-responsible a {
  color: rgba(255, 255, 255, 0.5);
  text-decoration: underline;
}

/* ── Utility ─────────────────────────────────────────────────────────────── */
.hidden {
  display: none !important;
}
