:root {
  color-scheme: dark;
  --felt: #135a46;
  --ink: #f7f3e7;
  --muted: #b9c8bd;
  --gold: #e0b54e;
  --red: #cf3f3f;
  --black: #252525;
  --panel: rgba(8, 24, 22, 0.84);
  --line: rgba(255, 255, 255, 0.14);
  --selected: #f2c85e;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 35%, rgba(255, 255, 255, 0.12), transparent 26rem),
    linear-gradient(135deg, #0a2924 0%, var(--felt) 48%, #12352e 100%);
}

body::before {
  content: "";
  position: fixed;
  top: 46%;
  left: 50%;
  z-index: 4;
  width: 78px;
  height: 110px;
  border: 0;
  border-radius: 14px;
  background: url("assets/cloudix-card-back.png") center / cover no-repeat;
  box-shadow: 0 20px 36px rgba(0, 0, 0, 0.34);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) rotate(-7deg);
}

body.shuffling::before {
  opacity: 1;
  animation: shuffleDeck 650ms ease-in-out;
}

button {
  font: inherit;
}

.intro-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(3, 14, 12, 0.9);
}

.intro-overlay[hidden] {
  display: none;
}

.splash-panel,
.player-panel {
  width: min(300px, 100%);
  border: 1px solid rgba(224, 181, 78, 0.38);
  background: rgba(11, 34, 31, 0.96);
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.42);
}

.splash-panel {
  min-height: 330px;
  padding: 22px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 18px;
}

.splash-logo-40 {
  width: 138px;
  height: 138px;
  object-fit: cover;
  border: 1px solid rgba(224, 181, 78, 0.5);
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.32);
}

.splash-logo-cloudix {
  width: 210px;
  height: 78px;
  object-fit: contain;
}

.splash-panel p {
  width: 92px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.player-panel {
  padding: 20px;
  display: grid;
  gap: 14px;
}

.avatar-panel {
  width: min(780px, 100%);
  max-height: min(82vh, 680px);
  padding: 18px;
  border: 1px solid rgba(224, 181, 78, 0.38);
  background: rgba(11, 34, 31, 0.96);
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.42);
  overflow: auto;
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(64px, 1fr));
  gap: 12px;
}

.avatar-option {
  aspect-ratio: 1;
  border: 1px solid rgba(224, 181, 78, 0.42);
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 3px;
}

.avatar-option:hover,
.avatar-option:focus-visible {
  outline: 3px solid rgba(242, 200, 94, 0.62);
  outline-offset: 2px;
}

.avatar-option img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.player-logo {
  width: 108px;
  height: 108px;
  justify-self: center;
  object-fit: cover;
  border: 1px solid rgba(224, 181, 78, 0.45);
}

.player-panel label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.player-panel input {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 0;
  padding: 0 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  font: inherit;
  font-weight: 700;
}

.player-panel input:focus {
  outline: 3px solid rgba(242, 200, 94, 0.45);
  outline-offset: 2px;
}

.gender-select {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.gender-button {
  min-height: 42px;
  border: 0;
  color: #1c1708;
  background: var(--gold);
  cursor: pointer;
  font-weight: 900;
}

.gender-button.active {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(242, 200, 94, 0.78);
}

.gender-button:focus-visible {
  outline: 3px solid rgba(242, 200, 94, 0.55);
  outline-offset: 2px;
}

.game-shell {
  width: min(1360px, 100%);
  height: 100vh;
  margin: 0 auto;
  padding: 8px;
  display: grid;
  grid-template-columns: 300px minmax(520px, 1fr);
  grid-template-rows: 138px 142px 104px minmax(156px, 1fr);
  gap: 8px;
  align-content: start;
  overflow: hidden;
}

.scoreboard,
.opponent-zone,
.table-zone,
.player-zone,
.play-panel,
.event-log {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.22);
}

.scoreboard {
  grid-column: 1;
  grid-row: 1 / 5;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
}

.brand-block h1 {
  margin: 2px 0 0;
  font-family: Georgia, serif;
  font-size: 70px;
  line-height: 0.9;
  color: var(--gold);
}

.brand-logo-40 {
  width: min(100%, 130px);
  aspect-ratio: 1;
  display: block;
  object-fit: cover;
  border: 1px solid rgba(224, 181, 78, 0.55);
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.32);
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.score-row {
  display: grid;
  gap: 8px;
}

.actions[hidden] { display: none !important; }

.score-card {
  min-height: 56px;
  padding: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  display: grid;
  gap: 3px;
}

.player-score-name {
  display: grid;
  grid-template-columns: 54px 1fr;
  align-items: center;
  gap: 9px;
}

.score-avatar {
  width: 50px;
  height: 50px;
  display: block;
  border: 1px solid rgba(242, 200, 94, 0.85);
  border-radius: 10px;
  object-fit: cover;
  background: rgba(0, 0, 0, 0.28);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.deck-score {
  min-height: 48px;
  padding: 7px 8px;
}

.score-card.active,
.opponent-zone.active,
.player-zone.active {
  border-color: rgba(242, 200, 94, 0.9);
  background: rgba(242, 200, 94, 0.13);
}

.score-card span,
.zone-header span,
.selected-play span {
  color: var(--muted);
  font-size: 13px;
}

.score-card strong {
  font-size: 23px;
  line-height: 1;
}

.deck-score strong {
  font-size: 24px;
}

.deck-score small {
  font-size: 11px;
}

.score-card small,
.selected-play small {
  color: var(--muted);
}

.score-markers {
  min-height: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
}

.score-dog {
  width: 22px;
  height: 22px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.12);
  display: grid;
  place-items: center;
  font-size: 15px;
  line-height: 1;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.score-match {
  width: 24px;
  height: 24px;
  background: url("assets/fosforo.png") center / cover no-repeat;
  border-radius: 5px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.cloudix-brand {
  margin-top: auto;
  min-height: 120px;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.cloudix-brand img {
  width: 100%;
  height: 138px;
  object-fit: contain;
  object-position: center;
}

.actions {
  display: grid;
  grid-template-columns: 48px 1fr 1fr;
  gap: 10px;
}

.primary-button,
.secondary-button,
.icon-button {
  min-height: 38px;
  border: 0;
  color: #1c1708;
  background: var(--gold);
  cursor: pointer;
  font-weight: 800;
}

.secondary-button {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.icon-button {
  font-size: 24px;
}

.opponent-zone {
  grid-column: 2;
  grid-row: 1;
  padding: 10px;
}

.table-zone {
  grid-column: 2;
  grid-row: 2;
  padding: 10px;
  min-height: 0;
  overflow: hidden;
}

.play-panel {
  grid-column: 2;
  grid-row: 3;
  padding: 10px;
  display: grid;
  grid-template-columns: 1fr 140px 140px;
  gap: 12px;
  align-items: center;
}

.player-zone {
  grid-column: 2;
  grid-row: 4;
  padding: 10px;
  overflow: hidden;
}

.event-log {
  display: none;
}

.zone-header {
  min-height: 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
}

.zone-header strong {
  color: var(--gold);
}

.card-grid {
  display: grid;
  gap: 8px;
}

.table-grid {
  grid-template-columns: repeat(auto-fill, 64px);
  align-content: start;
  align-items: start;
}

.hand-grid {
  grid-template-columns: repeat(5, 80px);
  justify-content: space-between;
}

.cpu-hand {
  min-height: 78px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card {
  position: relative;
  aspect-ratio: 5 / 7;
  min-height: 76px;
  border: 2px solid #67dff1;
  border-radius: 11px;
  background: linear-gradient(145deg, #ffffff 0%, #f7fbff 58%, #eeeaff 100%);
  color: #10245c;
  cursor: pointer;
  box-shadow:
    0 9px 16px rgba(0, 0, 0, 0.24),
    inset 0 0 14px rgba(103, 223, 241, 0.12);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.card::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(83, 76, 190, 0.33);
  border-radius: 7px;
  pointer-events: none;
}

.card:disabled {
  opacity: 1 !important;
  color: #10245c !important;
  filter: none !important;
  -webkit-text-fill-color: currentColor !important;
}

.card.red:disabled {
  color: var(--red) !important;
}

.card:disabled .rank,
.card:disabled .suit-icon,
.card:disabled small {
  opacity: 1 !important;
  color: currentColor !important;
  -webkit-text-fill-color: currentColor !important;
}

.hand-grid .card {
  width: 80px;
  height: 112px;
  min-height: 0;
}

.table-grid .card {
  width: 64px;
  height: 90px;
  min-height: 0;
}

.table-grid .card .rank {
  top: 6px;
  left: 6px;
  font-size: 15px;
}

.table-grid .card .rank.bottom {
  inset: auto 6px 6px auto;
}

.table-grid .card .suit-icon {
  font-size: 26px;
}

.cpu-hand .card {
  width: 54px;
  height: 76px;
  min-height: 0;
  cursor: default;
}

.cpu-hand .card .rank {
  top: 6px;
  left: 6px;
  font-size: 14px;
}

.cpu-hand .card .rank.bottom {
  inset: auto 6px 6px auto;
}

.cpu-hand .card .suit-icon {
  font-size: 23px;
}

.card.cpu-play-preview {
  border-color: var(--gold);
  box-shadow:
    0 0 0 3px rgba(224, 181, 78, 0.4),
    0 12px 22px rgba(0, 0, 0, 0.3);
  transform: translateY(4px);
}

.card:hover,
.card:focus-visible {
  outline: 3px solid rgba(103, 223, 241, 0.72);
  outline-offset: 2px;
  box-shadow:
    0 0 0 3px rgba(83, 76, 190, 0.32),
    0 12px 22px rgba(0, 0, 0, 0.28);
}

.card.selected {
  border-color: #43dfff;
  transform: translateY(-7px);
  box-shadow:
    0 0 0 4px rgba(104, 47, 203, 0.45),
    0 14px 25px rgba(0, 0, 0, 0.32);
}

.card.table-selected {
  border-color: #43dfff;
  background: linear-gradient(145deg, #ffffff 0%, #effcff 52%, #ded6ff 100%);
  transform: translateY(-7px) scale(1.03);
  box-shadow:
    0 0 0 4px rgba(67, 223, 255, 0.7),
    0 0 22px rgba(99, 76, 255, 0.55),
    0 15px 24px rgba(0, 0, 0, 0.34);
}

.card.cpu-preview {
  border-color: #7be3ff;
  background: #e6fbff;
  box-shadow:
    0 0 0 3px rgba(123, 227, 255, 0.4),
    0 12px 22px rgba(0, 0, 0, 0.3);
  animation: cpuPreviewPulse 900ms ease-in-out infinite;
}

.card-ghost {
  opacity: 0.28;
}

.flying-card {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  margin: 0;
  transition:
    transform 620ms cubic-bezier(0.18, 0.82, 0.22, 1),
    opacity 620ms ease;
  box-shadow: 0 22px 34px rgba(0, 0, 0, 0.38);
}

.rank {
  position: absolute;
  top: 8px;
  left: 8px;
  display: grid;
  text-align: center;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 900;
  line-height: 1;
}

.rank.bottom {
  inset: auto 8px 8px auto;
  transform: rotate(180deg);
}

.suit-icon {
  font-size: clamp(36px, 5vw, 54px);
  opacity: 0.18;
  transform: scale(1.08);
}

.card.red {
  color: #d22572;
}

.card-back {
  position: relative;
  width: 54px;
  height: 76px;
  overflow: hidden;
  border: 0;
  border-radius: 11px;
  background: url("assets/cloudix-card-back.png") center / cover no-repeat;
  box-shadow:
    0 8px 18px rgba(0, 18, 25, 0.73),
    0 0 10px rgba(56, 221, 255, 0.33);
}

.card-back::after {
  content: none;
}

.card.dealt,
.card-back.dealt {
  animation: dealCard 320ms ease-out both;
}

.selected-play {
  min-height: 48px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 3px 12px;
  align-items: center;
}

.selected-play small {
  grid-column: 1 / -1;
}

.event-log ol {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow: auto;
  display: grid;
  gap: 8px;
}

.event-log li {
  padding: 9px;
  border-left: 3px solid var(--gold);
  background: rgba(255, 255, 255, 0.06);
  font-size: 13px;
  line-height: 1.35;
}

.zapatero-overlay {
  position: fixed;
  inset: 0;
  z-index: 34;
  display: grid;
  place-items: center;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.18);
  animation: zapateroPop 420ms ease-out both;
}

.zapatero-overlay[hidden] {
  display: none;
}

.zapatero-overlay img {
  width: min(58vw, 760px);
  max-height: 62vh;
  object-fit: contain;
  filter: drop-shadow(0 26px 34px rgba(0, 0, 0, 0.45));
}

.cut-overlay {
  position: fixed;
  inset: 0;
  z-index: 36;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.62);
}

.cut-overlay[hidden] {
  display: none;
}

.cut-panel {
  width: min(640px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  background: #102b27;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
  display: grid;
  gap: 16px;
}

.cut-panel h2 {
  margin: 0;
  font-size: 34px;
}

.cut-panel p {
  margin: 0;
  color: var(--muted);
}

.cut-board {
  display: grid;
  grid-template-columns: 1fr 92px 1fr;
  gap: 18px;
  align-items: end;
}

.cut-player {
  display: grid;
  gap: 8px;
}

.cut-player span {
  color: var(--muted);
  font-size: 13px;
}

.cut-slot {
  min-height: 152px;
  display: grid;
  place-items: center;
  border: 1px dashed rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.05);
}

.cut-slot .card {
  width: 92px;
  height: 128px;
  min-height: 0;
  cursor: default;
  opacity: 1 !important;
  color: #111 !important;
  background: #fff8e8 !important;
  filter: none !important;
  mix-blend-mode: normal !important;
  -webkit-text-fill-color: currentColor !important;
}

.cut-slot .card.red {
  color: #d12c2c !important;
}

.cut-slot .card .rank,
.cut-slot .card .suit-icon,
.cut-slot .card small {
  opacity: 1 !important;
  color: currentColor !important;
  -webkit-text-fill-color: currentColor !important;
}

.cut-slot .card.cut-card {
  border-color: rgba(0, 0, 0, 0.38) !important;
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.28) !important;
}

.cut-slot .card.cut-card .rank {
  font-size: 18px;
}

.cut-slot .card.cut-card .suit-icon {
  font-size: 34px;
}

.cut-deck {
  width: 72px;
  height: 102px;
  justify-self: center;
  cursor: pointer;
}

.cut-deck:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 35;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.62);
}

.confetti-layer {
  position: fixed;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: -8vh;
  left: var(--confetti-x);
  width: 10px;
  height: 18px;
  border-radius: 2px;
  opacity: 0;
  animation: winnerConfetti var(--confetti-duration) linear var(--confetti-delay) infinite;
}

.modal-panel {
  position: relative;
  z-index: 2;
}

@keyframes winnerConfetti {
  0% {
    opacity: 1;
    transform: translate3d(0, -10vh, 0) rotate(0deg);
  }
  100% {
    opacity: 0.9;
    transform: translate3d(35px, 118vh, 0) rotate(var(--confetti-rotate));
  }
}

.modal[hidden] {
  display: none;
}

.modal-panel {
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  background: #102b27;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}

.modal-panel h2 {
  margin: 8px 0;
  font-size: 34px;
}

.modal-panel p {
  color: var(--muted);
}

@media (max-width: 980px) {
  .game-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }

  .scoreboard,
  .opponent-zone,
  .table-zone,
  .play-panel,
  .player-zone,
  .event-log {
    grid-column: 1;
    grid-row: auto;
  }

  .scoreboard {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
  }

  .score-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .avatar-grid {
    grid-template-columns: repeat(4, minmax(58px, 1fr));
  }

  .scoreboard {
    grid-template-columns: 1fr;
  }

  .score-row,
  .play-panel {
    grid-template-columns: 1fr;
  }

  .actions {
    width: 100%;
  }

  .hand-grid {
    grid-template-columns: repeat(5, minmax(54px, 1fr));
    gap: 7px;
  }

  .hand-grid .card {
    height: 104px;
  }

  .table-grid {
    grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  }
}

@keyframes shuffleDeck {
  0% { transform: translate(-50%, -50%) rotate(-10deg) scale(0.96); }
  30% { transform: translate(calc(-50% - 24px), -50%) rotate(13deg) scale(1.02); }
  62% { transform: translate(calc(-50% + 24px), -50%) rotate(-16deg) scale(1.02); }
  100% { transform: translate(-50%, -50%) rotate(-7deg) scale(1); }
}

@keyframes dealCard {
  from {
    opacity: 0;
    transform: translateY(-28px) scale(0.86) rotate(-4deg);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1) rotate(0deg);
  }
}

@keyframes zapateroPop {
  from {
    opacity: 0;
    transform: scale(0.86);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes cpuPreviewPulse {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-5px);
  }
}
