:root {
  --truco-gold: #f6c453;
  --truco-cyan: #36d9e8;
  --truco-felt: #063e38;
  --truco-ink: #020617;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body, #root {
  width: 100%;
  min-height: 100%;
  overscroll-behavior: none;
}

body {
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 15%, rgba(54,217,232,.15), transparent 34%),
    radial-gradient(circle at 50% 85%, rgba(16,185,129,.14), transparent 40%),
    linear-gradient(145deg, #010409, #061421 52%, #020409);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.viewportContainer {
  min-height: 100dvh;
  background: radial-gradient(ellipse at center, rgba(13,96,79,.22), transparent 63%);
}

.sideColumn {
  background:
    linear-gradient(90deg, rgba(0,0,0,.36), transparent),
    repeating-linear-gradient(135deg, transparent 0 16px, rgba(255,255,255,.012) 17px 18px);
}

.gameContainer {
  isolation: isolate;
  position: relative;
  width: min(100vw, 68vh);
  height: 100dvh;
  padding: clamp(6px, 1.25vh, 14px);
  border-inline: 1px solid rgba(103,232,249,.18);
  background: linear-gradient(180deg, rgba(1,17,23,.96), rgba(3,35,31,.96) 48%, rgba(1,13,20,.98));
  box-shadow: 0 0 70px rgba(0,0,0,.82), inset 0 0 45px rgba(45,212,191,.08);
  perspective: 1100px;
}

.gameContainer::before {
  opacity: .15;
  filter: saturate(.7) contrast(1.15);
}

.gameContainer::after {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 15% 3% 13%;
  border: 1px solid rgba(94,234,212,.26);
  border-radius: 48% / 22%;
  background:
    radial-gradient(ellipse at 50% 44%, rgba(45,212,191,.16), transparent 58%),
    repeating-radial-gradient(ellipse at center, rgba(255,255,255,.018) 0 1px, transparent 2px 6px),
    linear-gradient(155deg, #075a4f, #043a34 55%, #022922);
  box-shadow: inset 0 0 55px rgba(0,0,0,.62), 0 18px 35px rgba(0,0,0,.48), 0 0 24px rgba(20,184,166,.12);
  transform: rotateX(2deg);
}

.row, .column, .hand, .actionButtonsRow { position: relative; z-index: 2; }

.hand {
  perspective: 800px;
  transform-style: preserve-3d;
}

.card {
  width: clamp(54px, 9.5vh, 92px);
  margin-right: clamp(4px, .7vh, 9px);
  border: 1px solid rgba(255,255,255,.55);
  border-radius: clamp(7px, 1.1vh, 12px);
  background: #f8f3df;
  box-shadow: 0 10px 17px rgba(0,0,0,.42), 0 2px 2px rgba(255,255,255,.65) inset, 0 0 0 1px rgba(0,0,0,.22);
  filter: saturate(1.08) contrast(1.04);
  transform: translateZ(12px) rotateX(-1deg);
  transition: transform .2s cubic-bezier(.2,.8,.2,1), filter .2s, box-shadow .2s;
  user-select: none;
  -webkit-user-drag: none;
}

.card.truco-dealt { animation: trucoDeal .48s cubic-bezier(.18,.82,.22,1) both; }
.card.truco-dealt:nth-child(2) { animation-delay: 70ms; }
.card.truco-dealt:nth-child(3) { animation-delay: 140ms; }

.canReveal:hover, .canReveal:focus-visible {
  transform: translateY(-10px) translateZ(35px) rotateX(-4deg) scale(1.08);
  filter: saturate(1.15) brightness(1.06);
  box-shadow: 0 18px 28px rgba(0,0,0,.5), 0 0 22px rgba(246,196,83,.34);
}

.canReveal:active { transform: translateY(-4px) scale(.98); }

@keyframes trucoDeal {
  0% { opacity: 0; transform: translateY(-45px) rotateY(78deg) rotateZ(-7deg) scale(.78); }
  70% { opacity: 1; transform: translateY(4px) rotateY(-5deg) rotateZ(1deg) scale(1.03); }
  100% { opacity: 1; transform: translateZ(12px) rotateX(-1deg); }
}

.playerSection {
  margin: 0 clamp(5px, 1vh, 12px) 0 0;
  padding: clamp(4px, .65vh, 8px);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 18px;
  opacity: 1;
  background: linear-gradient(145deg, rgba(15,23,42,.82), rgba(2,6,23,.64));
  box-shadow: 0 8px 24px rgba(0,0,0,.34), inset 0 1px rgba(255,255,255,.08);
  backdrop-filter: blur(10px);
}

.playerSection img {
  width: clamp(46px, 8.4vh, 82px);
  border: 2px solid rgba(246,196,83,.46);
  border-radius: 20px;
  box-shadow: 0 7px 18px rgba(0,0,0,.45);
}

.playersTurn {
  border: 1px solid rgba(54,217,232,.78);
  animation: modernTurn 1.45s ease-in-out infinite;
}

@keyframes modernTurn {
  0%,100% { box-shadow: 0 0 10px rgba(54,217,232,.28), inset 0 1px rgba(255,255,255,.08); }
  50% { box-shadow: 0 0 25px rgba(54,217,232,.65), 0 0 0 3px rgba(54,217,232,.12); }
}

.playerName, .points { font-size: clamp(11px, 1.65vh, 17px); letter-spacing: .5px; }
.points { color: var(--truco-gold); }

.speech-bubble {
  border: 1px solid rgba(255,255,255,.72);
  border-radius: 14px;
  background: linear-gradient(145deg, rgba(255,255,255,.97), rgba(207,224,224,.93));
  box-shadow: 0 9px 20px rgba(0,0,0,.32);
}

.speech-bubble-text { color: #071019; font-weight: 800; }

.actionButtons {
  align-content: flex-start;
  gap: clamp(4px, .55vh, 7px);
  height: auto;
  min-height: 10vh;
  margin-bottom: max(3.5vh, var(--safe-bottom));
}

#modal button, #roundOverModal button, .actionButtons button {
  min-height: 38px;
  margin: 0;
  border: 1px solid rgba(246,196,83,.62);
  border-radius: 12px;
  background: linear-gradient(150deg, rgba(25,35,48,.98), rgba(4,10,18,.98));
  box-shadow: 0 6px 14px rgba(0,0,0,.36), inset 0 1px rgba(255,255,255,.1);
  color: #fff;
  text-shadow: 0 1px 2px #000;
  animation: actionGlow 1.8s ease-in-out infinite;
}

#modal button:hover, #roundOverModal button:hover, .actionButtons button:hover,
.actionButtons button:focus-visible {
  background: linear-gradient(135deg, #0f766e, #075985);
  border-color: #67e8f9;
  outline: none;
}

.actionButtons button:active { transform: translateY(2px) scale(.97); }

@keyframes actionGlow {
  0%,100% { box-shadow: 0 5px 12px rgba(0,0,0,.38), 0 0 0 rgba(246,196,83,0); }
  50% { box-shadow: 0 7px 16px rgba(0,0,0,.42), 0 0 14px rgba(246,196,83,.22); }
}

#startGame::before { opacity: .28; filter: saturate(.8) contrast(1.14); }

#startGame {
  min-height: 100dvh;
  background: radial-gradient(circle at 50% 46%, rgba(20,184,166,.2), transparent 42%);
}

#startGame h1 {
  margin-top: clamp(60px, 9vh, 100px);
  font-size: clamp(32px, 6vh, 66px);
  letter-spacing: .06em;
  color: #fff7d6;
  text-shadow: 0 5px 18px #000, 0 0 30px rgba(246,196,83,.3);
}

.startGameBot, .startGameHuman {
  border: 2px solid rgba(246,196,83,.74);
  box-shadow: 0 12px 32px #000, 0 0 22px rgba(246,196,83,.2);
}

#startGameButton {
  width: clamp(120px, 19vh, 210px);
  height: clamp(52px, 8vh, 82px);
  margin: 2vh;
  border: 1px solid rgba(103,232,249,.65);
  border-radius: 999px;
  background: linear-gradient(135deg, #0f766e, #0369a1, #6d28d9);
  box-shadow: 0 14px 35px rgba(0,0,0,.45), 0 0 25px rgba(34,211,238,.25);
  font-size: clamp(27px, 5vh, 48px) !important;
}

#truco-wallet, #truco-bet-panel, #truco-exit {
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
}

#truco-wallet {
  top: calc(8px + var(--safe-top));
  left: 8px;
  right: auto;
  border-color: rgba(54,217,232,.55);
  border-radius: 13px;
  background: linear-gradient(145deg, rgba(8,20,31,.9), rgba(1,8,14,.92));
}

#truco-exit {
  top: calc(8px + var(--safe-top));
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(145deg, rgba(70,15,24,.92), rgba(20,4,8,.94));
}

#truco-bet-panel {
  right: auto;
  left: 50%;
  bottom: calc(10px + var(--safe-bottom));
  width: min(430px, calc(100vw - 20px));
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-radius: 17px;
  background: linear-gradient(145deg, rgba(7,22,30,.95), rgba(2,8,14,.97));
}

#truco-bet-title, #truco-bet-message { grid-column: 1 / -1; }
#truco-bet-select, #truco-bet-submit { min-height: 42px; border-radius: 11px; }
#truco-bet-submit { background: linear-gradient(135deg, #f6c453, #f59e0b); }

#gameOverModalOverlay, #roundOverModalOverlay, #infoModal { z-index: 2147483000; }
#modal, #roundOverModal, #infoText {
  border: 1px solid rgba(246,196,83,.45);
  border-radius: 22px;
  background: rgba(3,12,20,.9);
  box-shadow: 0 25px 70px rgba(0,0,0,.65);
}

@media (max-width: 600px) {
  .sideColumn { display: none; }
  .gameContainer { width: 100vw; padding: max(5px, .7vh); border: 0; }
  .gameContainer::after { inset: 14% 1% 15%; }
  .hand { height: clamp(92px, 14.2vh, 126px); }
  .card { width: clamp(49px, 8.9vh, 72px); }
  .actionButtonsRow { align-items: flex-start; }
  .actionButtons { width: auto; padding-top: 3px; gap: 4px; margin-bottom: max(1.5vh, var(--safe-bottom)); }
  .twoButtons { width: min(25vw, 96px); height: 10vh; }
  .fourButtons { width: min(24vw, 90px); height: 5vh; }
  .sixButtons, .nineButtons { width: min(20vw, 72px); min-height: 34px; }
  .speech-bubble-container { width: clamp(88px, 15vh, 122px); }
  .speech-bubble-text { width: clamp(98px, 16vh, 132px); }
  #truco-wallet {
    top: calc(4px + var(--safe-top));
    left: 50%;
    right: auto;
    min-width: 118px;
    max-width: calc(100vw - 210px);
    transform: translateX(-50%);
  }
  #truco-wallet-user, #truco-wallet-coins {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #truco-exit { top: calc(4px + var(--safe-top)); right: 4px; width: 92px; height: 38px; }
  #truco-bet-panel { bottom: calc(5px + var(--safe-bottom)); padding: 8px; gap: 6px; }
  #startGame h1 { margin-top: calc(58px + var(--safe-top)); }
  .vsContainer { margin-top: 2vh; }
  .landingContent { width: 100%; align-items: center; }
}

@media (max-width: 600px) and (orientation: portrait) {
  html, body, #root, #startGame, .viewportContainer, .gameContainer {
    width: 100vw;
    width: 100dvw;
    height: 100vh;
    height: 100dvh;
    min-height: 100dvh;
    max-height: 100dvh;
  }

  body { position: fixed; inset: 0; }

  /* Cabecera reservada: el HUD ya no pisa al bot ni sus cantos. */
  .gameContainer {
    padding-top: calc(54px + var(--safe-top));
  }

  #truco-wallet, #truco-exit {
    z-index: 2147483647;
  }
}

@media (max-height: 650px) and (orientation: landscape) {
  .gameContainer { width: min(100vw, 96vh); padding: 3px 8px; }
  .hand { height: 15vh; }
  .card { width: 9vh; }
  .actionButtons { margin-bottom: 1vh; }
  #startGame h1 { margin-top: 2vh; font-size: 8vh; }
  .vsContainer { margin-top: .5vh; }
  .startGameBot, .startGameHuman { height: 14vh; }
  #startGameButton { width: 24vh; height: 11vh; margin: 1vh; }
  #info_link { margin-top: .5vh; }
  #truco-bet-panel {
    right: 8px;
    left: auto;
    bottom: calc(8px + var(--safe-bottom));
    width: min(245px, 31vw);
    transform: none;
  }
  #truco-wallet {
    left: 8px;
    right: auto;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
