:root{
  --felt:#18a34a;
  --felt2:#0f7d39;
  --felt3:#074b22;

  --wood1:#6e4525;
  --wood2:#4a2d17;
  --wood3:#2f190b;

  --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,90px);
}

*{
  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;
}

.peg-board-wrap,
.center-zone,
.cpu-area,
.player-area{
  position:relative;
  z-index:2;
}

.peg-board-wrap{
  background:
    linear-gradient(
      180deg,
      var(--wood1),
      var(--wood2)
    );

  border-radius:28px;

  padding:22px;

  border:2px solid rgba(255,255,255,.08);

  box-shadow:
    inset 0 2px 4px rgba(255,255,255,.12),
    inset 0 -10px 18px rgba(0,0,0,.25),
    0 14px 32px rgba(0,0,0,.28);

  margin-bottom:26px;
}

.peg-board-header{
  display:flex;
  justify-content:space-between;
  align-items:center;

  margin-bottom:14px;

  color:#fff7e6;

  font-weight:900;

  letter-spacing:.06em;

  text-transform:uppercase;
}

.peg-board{
  display:flex;
  flex-direction:column;
  gap:16px;
}

.peg-lane{
  position:relative;

  height:24px;

  border-radius:999px;

  background:
    linear-gradient(
      180deg,
      #1f1209,
      #120903
    );

  overflow:hidden;

  border:1px solid rgba(255,255,255,.08);
}

.peg{
  position:absolute;

  top:50%;
  left:0;

  width:28px;
  height:28px;

  transform:translate(-50%,-50%);

  border-radius:50%;

  transition:left .35s ease;

  box-shadow:
    0 2px 6px rgba(0,0,0,.45),
    inset 0 1px 2px rgba(255,255,255,.24);
}

.player-peg{
  background:
    radial-gradient(
      circle at 30% 30%,
      #fff1c2,
      #ffb703
    );
}

.cpu-peg{
  background:
    radial-gradient(
      circle at 30% 30%,
      #c9ecff,
      #2f80ed
    );
}

.peg-scale{
  display:flex;
  justify-content:space-between;

  margin-top:14px;

  color:#fff3dc;

  font-size:.82rem;

  font-weight:800;
}

.center-zone{
  display:flex;
  justify-content:center;
  align-items:flex-start;

  gap:clamp(18px,4vw,48px);

  flex-wrap:wrap;

  margin:34px 0;
}

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

.pile-box span{
  font-weight:900;

  letter-spacing:.05em;

  color:#f4fff6;
}

.starter-slot,
.crib-slot{
  width:clamp(76px,10vw,110px);

  aspect-ratio:5/7;

  border-radius:18px;

  position:relative;

  background:rgba(0,0,0,.22);

  border:2px dashed rgba(255,255,255,.16);
}

.pegging-pile{
  min-width:min(520px,92vw);

  min-height:140px;

  display:flex;
  align-items:center;
  justify-content:center;

  gap:10px;

  padding:16px;

  flex-wrap:wrap;

  border-radius:28px;

  border:2px dashed rgba(255,255,255,.16);

  background:rgba(0,0,0,.16);
}

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

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

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

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

  overflow-y:auto;

  -webkit-overflow-scrolling:touch;

  padding-right:10px;

  max-height:calc(86vh - 90px);
}

.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(40px,12vw,72px);
  }

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

  .pegging-pile{
    min-width:100%;
  }

}

@media (max-width:520px){

  :root{
    --card-width:clamp(30px,15vw,54px);
  }

  .game-shell{
    padding:8px;
  }

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

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

}
