/* style.css — all styling */
:root{
  color-scheme: dark;
  --bg: #15110d;
  --bg2: #1d1813;
  --panel: #221b14;
  --panel-2: #2a2218;
  --ink: #f3e7d3;
  --muted: #b09a7d;
  --line: rgba(255,255,255,0.08);
  --accent: #f3b04a;
  --accent-2: #e8893a;
  --ok: #8bd17c;
  --shadow: 0 10px 30px rgba(0,0,0,0.45);
}
html[data-theme="dark"]{ color-scheme: dark; }
html[data-theme="light"]{
  color-scheme: light;
  --bg: #f4ecdd;
  --bg2: #efe4cd;
  --panel: #ffffff;
  --panel-2: #f7efdf;
  --ink: #2a2014;
  --muted: #7a684c;
  --line: rgba(0,0,0,0.10);
  --accent: #d98a1f;
  --accent-2: #c66a1a;
  --shadow: 0 10px 30px rgba(80,55,20,0.18);
}
@media (prefers-color-scheme: light){
  :root{
    color-scheme: light;
    --bg: #f4ecdd; --bg2: #efe4cd;
    --panel: #ffffff; --panel-2: #f7efdf;
    --ink: #2a2014; --muted: #7a684c;
    --line: rgba(0,0,0,0.10);
    --accent: #d98a1f; --accent-2: #c66a1a;
    --shadow: 0 10px 30px rgba(80,55,20,0.18);
  }
}

*{ box-sizing: border-box; }
html,body{ margin:0; padding:0; height:100%; }
body{
  background: radial-gradient(120% 120% at 20% 0%, var(--bg2), var(--bg) 60%);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
}

.stage{
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 14px 16px;
  gap: 12px;
}

/* HUD */
.hud{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.hud-left h1{
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.hud-left .sub{
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}
.hud-right{ display: flex; align-items: center; gap: 8px; }
.progress{
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 13px;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 7px 12px;
  border-radius: 999px;
  color: var(--accent);
}
.btn{
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
}
.btn:hover{ background: var(--panel-2); }
.btn:active{ transform: translateY(1px); }
.btn.active{ border-color: var(--accent); color: var(--accent); }
.btn.ghost{ background: transparent; }

/* Play area */
.play{
  position: relative;
  flex: 1;
  display: flex;
  gap: 14px;
  min-height: 0;
}

/* Board */
.board{
  position: relative;
  flex: 0 0 auto;
  width: 256px;
  height: 256px;
  border-radius: 16px;
  background:
    linear-gradient(var(--panel), var(--panel)) padding-box,
    repeating-linear-gradient(45deg, rgba(255,255,255,0.03) 0 6px, transparent 6px 12px);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  align-self: center;
  overflow: hidden;
}
.board-label{
  position: absolute;
  top: 8px; left: 12px;
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.board-grid{
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  padding: 0;
}
.cell{
  border: 1px dashed rgba(255,255,255,0.07);
}
html[data-theme="light"] .cell,
:root:not([data-theme]) .cell{ border-color: rgba(0,0,0,0.07); }
.ghost{
  position: absolute;
  inset: 0;
  background-size: 256px 256px !important;
  opacity: 0.16;
  pointer-events: none;
  transition: opacity .25s ease;
}

/* Tray */
.tray{
  position: relative;
  flex: 1;
  min-width: 0;
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.03), rgba(0,0,0,0.05)),
    var(--panel-2);
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), var(--shadow);
  overflow: hidden;
}
.tray::before{
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(60% 50% at 80% 0%, rgba(243,176,74,0.08), transparent 70%);
  pointer-events: none;
}
.tray-label{
  position: absolute;
  top: 12px; left: 16px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}
.tray-label span{ color: var(--accent); }
.tray-hint{
  position: absolute;
  top: 14px; right: 16px;
  font-size: 11px;
  color: var(--muted);
  opacity: .8;
}

/* Pieces layer */
.pieces{
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.piece{
  position: absolute;
  left: 0; top: 0;
  pointer-events: auto;
  border-radius: 8px;
  touch-action: none;
  cursor: grab;
  box-shadow:
    0 1px 0 rgba(255,255,255,0.25) inset,
    0 -1px 0 rgba(0,0,0,0.25) inset,
    0 4px 10px rgba(0,0,0,0.35);
  border: 1px solid rgba(0,0,0,0.35);
  transition: box-shadow .15s ease, filter .15s ease;
  user-select: none;
  will-change: transform;
}
.piece:hover{ filter: brightness(1.06); }
.piece.dragging{
  cursor: grabbing;
  box-shadow:
    0 1px 0 rgba(255,255,255,0.3) inset,
    0 10px 24px rgba(0,0,0,0.5);
  filter: brightness(1.08);
}
.piece.placed{
  cursor: default;
  box-shadow:
    0 0 0 2px rgba(139,209,124,0.55),
    0 1px 0 rgba(255,255,255,0.2) inset;
  border-color: rgba(0,0,0,0.4);
}
.piece.just-placed{
  animation: pop .5s ease;
}
@keyframes pop{
  0%{ box-shadow: 0 0 0 0 rgba(139,209,124,0.0); }
  40%{ box-shadow: 0 0 0 8px rgba(139,209,124,0.5); }
  100%{ box-shadow: 0 0 0 2px rgba(139,209,124,0.55); }
}

/* Win overlay */
.win{
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: radial-gradient(80% 80% at 50% 40%, rgba(0,0,0,0.55), rgba(0,0,0,0.78));
  z-index: 50;
  backdrop-filter: blur(2px);
}
.win.show{ display: flex; animation: fade .3s ease; }
@keyframes fade{ from{ opacity:0; } to{ opacity:1; } }
.win-card{
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 32px;
  text-align: center;
  box-shadow: var(--shadow);
  max-width: 320px;
}
.win-emoji{ font-size: 44px; line-height: 1; }
.win-card h2{ margin: 10px 0 6px; font-size: 18px; }
.win-card p{ margin: 0 0 16px; color: var(--muted); font-size: 13px; }

.confetti{
  position: absolute;
  top: -30px;
  animation: fall 2.6s linear forwards;
  pointer-events: none;
}
@keyframes fall{
  to{ transform: translateY(110vh) rotate(540deg); opacity: .9; }
}

/* Responsive */
@media (max-width: 640px){
  .stage{ padding: 10px; gap: 10px; }
  .hud-left h1{ font-size: 17px; }
  .hud-left .sub{ font-size: 11.5px; }
  .play{ flex-direction: column; align-items: stretch; gap: 10px; }
  .board{ align-self: center; }
  .tray{ min-height: 220px; flex: 1 1 auto; }
}
@media (max-height: 560px) and (min-width: 641px){
  .hud-left .sub{ display: none; }
}
