*{
  box-sizing:border-box;
  margin:0;
  padding:0;
  font-family:"Space Grotesk",sans-serif;
}

html,
body{
  width:100%;
  min-height:100%;
  overflow-x:hidden;
  background:radial-gradient(circle at top,#16385f 0%,#07172b 52%,#020611 100%);
  color:white;
}

body{
  min-height:100vh;
}

button,
a{
  font-family:inherit;
}

.game-shell{
  min-height:100vh;
  display:flex;
  flex-direction:column;
}

.top-bar{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:16px;
  padding:14px 20px;
  background:rgba(0,0,0,.36);
  border-bottom:1px solid rgba(255,255,255,.08);
  backdrop-filter:blur(14px);
  position:sticky;
  top:0;
  z-index:100;
}

.top-left{
  display:flex;
  align-items:center;
  gap:24px;
  flex:1;
}

.title-wrap h1{
  font-size:clamp(1.35rem,3vw,2.45rem);
  letter-spacing:.12em;
}

.subtitle{
  opacity:.72;
  margin-top:5px;
}

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

.top-btn{
  min-height:48px;
  border:none;
  border-radius:999px;
  padding:12px 20px;
  background:linear-gradient(180deg,rgba(255,255,255,.18),rgba(255,255,255,.08));
  color:white;
  text-decoration:none;
  font-size:1rem;
  font-weight:900;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  box-shadow:0 10px 24px rgba(0,0,0,.28);
}

.hud{
  display:grid;
  grid-template-columns:repeat(3,1fr);
  gap:12px;
  padding:14px 20px 0;
}

.hud-card,
.status-box,
.rack-wrap{
  padding:10px;
  border-radius:20px;
  background:linear-gradient(180deg,rgba(255,255,255,.12),rgba(255,255,255,.045));
  border:1px solid rgba(255,255,255,.09);
}

.hud-label,
.rack-label{
  font-size:.82rem;
  text-transform:uppercase;
  letter-spacing:.08em;
  opacity:.7;
  margin-bottom:8px;
  font-weight:1000;
}

.hud-value{
  font-size:1.2rem;
  font-weight:1000;
}

.game-area{
  flex:1;
  display:grid;
  grid-template-columns:minmax(320px,620px) minmax(260px,340px);
  justify-content:center;
  align-items:start;
  gap:20px;
  padding:20px;
}

.board-panel{
  display:flex;
  justify-content:center;
}

.stack-board{
  width:min(78vw,560px);
  aspect-ratio:1;
  display:grid;
  grid-template-columns:repeat(10,1fr);
  grid-template-rows:repeat(10,1fr);
  gap:4px;
  padding:14px;
  border-radius:28px;
  background:
    radial-gradient(circle at top,rgba(255,255,255,.14),transparent 35%),
    linear-gradient(135deg,#1b75bc,#0a3d72 58%,#041a33);
  border:1px solid rgba(255,255,255,.12);
  box-shadow:
    0 28px 70px rgba(0,0,0,.5),
    inset 0 0 0 10px rgba(0,0,0,.16);
}

.board-cell{
  position:relative;
  border:none;
  border-radius:10px;
  background:linear-gradient(180deg,#b9dfff,#5e95ce);
  color:#07172b;
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight:1000;
  cursor:pointer;
  overflow:hidden;
}

.board-cell.preview{
  outline:4px solid rgba(255,243,109,.95);
}

.stack-height{
  position:absolute;
  top:3px;
  right:5px;
  font-size:.62rem;
  font-weight:1000;
  color:#07172b;
  opacity:.85;
}

.tile,
.stack-tile{
  width:86%;
  height:86%;
  border:none;
  border-radius:11px;
  background:linear-gradient(180deg,#fff4cf,#e3be78);
  color:#1a1207;
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight:1000;
  font-size:1.2rem;
  box-shadow:
    inset 0 5px 8px rgba(255,255,255,.5),
    inset 0 -5px 8px rgba(0,0,0,.18),
    0 6px 10px rgba(0,0,0,.28);
  user-select:none;
  position:relative;
}

.tile{
  cursor:pointer;
}

.tile.selected{
  outline:4px solid #fff36d;
  transform:translateY(-8px) scale(1.08);
  box-shadow:
    0 0 22px rgba(255,243,109,.85),
    inset 0 5px 8px rgba(255,255,255,.5),
    inset 0 -5px 8px rgba(0,0,0,.18),
    0 6px 10px rgba(0,0,0,.28);
}

.tile-score{
  position:absolute;
  right:6px;
  bottom:4px;
  font-size:.62rem;
}

.control-panel{
  display:flex;
  flex-direction:column;
  gap:14px;
}

.status-box{
  line-height:1.5;
  font-weight:900;
}

.tile-rack{
  min-height:72px;
  display:grid;
  grid-template-columns:repeat(7,1fr);
  gap:8px;
}

.action-grid{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:10px;
}

.action-btn{
  min-height:54px;
  border:none;
  border-radius:18px;
  background:linear-gradient(180deg,#7effc8,#1fb487);
  color:#041a17;
  font-weight:1000;
  font-size:1rem;
  cursor:pointer;
  box-shadow:0 12px 24px rgba(0,0,0,.28);
}

.action-btn.secondary{
  background:linear-gradient(180deg,rgba(255,255,255,.18),rgba(255,255,255,.08));
  color:white;
}

.instructions-overlay{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.78);
  display:flex;
  align-items:center;
  justify-content:center;
  padding:18px;
  z-index:999;
}

.hidden{
  display:none;
}

.instructions-modal{
  width:min(94vw,820px);
  max-height:86vh;
  overflow:auto;
  border-radius:28px;
  background:
    radial-gradient(circle at top,rgba(126,255,200,.18),transparent 40%),
    #07172b;
  border:1px solid rgba(255,255,255,.12);
  padding:28px;
  position:relative;
}

.instructions-modal h2{
  margin-bottom:18px;
}

.instructions-content{
  display:flex;
  flex-direction:column;
  gap:18px;
  line-height:1.7;
}

.instructions-content ul{
  padding-left:22px;
}

.close-btn{
  position:absolute;
  top:18px;
  right:18px;
  width:42px;
  height:42px;
  border:none;
  border-radius:50%;
  font-weight:1000;
  cursor:pointer;
}

@media (max-width:980px){
  .game-area{
    grid-template-columns:1fr;
    gap:12px;
  }

  .control-panel{
    width:min(94vw,620px);
    margin:0 auto;
  }

  .stack-board{
    width:min(94vw,520px);
  }
}

@media (max-width:720px){
  .top-bar{
    flex-direction:column;
    align-items:flex-start;
  }

  .top-left{
    width:100%;
    flex-wrap:wrap;
    gap:14px;
  }

  .top-actions{
    width:100%;
  }

  .top-btn{
    flex:1;
  }

  .hud{
    grid-template-columns:1fr;
    padding:12px 14px 0;
  }

  .game-area{
    padding:14px;
  }

  .stack-board{
    gap:3px;
    padding:9px;
    border-radius:20px;
  }

  .board-cell{
    border-radius:7px;
  }

  .tile,
  .stack-tile{
    border-radius:7px;
    font-size:1rem;
  }

  .tile-score{
    font-size:.48rem;
    right:3px;
    bottom:2px;
  }

  .action-grid{
    grid-template-columns:1fr;
  }
}

.tile{
  touch-action:none;
  -webkit-user-select:none;
  user-select:none;
  cursor:grab;
}

.tile:active{
  cursor:grabbing;
}

.drag-ghost{
  position:fixed;
  z-index:99999;
  width:52px;
  height:52px;
  pointer-events:none;
  transform:translate(-50%,-50%) scale(1.12);
  opacity:.95;
  box-shadow:0 18px 38px rgba(0,0,0,.45),0 0 22px rgba(255,243,109,.8);
}

.board-cell.drop-target{
  outline:4px solid rgba(126,255,200,.95);
  transform:scale(.96);
}
