/* Habibi — daily BlockBlast. Grayscale "Habibi" palette; amber only on the
   wordmark. Mobile-first; the layout never needs to grow past a phone column. */

:root {
  --white: #ffffff;
  --g50: #f4f4f3;
  --g100: #e4e4e2;
  --g200: #c9c9c5;
  --g400: #9a9a95;
  --g600: #6b6b66;
  --g700: #454542;
  --g800: #262625;
  --black: #0f0f0e;
  --amber: #ffa63d; /* wordmark/logo ONLY */

  --gap: 4px;
  --radius: 5px;
  --tray-cell: 26px;

  --maxw: 460px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--g50);
  color: var(--g700);
  font-family: "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 14px 14px 0;
}

/* ---- header ---- */
.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 10px;
}
.brand { line-height: 1; }
.wordmark {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--amber); /* the one saturated element */
}
.tagline {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--g400);
  margin-top: 3px;
}
.stats { text-align: right; line-height: 1.2; }
.elo-row { font-size: 12px; color: var(--g400); }
#elo-value { font-size: 20px; font-weight: 800; color: var(--g800); display: block; white-space: nowrap; }
#streak { font-size: 12px; color: var(--g600); min-height: 14px; }

.chances {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin-top: 6px;
}
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--g200);
}
.dot.live { background: var(--g800); }
.dot.spent { background: var(--g100); box-shadow: inset 0 0 0 1px var(--g200); }

/* free-play page (/habibi/play): no ELO/chances/streak */
body.freeplay #chances,
body.freeplay #streak { display: none; }

/* pieces inspector (/habibi/pieces): hide the game, lay out the catalog */
body.pieces #board,
body.pieces #chances,
body.pieces #streak,
body.pieces .controls,
body.pieces #scrubber,
body.pieces #scrub-hint,
body.pieces .daily-cta { display: none; }
body.pieces #status { margin: 4px 0 14px; }
body.pieces #tray {
  align-items: flex-start;
  justify-content: flex-start;
  gap: 16px 12px;
  min-height: 0;
}
.piece-card { display: flex; flex-direction: column; align-items: center; }
.piece-id { font-size: 11px; color: var(--g400); margin-bottom: 3px; }

/* ---- board ---- */
#board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-auto-rows: 1fr;
  gap: var(--gap);
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: var(--gap);
  background: var(--g100);
  border-radius: 12px;
  touch-action: none;
  user-select: none;
}
.cell {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: inset 0 0 0 1px var(--g100);
  transition: background 0.12s ease, transform 0.12s ease;
}
.cell.filled {
  background: var(--g800);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18);
}
/* the piece just placed in a View Solution replay, until the next one lands */
.cell.sol-current {
  background: var(--amber);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18);
}
.cell.preview-ok { background: var(--g400); }
.cell.preview-bad {
  background: repeating-linear-gradient(
    45deg, var(--g200), var(--g200) 3px, transparent 3px, transparent 6px
  );
}
/* a row/column this drop would complete: existing cells solid accent... */
.cell.preview-line { background: var(--amber); }
/* ...and the piece's new cells shown faded so you see what's being added */
.cell.preview-line-new { background: rgba(255, 166, 61, 0.45); }
.cell.just-placed { animation: pop 0.22s ease; }
.cell.cleared { animation: clear 0.36s ease; }
@keyframes pop {
  0% { transform: scale(0.6); }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); }
}
@keyframes clear {
  0% { background: var(--g800); transform: scale(1); }
  40% { background: var(--white); transform: scale(1.12); }
  100% { background: var(--white); transform: scale(0.4); opacity: 0.2; }
}
#board.locked { opacity: 0.92; }

/* ---- status line ---- */
.status {
  text-align: center;
  font-size: 14px;
  color: var(--g700);
  margin: 12px 4px 8px;
  min-height: 40px;
}
.status.good { color: var(--g800); }
.status.warn { color: var(--g700); }
.status.muted { color: var(--g400); }
.status b { color: var(--g800); }
.muted { color: var(--g400); }

/* ---- tray ---- */
#tray {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: calc(var(--tray-cell) * 3 + 12px);
  padding: 6px 0 10px;
}
.piece {
  display: grid;
  gap: 3px;
  padding: 6px;
  border-radius: 10px;
  background: var(--white);
  box-shadow: 0 1px 0 var(--g200), inset 0 0 0 1px var(--g100);
  cursor: grab;
  touch-action: none;
}
.piece.selected { box-shadow: inset 0 0 0 2px var(--g600); }
.pblk {
  width: 100%;
  height: 100%;
  background: var(--g800);
  border-radius: 4px;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}
.pgap { width: 100%; height: 100%; }

/* dragging ghost */
.ghost {
  position: fixed;
  display: grid;
  gap: var(--gap);
  padding: 0;
  background: transparent;
  box-shadow: none;
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
}
.ghost.active { opacity: 0.95; }
.ghost .pblk { box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.22); }
/* a block of the held piece that wouldn't fit where it's hovering */
.ghost .pblk.nofit {
  background:
    repeating-linear-gradient(
      45deg, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0.6) 2px, transparent 2px, transparent 5px
    ),
    var(--g800);
}

/* ---- controls ---- */
.controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  padding: 4px 0 10px;
}
.btn {
  appearance: none;
  border: 1px solid var(--g200);
  background: var(--white);
  color: var(--g700);
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
}
.btn:active { background: var(--g50); }
.btn.solid { background: var(--g800); color: var(--white); border-color: var(--g800); }

/* "Play Habibi Daily" CTA on the free-play page (shown after solve / reveal) */
.daily-cta { display: flex; justify-content: center; padding: 8px 0 14px; }
a.btn { display: inline-block; text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: default; }
.hidden { display: none !important; }

/* ---- solution scrubber ---- */
#scrubber {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 2px 12px;
}
#scrub-play {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--g200);
  background: var(--white);
  font-size: 16px;
  cursor: pointer;
}
#scrub-range { flex: 1 1 auto; accent-color: var(--g700); }
#scrub-close { flex: 0 0 auto; }
.scrub-hint {
  text-align: center;
  font-size: 13px;
  color: var(--g400);
  padding: 0 4px 14px;
}
.scrub-hint.hidden { display: none; }

/* ---- footer ---- */
.footer {
  margin-top: auto;
  padding: 16px 0 18px;
  text-align: center;
  font-size: 12px;
  color: var(--g400);
}
.footer a { color: var(--g600); text-decoration: none; font-weight: 700; }
.footer a:hover { color: var(--g800); }

/* ---- info pane (bottom sheet) + forfeit modal ---- */
[data-info] { cursor: pointer; }

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 14, 0.38);
  z-index: 1050;
}
.backdrop.hidden { display: none; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: var(--maxw);
  margin: 0 auto;
  background: var(--white);
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.2);
  padding: 26px 20px calc(28px + env(safe-area-inset-bottom));
  max-height: 84vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform: translateY(110%);
  transition: transform 0.28s ease;
  z-index: 1100;
}
.sheet.open { transform: translateY(0); }
.sheet-close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 38px;
  height: 38px;
  border: none;
  background: transparent;
  font-size: 26px;
  line-height: 1;
  color: var(--g400);
  cursor: pointer;
}
.sheet-text h3 { margin: 0 0 8px; font-size: 18px; color: var(--g800); }
.sheet-text p { margin: 0 0 10px; font-size: 15px; line-height: 1.5; color: var(--g700); }
.sheet-text p:last-child { margin-bottom: 0; }
.sheet-text b { color: var(--g800); }
.sheet-rule { border: none; border-top: 1px solid var(--g200); margin: 18px 0 12px; }
.sheet-btn { display: block; width: 100%; margin-top: 4px; }

.modal-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1200;
}
.modal-overlay.hidden { display: none; }
.modal {
  width: 100%;
  max-width: 340px;
  background: var(--white);
  border-radius: 16px;
  padding: 22px 20px 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.modal-text h3 { margin: 0 0 8px; font-size: 18px; color: var(--g800); }
.modal-text p { margin: 0 0 10px; font-size: 14px; line-height: 1.5; color: var(--g700); }
.modal-text p:last-child { margin-bottom: 0; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

@media (max-width: 360px) {
  :root { --tray-cell: 22px; }
  .wordmark { font-size: 26px; }
}
