:root {
  --card-w: clamp(76px, min(11vw, 15vh), 140px);
  --card-h: calc(var(--card-w) * 1.45);
  --felt-dark: #0b3d2e;
  --felt-light: #145c43;
  --gold: #d4af37;
  --panel-bg: rgba(10, 20, 18, 0.55);
  --panel-border: rgba(255, 255, 255, 0.08);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
  color: #f2f2f2;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(ellipse at center, var(--felt-light) 0%, var(--felt-dark) 65%, #062018 100%);
  background-attachment: fixed;
}

.table {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: clamp(8px, 1.5vh, 20px) clamp(10px, 2vw, 24px);
  gap: clamp(6px, 1.2vh, 14px);
  transition: box-shadow .4s ease, background .4s ease;
}

.table.war-active {
  box-shadow: inset 0 0 80px 10px rgba(220, 40, 40, 0.35);
}

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  backdrop-filter: blur(6px);
}

.logo {
  margin: 0;
  font-size: clamp(1.1rem, 2.2vw, 1.6rem);
  letter-spacing: 1px;
  color: var(--gold);
  text-shadow: 0 2px 6px rgba(0,0,0,.5);
}

.logo-sub {
  font-size: 0.55em;
  opacity: 0.6;
  font-weight: normal;
  margin-inline-start: 6px;
}

.sound-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--panel-border);
  color: #fff;
  font-size: 1.2rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  transition: transform .15s ease, background .15s ease;
}
.icon-btn:hover { background: rgba(255,255,255,0.18); transform: scale(1.06); }

input[type="range"] { accent-color: var(--gold); cursor: pointer; }

/* ---------- Rows (deck + reveal area, side by side) ---------- */

.row {
  flex: 1;
  display: flex;
  align-items: center;
  gap: clamp(10px, 2vw, 24px);
  min-height: 0;
}

.pile-slot {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.opponent-row .pile-slot { flex-direction: column; }
.player-row .pile-slot { flex-direction: column-reverse; }

.pile-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: clamp(0.8rem, 1.3vw, 1rem);
  opacity: 0.9;
}

.pile-label {
  padding: 4px 12px;
  background: rgba(0,0,0,0.3);
  border-radius: 20px;
  border: 1px solid var(--panel-border);
}

.pile-count {
  font-weight: bold;
  color: var(--gold);
  font-size: 1.2em;
  min-width: 1.6em;
  text-align: center;
}

.pile {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 12px;
  position: relative;
  transition: opacity .3s ease, transform .3s ease;
}

.pile.face-down {
  background: repeating-linear-gradient(135deg, #7a1f2b 0 8px, #5c1420 8px 16px);
  border: 3px solid var(--gold);
  box-shadow: 0 6px 18px rgba(0,0,0,.5);
}

.pile.face-down::before,
.pile.face-down::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 12px;
  background: inherit;
  border: 3px solid var(--gold);
}
.pile.face-down::before { transform: translate(-4px, -4px); z-index: -1; opacity: .7; }
.pile.face-down::after { transform: translate(-8px, -8px); z-index: -2; opacity: .45; }

.pile.empty {
  opacity: 0.15;
  transform: scale(0.9);
  box-shadow: none;
}
.pile.empty::before, .pile.empty::after { display: none; }

/* ---------- Reveal slots (where drawn cards land) ---------- */

.reveal-slot {
  flex: 1;
  height: calc(var(--card-h) + 24px);
  min-height: calc(var(--card-h) + 24px);
  position: relative;
  border-radius: 18px;
  border: 1px dashed rgba(255,255,255,0.15);
  background: rgba(0,0,0,0.12);
}

.center-strip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  height: clamp(30px, 4vh, 46px);
}

.vs-badge {
  font-weight: 800;
  font-size: clamp(0.9rem, 1.8vw, 1.3rem);
  color: var(--gold);
  background: rgba(0,0,0,0.4);
  border: 2px solid var(--gold);
  border-radius: 50%;
  width: clamp(32px, 4vh, 44px);
  height: clamp(32px, 4vh, 44px);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.table.war-active .vs-badge {
  animation: pulse-war 0.9s infinite ease-in-out;
}

@keyframes pulse-war {
  0%, 100% { box-shadow: 0 0 6px 2px rgba(220,40,40,.6); }
  50% { box-shadow: 0 0 18px 8px rgba(220,40,40,.9); }
}

/* ---------- Cards ---------- */

.card {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--card-w);
  height: var(--card-h);
  margin-left: calc(var(--card-w) / -2);
  margin-top: calc(var(--card-h) / -2);
  border-radius: calc(var(--card-w) * 0.09);
  box-shadow: 0 8px 20px rgba(0,0,0,.45);
  direction: ltr;
  opacity: 0;
  transform:
    translateX(calc(var(--i, 0) * 16px))
    translateY(calc(var(--i, 0) * -3px))
    rotate(calc(var(--i, 0) * 4deg))
    scale(0.7)
    rotateY(90deg);
  transition: transform .45s cubic-bezier(.2,.8,.3,1.15), opacity .3s ease, box-shadow .3s ease;
}

.card.revealed {
  opacity: 1;
  transform:
    translateX(calc(var(--i, 0) * 16px))
    translateY(calc(var(--i, 0) * -3px))
    rotate(calc(var(--i, 0) * 4deg))
    scale(1)
    rotateY(0deg);
}

.card.face-up {
  background: linear-gradient(160deg, #fdfdfd, #ececec);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 6px 8px;
  border: 1px solid rgba(0,0,0,0.1);
}

.card.face-down {
  background: repeating-linear-gradient(135deg, #7a1f2b 0 8px, #5c1420 8px 16px);
  border: 2px solid var(--gold);
}
.card.face-down .card-back-pattern {
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(212,175,55,.5);
  border-radius: calc(var(--card-w) * 0.06);
}

.card.red { color: #c62828; }
.card.black { color: #1a1a1a; }

.corner {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  font-weight: 700;
  font-size: clamp(0.7rem, 1.6vw, 1.05rem);
  width: fit-content;
}
.corner.bottom { align-self: flex-end; transform: rotate(180deg); }
.corner-suit { font-size: 0.9em; }

/* ---------- Pips (number cards 2-10) ---------- */

.card-pips {
  position: relative;
  flex: 1;
  width: 100%;
}

.pip {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: clamp(0.6rem, 1.6vw, 1.05rem);
  line-height: 1;
}
.pip.rot { transform: translate(-50%, -50%) rotate(180deg); }

/* ---------- Ace ---------- */

.card-pips.ace-pip {
  display: flex;
  align-items: center;
  justify-content: center;
}
.pip-ace {
  font-size: clamp(2.2rem, 6.5vw, 4rem);
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.25));
}

/* ---------- Court cards (J/Q/K) ---------- */

.card-face {
  position: relative;
  flex: 1;
  width: 100%;
}

.face-frame {
  position: absolute;
  inset: 8% 12%;
  border-radius: calc(var(--card-w) * 0.06);
  box-shadow: inset 0 0 0 2px currentColor, inset 0 0 0 5px rgba(0,0,0,0.04);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.face-figure {
  font-size: clamp(1.7rem, 4.8vw, 2.8rem);
  line-height: 1;
}

.face-letter {
  font-size: clamp(0.7rem, 1.6vw, 1rem);
  font-weight: 800;
  letter-spacing: 1px;
  opacity: 0.75;
}

.card.joker {
  background: linear-gradient(160deg, #fff8e1, #f3e5ff);
}
.card.joker .corner { color: #7b2cbf; font-size: clamp(0.6rem, 1.3vw, 0.85rem); }
.card.joker .joker-icon {
  align-self: center;
  font-size: clamp(1.8rem, 5vw, 3rem);
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.3));
}

.card.war-back { filter: brightness(0.92); }

.battle-side.winning-side .card.face-up.revealed {
  box-shadow: 0 0 22px 6px var(--gold), 0 8px 20px rgba(0,0,0,.45);
}
.battle-side.losing-side .card { filter: brightness(0.65) saturate(0.8); }

/* ---------- Controls / Footer ---------- */

.controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.log-panel {
  height: 78px;
  overflow-y: auto;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
  backdrop-filter: blur(6px);
}

.log-entry { opacity: 0.85; }
.log-entry.win { color: #7ee787; }
.log-entry.lose { color: #ff9b9b; }
.log-entry.war { color: #ffcf5c; font-weight: 600; }
.log-entry.info { color: #a9c7ff; }

.buttons-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 12px 18px;
  backdrop-filter: blur(6px);
}

.btn {
  padding: 10px 22px;
  border-radius: 10px;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform .15s ease, filter .15s ease;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn.primary {
  background: linear-gradient(135deg, var(--gold), #f5d76e);
  color: #2a2000;
}
.btn.secondary {
  background: rgba(255,255,255,0.1);
  color: #fff;
  border: 1px solid var(--panel-border);
}

.auto-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}
.auto-toggle input { width: 18px; height: 18px; accent-color: var(--gold); cursor: pointer; }

.speed-control {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  opacity: 0.9;
}

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease;
  z-index: 50;
}
.modal-overlay.visible { opacity: 1; pointer-events: auto; }

.modal {
  background: linear-gradient(160deg, #163d2e, #0b241b);
  border: 1px solid var(--gold);
  border-radius: 18px;
  padding: 32px 40px;
  text-align: center;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
  transform: scale(0.9);
  transition: transform .3s ease;
}
.modal-overlay.visible .modal { transform: scale(1); }

.modal h2 { margin: 0 0 10px; color: var(--gold); font-size: 1.8rem; }
.modal p { margin: 0 0 20px; opacity: 0.85; }

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  .buttons-row { flex-direction: column; }
  .row { flex-direction: column; }
  .reveal-slot { width: 100%; }
}
