: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(54px,8vw,92px);
}

*{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(1650px,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;
}

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

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

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

.center-area{
  margin:34px 0;
  display:flex;
  justify-content:center;
  align-items:center;
  gap:clamp(18px,4vw,48px);
  flex-wrap:wrap;
}

.stock-box{
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:10px;
  color:var(--muted);
  font-weight:900;
  text-transform:uppercase;
  letter-spacing:.05em;
  font-size:.82rem;
}

.stock-pile,
.center-pile{
  width:clamp(74px,10vw,112px);
  aspect-ratio:5/7;
  border-radius:18px;
  position:relative;
  border:none;
  background:rgba(0,0,0,.18);
  box-shadow:0 12px 28px rgba(0,0,0,.35);
}

.clickable-stock,
.center-pile{
  cursor:pointer;
}

.stock-pile strong{
  position:absolute;
  right:-10px;
  bottom:-10px;
  background:#ffd166;
  color:#000;
  border-radius:999px;
  padding:7px 10px;
  font-weight:900;
  z-index:5;
}

.speed-piles{
  display:flex;
  gap:clamp(16px,3vw,34px);
  align-items:center;
  justify-content:center;
  padding:18px;
  border-radius:28px;
  border:2px dashed rgba(255,255,255,.16);
  background:rgba(0,0,0,.16);
}

.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,filter .16s ease;
}

.card:hover{transform:translateY(-8px)}
.card.playable{box-shadow:0 0 0 3px rgba(255,209,102,.9),0 12px 28px rgba(0,0,0,.45)}

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

.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 22px;
  cursor:pointer;
  font-weight:900;
}

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

.secondary-btn{
  color:#fff;
  background:rgba(0,0,0,.28);
  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;
  flex:0 0 auto;
}

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

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

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

@media (max-width:820px){
  :root{
    --card-width:clamp(42px,13vw,72px);
  }

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

@media (max-width:520px){
  :root{
    --card-width:clamp(32px,15vw,54px);
  }

  .game-shell{
    padding:8px;
  }

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

  .speed-piles{
    padding:10px;
  }

  .controls{
    gap:8px;
  }

  .primary-btn,
  .secondary-btn{
    padding:12px 14px;
    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);
  }
}
