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

body {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  font-family: 'Georgia', serif;
  color: #3b1f4e;
  overflow: hidden;
}

/* ── App shell ────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  width: min(480px, 100vw);
  padding: 16px;
}

/* ── Challenge banner ────────────────────────────────────────────────────── */
#challenge-banner {
  width: 100%;
  background: linear-gradient(135deg, #4a148c, #7b1fa2);
  color: #fff;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 0.78rem;
  font-weight: bold;
  letter-spacing: 0.03em;
  text-align: center;
  margin-bottom: 6px;
  line-height: 1.4;
}
#challenge-banner.hidden { display: none; }

/* ── Level progress bar ───────────────────────────────────────────────────── */
#level-progress {
  width: 100%;
  padding-bottom: 6px;
}

#level-progress-track {
  width: 100%;
  height: 10px;
  background: rgba(180, 120, 210, 0.25);
  border-radius: 5px;
  border: 1px solid rgba(180, 100, 220, 0.35);
  overflow: hidden;
  box-shadow: inset 0 1px 4px rgba(100, 0, 120, 0.15);
}

#level-progress-fill {
  height: 100%;
  width: 1%;
  background: linear-gradient(90deg, #ab47bc, #e91e8c);
  border-radius: 5px;
  transition: width 0.5s ease;
}

#level-progress-label {
  font-size: 0.62rem;
  font-weight: bold;
  letter-spacing: 0.08em;
  color: #9c27b0;
  text-align: center;
  margin-top: 3px;
}

/* ── HUD health bar ───────────────────────────────────────────────────────── */
#hud {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0 6px;
}

.hud-player {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
}

#hud-cpu  { flex-direction: row; }
#hud-you  { flex-direction: row-reverse; }

.hud-name {
  font-size: 0.7rem;
  font-weight: bold;
  letter-spacing: 0.08em;
  color: #7b3fa0;
  white-space: nowrap;
  min-width: 26px;
}

.hud-cards {
  font-size: 0.75rem;
  font-weight: bold;
  color: #5c1f7a;
  min-width: 18px;
  text-align: center;
}

.health-track {
  flex: 1;
  height: 18px;
  background: rgba(180, 120, 210, 0.25);
  border-radius: 3px;
  border: 1px solid rgba(180, 100, 220, 0.35);
  overflow: hidden;
  box-shadow: inset 0 1px 4px rgba(100, 0, 120, 0.15);
}

/* CPU bar grows left-to-right from the left edge */
.cpu-track { direction: ltr; }
/* Player bar grows right-to-left (mirror) */
.you-track { direction: rtl; }

.health-fill {
  height: 100%;
  width: 50%;
  background: linear-gradient(90deg, #ab47bc, #ce93d8);
  border-radius: 3px;
  transition: width 0.4s ease, background 0.4s ease;
}

/* ── HUD centre (VS + streak) ─────────────────────────────────────────────── */
#hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 48px;
}

#hud-vs {
  font-size: 0.8rem;
  font-weight: bold;
  color: #9c27b0;
  letter-spacing: 0.1em;
  text-shadow: 0 1px 3px rgba(156, 39, 176, 0.3);
}

#snap-streak {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 0.75rem;
  font-weight: bold;
  color: #fff;
  background: linear-gradient(135deg, #e91e8c, #9c27b0);
  border-radius: 10px;
  padding: 1px 7px;
  white-space: nowrap;
}
#snap-streak.hidden { display: none; }

@keyframes streak-pop {
  0%   { transform: scale(0.7); }
  60%  { transform: scale(1.25); }
  100% { transform: scale(1); }
}
.streak-pop { animation: streak-pop 0.2s ease-out forwards; }

#level-badge {
  font-size: 0.65rem;
  font-weight: bold;
  letter-spacing: 0.1em;
  color: #fff;
  background: linear-gradient(135deg, #7b1fa2, #4a148c);
  border-radius: 8px;
  padding: 1px 6px;
}
#level-badge #level-num { font-size: 0.75rem; }

/* ── Snap counters ────────────────────────────────────────────────────────── */
#snap-counters {
  width: 100%;
  display: flex;
  justify-content: space-between;
  padding: 2px 2px 6px;
}

.snap-counter {
  display: flex;
  align-items: center;
  gap: 6px;
}

.snap-counter-label {
  font-size: 0.7rem;
  font-weight: bold;
  letter-spacing: 0.06em;
  color: #9c27b0;
  text-transform: uppercase;
}

.snap-counter-value {
  font-size: 1.1rem;
  font-weight: bold;
  color: #fff;
  background: linear-gradient(135deg, #e91e8c, #9c27b0);
  border-radius: 20px;
  min-width: 28px;
  text-align: center;
  padding: 1px 8px;
  transition: transform 0.15s;
  box-shadow: 0 2px 8px rgba(156, 39, 176, 0.3);
}

@keyframes counter-pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.4); }
  100% { transform: scale(1); }
}
.snap-counter-value.pop { animation: counter-pop 0.25s ease-out forwards; }

/* ── Table surface ────────────────────────────────────────────────────────── */
#table {
  width: 100%;
  background: linear-gradient(135deg, #f8e8ff 0%, #fce4f4 40%, #ede0ff 100%);
  border: 10px solid #ce93d8;
  border-radius: 24px;
  box-shadow: 0 0 0 4px #f48fb1, 0 8px 32px rgba(156, 39, 176, 0.35), inset 0 0 50px rgba(200,100,220,0.08);
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-areas:
    "cpu-label  cpu-deck    ."
    ".          pile-area   ."
    "snap-stats player-deck you-label";
  align-items: center;
  gap: 12px 8px;
}

#cpu-label          { grid-area: cpu-label; }
#ai-deck-visual     { grid-area: cpu-deck; }
#pile-area          { grid-area: pile-area; }
#snap-stats         { grid-area: snap-stats; align-self: end; }
#player-deck-visual { grid-area: player-deck; }
#you-label          { grid-area: you-label; text-align: right; }

.player-label {
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  color: #7b1fa2;
  white-space: nowrap;
}
.player-label strong {
  display: block;
  font-size: 1rem;
  color: #4a148c;
}

.turn-tag {
  display: block;
  font-size: 0.55rem;
  font-weight: bold;
  letter-spacing: 0.07em;
  color: #fff;
  background: linear-gradient(135deg, #e91e8c, #9c27b0);
  border-radius: 5px;
  padding: 1px 5px;
  margin-top: 3px;
  text-transform: uppercase;
  min-height: 1em;
}
.turn-tag:empty {
  background: none;
  padding: 0;
  margin: 0;
}
@keyframes turn-pulse {
  from { opacity: 0.75; transform: scale(0.97); }
  to   { opacity: 1;    transform: scale(1.03); }
}
.turn-tag:not(:empty) {
  animation: turn-pulse 0.55s ease-in-out infinite alternate;
}

/* Card stack visualisation */
.card-stack {
  /* Padding lets the box-shadow stack be visible without clipping */
  padding: 0 22px 22px 0;
  flex-shrink: 0;
}

.stack-card {
  width: 62px;
  height: 88px;
  border-radius: 6px;
  background: repeating-linear-gradient(
    -45deg,
    #9c27b0 0px 6px,
    #7b1fa2 6px 12px
  );
  border: 1px solid rgba(255,255,255,0.35);
  position: relative;
  transition: box-shadow 0.35s ease, opacity 0.3s ease;
}

.stack-card.empty {
  opacity: 0.2;
  box-shadow: none !important;
}

/* ── Snap stats bubble (in table) ─────────────────────────────────────────── */
#snap-stats {
  background: rgba(123, 31, 162, 0.08);
  border: 1px solid rgba(180, 100, 220, 0.4);
  border-radius: 8px;
  padding: 6px 8px;
}

.stat-header-row,
.stat-row {
  display: grid;
  grid-template-columns: 2.8rem 1fr 1fr;
  gap: 2px;
  font-size: 0.62rem;
  line-height: 1.65;
}

.stat-col-header {
  font-size: 0.58rem;
  font-weight: bold;
  letter-spacing: 0.06em;
  color: #ce93d8;
  text-align: right;
  text-transform: uppercase;
  padding-bottom: 2px;
  border-bottom: 1px solid rgba(156, 39, 176, 0.2);
}

.stat-divider {
  border-top: 1px solid rgba(156, 39, 176, 0.25);
  margin-top: 2px;
  padding-top: 2px;
}

.stat-label {
  font-weight: bold;
  letter-spacing: 0.04em;
  color: #9c27b0;
  text-transform: uppercase;
}

.stat-val {
  font-weight: bold;
  color: #4a148c;
  text-align: right;
}

/* ── Central pile ─────────────────────────────────────────────────────────── */
#pile-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: filter 0.4s ease;
}

#pile-main {
  position: relative;
}

#pile-face {
  position: absolute;
  right: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  font-size: 7rem;
  line-height: 1;
  user-select: none;
  transition: font-size 0.35s ease;
}

#pile-cards {
  position: relative;
  width: 92px;
  height: 112px;
  transform-origin: center bottom;
  transition: transform 0.35s ease;
}

#pile-card-prev {
  position: absolute;
  top: 8px;
  left: 10px;
  transform: rotate(-6deg);
  z-index: 1;
  transition: box-shadow 0.35s ease;
}

#pile-card-top {
  position: absolute;
  top: 3px;
  left: 10px;
  transform: rotate(3deg);
  z-index: 2;
}

#pile-count {
  font-size: 0.8rem;
  color: #9c27b0;
  letter-spacing: 0.05em;
  transition: color 0.4s ease, font-size 0.35s ease;
}

/* ── Snap flash overlay ───────────────────────────────────────────────────── */
#snap-flash {
  position: fixed;
  top: 0;
  left: 0;
  transform: translate(-50%, -50%) scale(0);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  z-index: 100;
  opacity: 0;
  white-space: nowrap;
}

.flash-emoji {
  font-size: 6rem;
  line-height: 1;
  filter: drop-shadow(0 0 20px currentColor);
}

.flash-label {
  font-size: 2.8rem;
  font-weight: bold;
  letter-spacing: 0.18em;
}

.flash-snap .flash-label {
  color: #ffd700;
  text-shadow: 0 0 30px #ffaa00, 0 0 60px #ff8800, 0 3px 8px rgba(0,0,0,0.7);
}

.flash-deny .flash-label {
  color: #ff3333;
  text-shadow: 0 0 30px #cc0000, 0 0 60px #990000, 0 3px 8px rgba(0,0,0,0.7);
}

@keyframes flash-snap-anim {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.1) rotate(-15deg); }
  15%  { opacity: 1; transform: translate(-50%, -50%) scale(1.25) rotate(5deg); }
  28%  { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0deg); }
  70%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.9) translateY(-20px); }
}

@keyframes flash-deny-anim {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.1); }
  12%  { opacity: 1; transform: translate(-50%, -50%) scale(1.2) rotate(-8deg); }
  22%  { opacity: 1; transform: translate(-50%, -50%) scale(1.1) rotate(8deg); }
  32%  { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0deg); }
  70%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.9) translateY(-20px); }
}

#snap-flash.flash-snap { animation: flash-snap-anim 1.4s ease-out forwards; }
#snap-flash.flash-deny { animation: flash-deny-anim 1.4s ease-out forwards; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  width: 72px;
  height: 100px;
  border-radius: 7px;
  border: 1px solid #e0b0e8;
  background: #fff;
  box-shadow: 2px 4px 12px rgba(100, 0, 120, 0.3);
  position: relative;
  flex-shrink: 0;
}

.card.empty {
  background: rgba(255,255,255,0.12);
  border: 2px dashed rgba(255,255,255,0.35);
  box-shadow: none;
}

.card.red   { color: #c2185b; }
.card.black { color: #4a148c; }

.corner {
  position: absolute;
  font-size: 12px;
  line-height: 1.2;
  font-weight: bold;
  text-align: center;
}
.top-left     { top: 5px; left: 6px; }
.bottom-right {
  bottom: 5px; right: 6px;
  transform: rotate(180deg);
}

.center-suit {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 32px;
  line-height: 1;
}

/* Card flip-in animation */
@keyframes flip-in {
  0%   { transform: scaleY(0.05) translateY(-20px); opacity: 0.3; }
  65%  { transform: scaleY(1.06); }
  100% { transform: scaleY(1) translateY(0); opacity: 1; }
}
.card.flip-in { animation: flip-in 0.2s ease-out forwards; }

/* ── Controls ─────────────────────────────────────────────────────────────── */
#controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding-top: 8px;
}

#status-msg {
  font-size: 0.9rem;
  color: #7b1fa2;
  text-align: center;
  min-height: 1.4em;
  letter-spacing: 0.03em;
  font-weight: bold;
}

.action-btn {
  padding: 12px 32px;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: bold;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s, opacity 0.15s;
}
.action-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(156,39,176,0.35); }
.action-btn:active:not(:disabled) { transform: translateY(0); }
.action-btn:disabled { opacity: 0.4; cursor: not-allowed; }

#btn-flip {
  background: linear-gradient(135deg, #ab47bc, #7b1fa2);
  color: #fff;
  width: 180px;
  box-shadow: 0 4px 14px rgba(123, 31, 162, 0.4);
}

#btn-snap {
  background: linear-gradient(135deg, #f06292, #e91e8c);
  color: #fff;
  font-size: 1.3rem;
  width: 200px;
  box-shadow: 0 0 24px rgba(233, 30, 140, 0.65);
}
@keyframes snap-pulse {
  0%   { transform: scale(0.4); opacity: 0; }
  70%  { transform: scale(1.12); }
  100% { transform: scale(1);   opacity: 1; }
}
#btn-snap.snap-active { animation: snap-pulse 0.22s ease-out forwards; }

/* ── Game-over overlay ────────────────────────────────────────────────────── */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(60, 0, 80, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
#overlay[hidden] { display: none; }

#overlay-content {
  background: linear-gradient(160deg, #fce4ec, #f3e5f5);
  border: 2px solid #ce93d8;
  border-radius: 16px;
  padding: 32px 40px;
  text-align: center;
  box-shadow: 0 8px 40px rgba(156, 39, 176, 0.4);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
#overlay-title { font-size: 2rem; color: #7b1fa2; }
#overlay-body  { font-size: 0.95rem; color: #5c1f7a; line-height: 1.6; }
#overlay-level { font-size: 0.9rem; font-weight: bold; color: #9c27b0; }
#overlay-level.hidden { display: none; }

#overlay-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

#btn-share {
  background: linear-gradient(135deg, #7b1fa2, #4a148c);
  color: #fff;
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.1s;
  box-shadow: 0 4px 14px rgba(74, 20, 140, 0.4);
}
#btn-share:hover { transform: scale(1.04); }

#share-confirm {
  font-size: 0.8rem;
  color: #7b1fa2;
  font-weight: bold;
  letter-spacing: 0.04em;
  margin-top: -6px;
}
#share-confirm.hidden { display: none; }

#btn-play-again {
  background: linear-gradient(135deg, #f06292, #e91e8c);
  color: #fff;
  padding: 12px 36px;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.1s;
  margin-top: 4px;
  box-shadow: 0 4px 14px rgba(233, 30, 140, 0.4);
}
#btn-play-again:hover { transform: scale(1.04); }
