:root{
  --felt:#18a34a;
  --felt2:#0f7d39;
  --felt3:#074b22;
  --panel:rgba(0,0,0,.24);
  --line:rgba(255,255,255,.12);
  --text:#f8fff9;
  --muted:#d7f5df;
  --gold:#ffd166;
  --gold2:#f59f00;
  --shadow:0 24px 70px rgba(0,0,0,.45);
  --card-width:clamp(52px,7vw,88px);
}

*{
  box-sizing:border-box;
  margin:0;
  padding:0;
}

html,
body{
  width:100%;
  max-width:100%;
  min-height:100vh;
  overflow-x:hidden;
  font-family:"Space Grotesk",sans-serif;
  color:var(--text);
  background:
    radial-gradient(circle at center,
      #2fe37a 0%,
      var(--felt) 24%,
      var(--felt2) 58%,
      var(--felt3) 100%);
}

body{
  touch-action:manipulation;
}

button{
  font-family:inherit;
}

.game-shell{
  width:min(1700px,100%);
  margin:0 auto;
  padding:clamp(10px,2vw,20px);
  display:flex;
  flex-direction:column;
  gap:18px;
}

.topbar{
  display:grid;
  grid-template-columns:auto 1fr auto;
  gap:16px;
  align-items:center;
  background:rgba(0,0,0,.22);
  border:1px solid var(--line);
  border-radius:24px;
  padding:18px;
  backdrop-filter:blur(14px);
  box-shadow:var(--shadow);
}

.back-btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  padding:12px 16px;
  border-radius:14px;
  text-decoration:none;
  color:#fff;
  background:rgba(0,0,0,.26);
  border:1px solid var(--line);
}

.title-wrap{
  text-align:center;
}

.title-wrap h1{
  font-size:clamp(2rem,5vw,3.5rem);
  font-weight:900;
  letter-spacing:-.05em;
}

.title-wrap p{
  margin-top:6px;
  color:var(--muted);
}

.top-actions{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  justify-content:flex-end;
}

.game-btn{
  border:none;
  border-radius:14px;
  padding:12px 18px;
  font-weight:800;
  cursor:pointer;
  color:#1d1200;
  background:
    linear-gradient(
      135deg,
      var(--gold),
      var(--gold2)
    );
}

.hud{
  display:grid;
  grid-template-columns:repeat(4,minmax(0,1fr));
  gap:14px;
}

.hud-card{
  background:rgba(0,0,0,.22);
  border:1px solid var(--line);
  border-radius:20px;
  padding:16px;
  text-align:center;
  backdrop-filter:blur(10px);
  box-shadow:var(--shadow);
}

.hud-card span{
  display:block;
  color:var(--muted);
  font-size:.82rem;
}

.hud-card strong{
  display:block;
  margin-top:8px;
  font-size:clamp(1.2rem,3vw,2rem);
}

.table-area{
  position:relative;
  background:
    radial-gradient(circle at center,
      #37ef81 0%,
      #18b358 20%,
      #0d8a42 54%,
      #065428 100%);
  border-radius:36px;
  padding:clamp(16px,3vw,34px);
  border:2px solid rgba(255,255,255,.14);
  box-shadow:
    inset 0 2px 10px rgba(255,255,255,.14),
    inset 0 -20px 50px rgba(0,0,0,.22),
    var(--shadow);
  overflow:hidden;
}

.table-area::before{
  content:"";
  position:absolute;
  inset:0;
  background:
    repeating-linear-gradient(
      45deg,
      rgba(255,255,255,.012) 0px,
      rgba(255,255,255,.012) 2px,
      transparent 2px,
      transparent 6px
    );
  pointer-events:none;
}

.cpu-top,
.player-area{
  position:relative;
  z-index:2;
}

.cpu-top h2,
.player-area h2,
.cpu-side h2{
  text-align:center;
  margin-bottom:14px;
  font-size:1.2rem;
}

.middle-row{
  display:grid;
  grid-template-columns:auto 1fr auto;
  align-items:center;
  gap:20px;
  margin:30px 0;
}

.play-area{
  display:flex;
  justify-content:center;
  align-items:center;
}

.trick-center{
  width:min(420px,100%);
  min-height:220px;
  border-radius:28px;
  border:2px dashed rgba(255,255,255,.16);
  background:rgba(0,0,0,.16);
  display:flex;
  justify-content:center;
  align-items:center;
  gap:14px;
  flex-wrap:wrap;
  padding:18px;
}

.cpu-hand.horizontal,
.player-hand{
  display:flex;
  justify-content:center;
  gap:clamp(3px,1vw,10px);
}

.cpu-hand.vertical{
  display:flex;
  flex-direction:column;
  gap:4px;
}

.card{
  width:var(--card-width);
  aspect-ratio:5/7;
  border-radius:16px;
  position:relative;
  border:none;
  background:none;
  cursor:pointer;
  transition:
    transform .16s ease,
    box-shadow .16s ease;
}

.card:hover{
  transform:translateY(-8px);
}

.card.selected{
  transform:translateY(-18px);
}

.card.selected::after{
  content:"SELECTED";
  position:absolute;
  left:50%;
  bottom:-32px;
  transform:translateX(-50%);
  padding:5px 10px;
  border-radius:999px;
  background:#ffd166;
  color:#000;
  font-size:.72rem;
  font-weight:900;
  letter-spacing:.08em;
}

.card-face{
  position:absolute;
  inset:0;
  border-radius:16px;
  overflow:hidden;
  background-image:url("./cards/cards.png");
  background-repeat:no-repeat;
  background-size:1300% 400%;
  box-shadow:0 12px 28px rgba(0,0,0,.45);
}

.card-back{
  position:absolute;
  inset:0;
  border-radius:16px;
  background-image:url("./cards/card_back.png");
  background-size:cover;
  background-position:center;
  box-shadow:0 12px 28px rgba(0,0,0,.45);
}

.controls{
  display:flex;
  justify-content:center;
  gap:14px;
  flex-wrap:wrap;
}

.primary-btn{
  border:none;
  border-radius:16px;
  padding:14px 22px;
  cursor:pointer;
  font-weight:900;
  color:#000;
  background:
    linear-gradient(
      135deg,
      #ffe08a,
      #ffb703
    );
}

.howto-overlay{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.7);
  backdrop-filter:blur(10px);
  display:none;
  align-items:center;
  justify-content:center;
  z-index:1000;
  padding:20px;
}

.howto-overlay.open{
  display:flex;
}

.howto-panel{
  width:min(720px,100%);
  background:
    linear-gradient(
      180deg,
      #13914a,
      #074624
    );
  border-radius:28px;
  border:1px solid rgba(255,255,255,.14);
  padding:28px;
  box-shadow:var(--shadow);
}

.howto-header{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:16px;
}

.close-howto{
  width:46px;
  height:46px;
  border:none;
  border-radius:14px;
  background:rgba(0,0,0,.26);
  color:#fff;
  cursor:pointer;
  font-size:1.2rem;
}

.howto-content{
  margin-top:18px;
}

.howto-content p{
  margin-bottom:16px;
  line-height:1.6;
}

.howto-content ul{
  padding-left:22px;
  display:flex;
  flex-direction:column;
  gap:12px;
  line-height:1.5;
}

@media (max-width:1050px){

  .topbar{
    grid-template-columns:1fr;
    text-align:center;
  }

  .top-actions{
    justify-content:center;
  }

  .middle-row{
    grid-template-columns:1fr;
  }

  .cpu-hand.vertical{
    flex-direction:row;
    justify-content:center;
  }

}

@media (max-width:820px){

  :root{
    --card-width:clamp(38px,11vw,68px);
  }

  .hud{
    grid-template-columns:repeat(2,minmax(0,1fr));
  }

}

@media (max-width:520px){

  :root{
    --card-width:clamp(30px,14vw,52px);
  }

  .game-shell{
    padding:8px;
  }

  .cpu-hand.horizontal,
  .player-hand{
    gap:2px;
  }

}

.howto-panel{
  max-height:min(86vh,760px);
  overflow:hidden;
  display:flex;
  flex-direction:column;
}

.howto-header{
  flex:0 0 auto;
  position:sticky;
  top:0;
  z-index:5;
}

.howto-content{
  overflow-y:auto;
  -webkit-overflow-scrolling:touch;
  padding-right:10px;
  max-height:calc(86vh - 90px);
}

@media (max-width:520px){
  .howto-overlay{
    align-items:flex-start;
    padding:10px;
    overflow-y:auto;
  }

  .howto-panel{
    max-height:92vh;
    width:100%;
    padding:18px;
    border-radius:20px;
  }

  .howto-content{
    max-height:calc(92vh - 82px);
  }

  .close-howto{
    flex:0 0 auto;
  }
}


.card-corner-helper{
  position:absolute;
  top:4px;
  left:4px;
  z-index:50;
  min-width:22px;
  padding:3px 5px;
  border-radius:8px;
  background:rgba(255,255,255,.96);
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  font-size:clamp(.56rem,1vw,.82rem);
  font-weight:900;
  line-height:1;
  box-shadow:0 2px 6px rgba(0,0,0,.22);
  pointer-events:none;
}

.card-corner-helper.red{
  color:#d3152a;
}

.card-corner-helper.black{
  color:#111;
}

.card-corner-helper .suit{
  margin-top:2px;
}
