:root{
  --felt:#0f6b3d;
  --felt-dark:#073b25;
  --felt-light:#168d52;
  --panel:rgba(5,30,20,.72);
  --line:rgba(255,255,255,.14);
  --text:#f7fff9;
  --muted:#c8ead7;
  --gold:#ffd166;
  --gold2:#f59f00;
  --shadow:0 20px 60px rgba(0,0,0,.45);
  --card-width:clamp(42px,7vw,96px);
  --pile-width:clamp(64px,9vw,110px);
}

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

html,
body{
  width:100%;
  max-width:100%;
  min-height:100vh;
  overflow-x:hidden;
  color:var(--text);
  font-family:"Space Grotesk",sans-serif;
  background:
    radial-gradient(circle at top,#22a462 0%,var(--felt) 34%,var(--felt-dark) 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:clamp(10px,2vw,20px);
}

.topbar{
  display:grid;
  grid-template-columns:auto 1fr auto;
  gap:14px;
  align-items:center;
  background:var(--panel);
  border:1px solid var(--line);
  border-radius:24px;
  padding:clamp(12px,2vw,20px);
  backdrop-filter:blur(16px);
  box-shadow:var(--shadow);
}

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

.topbar-center{
  text-align:center;
  min-width:0;
}

.game-title{
  font-size:clamp(1.65rem,4vw,3.2rem);
  font-weight:800;
  letter-spacing:-.04em;
}

.game-subtitle{
  margin-top:6px;
  color:var(--muted);
  font-size:clamp(.82rem,1.8vw,1rem);
}

.topbar-right{
  display:flex;
  justify-content:flex-end;
  gap:10px;
  flex-wrap:wrap;
}

.hud-btn{
  border:none;
  cursor:pointer;
  border-radius:14px;
  padding:11px 15px;
  color:#1b1200;
  background:linear-gradient(135deg,var(--gold),var(--gold2));
  font-weight:800;
  white-space:nowrap;
}

.hud{
  display:grid;
  grid-template-columns:repeat(3,minmax(0,1fr));
  gap:clamp(8px,1.5vw,16px);
}

.hud-card{
  background:var(--panel);
  border:1px solid var(--line);
  border-radius:20px;
  padding:clamp(10px,2vw,18px);
  backdrop-filter:blur(14px);
  box-shadow:var(--shadow);
}

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

.hud-value{
  display:block;
  margin-top:4px;
  font-size:clamp(1.35rem,3vw,2rem);
  font-weight:800;
}

.game-board{
  position:relative;
  background:
    radial-gradient(circle at center,
      #2ac977 0%,
      #179c59 18%,
      #0f7d48 38%,
      #0c643a 58%,
      #084b2c 100%);
  border:2px solid rgba(255,255,255,.12);
  border-radius:30px;
  padding:clamp(14px,3vw,34px) clamp(8px,2vw,24px) clamp(24px,4vw,40px);
  box-shadow:
    inset 0 2px 12px rgba(255,255,255,.08),
    inset 0 -10px 40px rgba(0,0,0,.32),
    0 20px 60px rgba(0,0,0,.45);
  overflow:hidden;
  min-width:0;
}

.game-board::before{
  content:"";
  position:absolute;
  inset:0;
  background:
    radial-gradient(circle at top,
      rgba(255,255,255,.10),
      transparent 40%),
    repeating-linear-gradient(
      45deg,
      rgba(255,255,255,.015) 0px,
      rgba(255,255,255,.015) 2px,
      transparent 2px,
      transparent 6px
    );
  pointer-events:none;
}

.game-board::after{
  content:"";
  position:absolute;
  inset:14px;
  border-radius:22px;
  border:1px solid rgba(255,255,255,.08);
  pointer-events:none;
}

.peaks-area{
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:clamp(8px,2.2vw,26px);
  width:100%;
  min-width:0;
}

.peak-row{
  display:flex;
  justify-content:center;
  gap:clamp(4px,1vw,14px);
  width:100%;
  min-width:0;
}

.card-slot{
  width:var(--card-width);
  aspect-ratio:5/7;
  border-radius:clamp(8px,1.4vw,18px);
  position:relative;
  flex:0 1 var(--card-width);
  min-width:0;
}

.card-slot.playable{
  cursor:pointer;
}

.card-slot.playable:hover{
  transform:translateY(-5px);
}

.card-slot.covered::before{
  content:"";
  position:absolute;
  inset:0;
  border-radius:inherit;
  background-image:url("./cards/card_back.png");
  background-size:cover;
  background-position:center;
  box-shadow:0 10px 24px rgba(0,0,0,.45);
}

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

.bottom-area{
  margin-top:clamp(22px,4vw,40px);
  display:flex;
  justify-content:center;
}

.deck-section{
  display:flex;
  align-items:flex-start;
  justify-content:center;
  gap:clamp(24px,7vw,70px);
  flex-wrap:wrap;
}

.pile-group{
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:10px;
}

.pile-label{
  color:var(--muted);
  font-weight:800;
  letter-spacing:.05em;
  text-transform:uppercase;
  font-size:.78rem;
}

.card-pile{
  width:var(--pile-width);
  aspect-ratio:5/7;
  border:none;
  border-radius:clamp(10px,1.5vw,20px);
  background:transparent;
  position:relative;
}

.stock-pile{
  cursor:pointer;
}

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

.waste-pile{
  background:rgba(0,0,0,.16);
  border:2px dashed rgba(255,255,255,.24);
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:hidden;
}

.empty-waste{
  color:var(--muted);
  text-align:center;
  padding:10px;
  font-size:.85rem;
}

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

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

.howto-panel{
  width:min(720px,100%);
  background:linear-gradient(180deg,#0f6b3d,#073b25);
  border:1px solid var(--line);
  border-radius:26px;
  padding:24px;
  box-shadow:var(--shadow);
}

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

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

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

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

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

  .topbar-left,
  .topbar-right{
    display:flex;
    justify-content:center;
  }
}

@media (max-width:720px){
  :root{
    --card-width:clamp(30px,8.6vw,58px);
    --pile-width:clamp(58px,18vw,82px);
  }

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

  .hud-card{
    text-align:center;
  }

  .game-board{
    border-radius:22px;
  }

  .game-subtitle{
    display:none;
  }
}

@media (max-width:430px){
  :root{
    --card-width:clamp(26px,8.4vw,38px);
    --pile-width:64px;
  }

  .game-shell{
    padding:8px;
  }

  .topbar{
    border-radius:18px;
  }

  .hud{
    gap:6px;
  }

  .hud-card{
    border-radius:14px;
    padding:8px 6px;
  }

  .hud-label{
    font-size:.68rem;
  }

  .hud-value{
    font-size:1.1rem;
  }

  .peak-row{
    gap:3px;
  }

  .deck-section{
    gap:20px;
  }
}

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