: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;
  --danger:#ff3b5c;
  --shadow:0 24px 70px rgba(0,0,0,.45);
  --card-width:clamp(82px,13vw,140px);
}

*{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(1500px,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(1rem,2.5vw,1.65rem);
}

.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;
  display:grid;
  grid-template-columns:1fr minmax(260px,480px) 1fr;
  gap:clamp(14px,3vw,34px);
  align-items:center;
}

.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-area,
.center-area,
.player-area{
  position:relative;
  z-index:2;
  text-align:center;
}

.cpu-area h2,
.player-area h2{
  margin-bottom:12px;
  font-size:1.25rem;
}

.stock-stack{
  width:var(--card-width);
  aspect-ratio:5/7;
  margin:0 auto;
  border-radius:18px;
  position:relative;
}

.stock-stack strong{
  position:absolute;
  right:-12px;
  bottom:-12px;
  z-index:5;
  color:#000;
  background:var(--gold);
  border-radius:999px;
  padding:8px 12px;
  font-weight:900;
}

.center-area{
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:18px;
}

.reaction-banner{
  min-height:44px;
  padding:12px 18px;
  border-radius:999px;
  background:rgba(0,0,0,.25);
  border:1px solid rgba(255,255,255,.14);
  font-weight:900;
  letter-spacing:.04em;
}

.reaction-banner.jack{
  background:linear-gradient(135deg,#ffe08a,#ffb703);
  color:#1d1200;
  animation:pulse .45s ease infinite alternate;
}

.slap-zone{
  width:clamp(136px,22vw,220px);
  aspect-ratio:5/7;
  border:none;
  border-radius:24px;
  background:rgba(0,0,0,.18);
  cursor:pointer;
  position:relative;
  box-shadow:0 18px 44px rgba(0,0,0,.38);
}

.pile-card{
  position:absolute;
  inset:0;
  border-radius:24px;
}

.empty-pile{
  height:100%;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:18px;
  color:var(--muted);
  font-weight:900;
}

.last-play{
  color:var(--muted);
  font-weight:800;
}

.card{
  width:100%;
  aspect-ratio:5/7;
  border-radius:18px;
  position:relative;
  border:none;
  background:none;
}

.card-face{
  position:absolute;
  inset:0;
  border-radius:18px;
  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:18px;
  background-image:url("./cards/card_back.png");
  background-size:cover;
  background-position:center;
  box-shadow:0 12px 28px rgba(0,0,0,.45);
}

.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}

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

.primary-btn,
.secondary-btn{
  border:none;
  border-radius:16px;
  padding:14px 24px;
  cursor:pointer;
  font-weight:900;
}

.primary-btn{
  color:#000;
  background:linear-gradient(135deg,#ffe08a,#ffb703);
}

.secondary-btn{
  color:#fff;
  background:linear-gradient(135deg,#ff4566,#b81235);
  border:1px solid rgba(255,255,255,.14);
}

.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;
  overflow-y:auto;
}

.howto-overlay.open{display:flex}

.howto-panel{
  width:min(760px,100%);
  max-height:min(86vh,760px);
  overflow:hidden;
  display:flex;
  flex-direction:column;
  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;
  flex:0 0 auto;
  position:sticky;
  top:0;
  z-index:5;
}

.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;
  overflow-y:auto;
  -webkit-overflow-scrolling:touch;
  max-height:calc(86vh - 90px);
  padding-right:10px;
}

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

.howto-content h3{
  margin:20px 0 10px;
}

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

@keyframes pulse{
  from{transform:scale(1)}
  to{transform:scale(1.06)}
}

@media (max-width:1050px){
  .topbar{
    grid-template-columns:1fr;
    text-align:center;
  }

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

  .table-area{
    grid-template-columns:1fr;
  }
}

@media (max-width:820px){
  .hud{
    grid-template-columns:repeat(2,minmax(0,1fr));
  }
}

@media (max-width:520px){
  :root{
    --card-width:clamp(64px,20vw,86px);
  }

  .game-shell{
    padding:8px;
  }

  .table-area{
    gap:12px;
    border-radius:24px;
  }

  .title-wrap p{
    display:none;
  }

  .primary-btn,
  .secondary-btn{
    padding:12px 16px;
    font-size:.9rem;
  }

  .howto-overlay{
    align-items:flex-start;
    padding:10px;
  }

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

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