/* ====================================================================
   Wood Block Fill Puzzle — styles
   ==================================================================== */
:root {
  --bcs: 44px;                 /* board cell size (set by JS)  */
  --tcs: 26px;                 /* tray cell size               */

  --wood-bg-1: #2c1b10;
  --wood-bg-2: #3a2417;
  --wood-frame-1: #6b4423;
  --wood-frame-2: #4a2f18;
  --slot-1: #5a3c22;
  --slot-2: #4a2f18;
  --slot-hole: rgba(0,0,0,.18);

  --cream: #f6ead7;
  --gold: #e7b75b;
  --gold-dark: #c8932f;
  --green: #5fb35f;
  --green-dark: #3f8a3f;
  --red: #d76a5a;

  --shadow: 0 10px 30px rgba(0,0,0,.45);
  --radius: 16px;

  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  overscroll-behavior: none;
}
/* The game fills the first screen (.app is 100svh); the About/SEO content and
   its ad units sit below and are reachable by scrolling. The board and tray
   pieces set touch-action:none, so dragging never scrolls the page. */
body.play {
  min-height: 100vh;
  min-height: 100svh;
  overflow-x: hidden;
  overflow-y: auto;
}
body.dragging { -webkit-user-select: none; user-select: none; }

/* Full-screen game shell: the game fills the viewport; SEO content sits below. */
.app {
  height: 100vh;          /* fallback */
  height: 100svh;         /* small viewport — stable while the mobile URL bar animates */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body {
  font-family: var(--font);
  color: var(--cream);
  background:
    radial-gradient(circle at 20% 0%, rgba(231,183,91,.10), transparent 45%),
    radial-gradient(circle at 80% 100%, rgba(231,183,91,.08), transparent 45%),
    repeating-linear-gradient(115deg, var(--wood-bg-1) 0 14px, var(--wood-bg-2) 14px 28px);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;

  /* Pin the gradient to the viewport instead of letting it scroll with the
     page. Must live in THIS rule and after the `background:` shorthand -
     the shorthand resets background-attachment to scroll, so declaring it
     in the earlier `html, body` rule had no effect. */
  background-attachment: fixed;
}

.visually-hidden,
.skip-link {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}
.skip-link:focus {
  position: fixed !important;
  left: 12px; top: 12px;
  width: auto; height: auto;
  clip: auto;
  background: var(--gold); color: #2a1a0d;
  padding: 10px 14px; border-radius: 10px; z-index: 999;
  font-weight: 700;
}

/* ----------------------------- Top bar ----------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px clamp(12px, 4vw, 28px);
  background: linear-gradient(180deg, rgba(0,0,0,.28), rgba(0,0,0,0));
  flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { font-size: 1.7rem; filter: drop-shadow(0 2px 2px rgba(0,0,0,.4)); }
.brand-title {
  font-size: clamp(1.05rem, 3.4vw, 1.5rem);
  margin: 0; font-weight: 800; letter-spacing: .3px;
  color: var(--cream);
  text-shadow: 0 2px 0 rgba(0,0,0,.35);
}
.brand-title span { color: var(--gold); }
.topnav { display: flex; gap: 8px; }

/* ----------------------------- Buttons ----------------------------- */
.btn {
  font-family: inherit;
  font-weight: 700;
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  cursor: pointer;
  color: #2a1a0d;
  background: linear-gradient(180deg, #f0d49b, var(--gold));
  box-shadow: 0 4px 0 var(--gold-dark), 0 6px 12px rgba(0,0,0,.3);
  transition: transform .06s ease, box-shadow .06s ease, filter .15s ease;
  -webkit-user-select: none; user-select: none;
  font-size: .95rem;
  touch-action: manipulation;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--gold-dark), 0 2px 6px rgba(0,0,0,.3); }
a.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.btn:focus-visible { outline: 3px solid #fff6; outline-offset: 2px; }
.btn:disabled { filter: grayscale(.7) brightness(.85); opacity: .65; cursor: not-allowed; box-shadow: 0 4px 0 rgba(0,0,0,.3); }

.btn-ghost {
  background: rgba(255,255,255,.08);
  color: var(--cream);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}
.btn-ghost:active { transform: translateY(2px); }

.btn-primary { background: linear-gradient(180deg, #f0d49b, var(--gold)); box-shadow: 0 4px 0 var(--gold-dark), 0 6px 12px rgba(0,0,0,.3); }
.btn-secondary { background: linear-gradient(180deg, #e7d7bf, #c9aa7d); box-shadow: 0 4px 0 #9c7e54, 0 6px 12px rgba(0,0,0,.3); }
.btn-success { background: linear-gradient(180deg, #8fd98f, var(--green)); color: #103a10; box-shadow: 0 4px 0 var(--green-dark), 0 6px 12px rgba(0,0,0,.3); }

.btn-nav {
  width: 46px; height: 46px;
  border-radius: 50%;
  font-size: 1.6rem; line-height: 1;
  padding: 0;
  display: grid; place-items: center;
  flex: 0 0 auto;
}
.btn-icon { padding: 10px 12px; font-size: 1.1rem; line-height: 1; }
.btn-ghost { display: inline-flex; align-items: center; text-decoration: none; }
.btn-block { width: 100%; margin-top: 14px; }
.btn-close { width: 40px; height: 40px; padding: 0; font-size: 1.1rem; }

/* ----------------------------- Main / HUD ----------------------------- */
main {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 4px clamp(8px, 2.5vw, 18px) 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex: 1 1 auto;
  min-height: 0;          /* allow children to shrink so the board can size to fit */
}
.hud {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex: 0 0 auto;
}
.hud-center { text-align: center; }
.hud-level { margin: 0; font-size: 1rem; font-weight: 600; }
.hud-level strong { color: var(--gold); font-size: 1.2rem; }
.hud-of { opacity: .7; font-weight: 400; font-size: .9rem; }
.hud-meta { display: flex; gap: 8px; justify-content: center; margin-top: 3px; flex-wrap: wrap; }
.chip {
  font-size: .8rem;
  background: rgba(0,0,0,.25);
  padding: 4px 10px;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}
.chip-soft { opacity: .8; }
.chip.bump { animation: chipbump .35s ease; }
@keyframes chipbump { 0% { transform: scale(1); } 40% { transform: scale(1.22); color: var(--gold); } 100% { transform: scale(1); } }

/* ----------------------- Play area (board + side) ----------------------- */
.play-area {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;   /* portrait: board on top, tray + actions below */
  gap: 8px;
}
.side {
  width: 100%;
  flex: 0 0 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ----------------------------- Board ----------------------------- */
.board-area {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
  min-height: 0;          /* measured by JS to size the board to the free space */
  overflow: hidden;
}
.board-frame {
  padding: 8px;
  border-radius: 16px;
  background:
    repeating-linear-gradient(90deg, var(--wood-frame-1) 0 8px, var(--wood-frame-2) 8px 16px);
  box-shadow:
    var(--shadow),
    inset 0 0 0 3px rgba(255,255,255,.06),
    inset 0 0 22px rgba(0,0,0,.45);
}
.board {
  display: grid;
  gap: 0;
  background: rgba(0,0,0,.25);
  border-radius: 10px;
  overflow: hidden;
  touch-action: none;          /* prevent the page from scrolling while dragging on the board */
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
.cell {
  width: var(--bcs);
  height: var(--bcs);
  position: relative;
  touch-action: none;
}
/* a playable, empty slot (recessed wood) */
.cell.slot {
  background: linear-gradient(145deg, var(--slot-1), var(--slot-2));
  box-shadow:
    inset 2px 2px 4px rgba(0,0,0,.5),
    inset -2px -2px 4px rgba(255,255,255,.05);
  border: 1px solid rgba(0,0,0,.25);
}
/* a hole / not part of the board */
.cell.hole {
  background: var(--slot-hole);
  box-shadow: inset 0 0 6px rgba(0,0,0,.5);
}
/* highlight while dragging */
.cell.hi-ok::after,
.cell.hi-bad::after {
  content: "";
  position: absolute; inset: 2px;
  border-radius: 6px;
  pointer-events: none;
}
.cell.hi-ok::after { background: rgba(95,179,95,.55); box-shadow: 0 0 0 2px rgba(95,179,95,.9) inset; }
.cell.hi-bad::after { background: rgba(215,106,90,.45); box-shadow: 0 0 0 2px rgba(215,106,90,.9) inset; }

/* a filled wooden block (inside board or in tray/clone) */
.block {
  --c: #b07d4f;
  position: absolute; inset: 0;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,.05) 0 3px, rgba(0,0,0,.05) 3px 6px),
    linear-gradient(150deg, color-mix(in srgb, var(--c) 80%, #fff 20%), var(--c) 55%, color-mix(in srgb, var(--c) 75%, #000 25%));
  border-radius: 7px;
  box-shadow:
    inset 0 2px 1px rgba(255,255,255,.45),
    inset 0 -3px 4px rgba(0,0,0,.4),
    0 1px 2px rgba(0,0,0,.3);
  border: 1px solid rgba(0,0,0,.25);
}
.cell .block { inset: 1px; }
.cell.placed { cursor: grab; }
.block.pop { animation: pop .22s ease; }
@keyframes pop {
  0% { transform: scale(.6); }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* ----------------------------- Tray ----------------------------- */
.tray-area { width: 100%; flex: 0 0 auto; }
.tray {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 12px;
  min-height: calc(var(--tcs) * 2 + 16px);
  max-height: 23vh;
  overflow-y: auto;
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(0,0,0,.22);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.05), inset 0 4px 14px rgba(0,0,0,.4);
  touch-action: pan-y;          /* empty tray space can scroll; pieces (below) capture the drag */
  scrollbar-width: thin;
}
.tray:empty::after {
  content: "Solved! 🎉";
  opacity: .7; font-size: 1rem; font-weight: 700;
}
.piece {
  display: grid;
  gap: 0;
  cursor: grab;
  touch-action: none;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,.35));
  transition: transform .12s ease;
}
.piece:active { cursor: grabbing; }
.piece:hover { transform: translateY(-2px) scale(1.03); }
.pcell { width: var(--tcs); height: var(--tcs); position: relative; }
.pcell.empty { visibility: hidden; }

/* a tray piece that can't fit anywhere on the board is dimmed */
.piece.dead { opacity: .38; filter: grayscale(.5); }

/* animated line wipe-out: blocks flash bright, pop, then shrink away in a sweep */
.block.wipe {
  animation: wipe 300ms cubic-bezier(.5, -0.2, .7, 1) both;
  z-index: 2;
}
@keyframes wipe {
  0%   { transform: scale(1) rotate(0deg);      opacity: 1; filter: brightness(1); }
  25%  { transform: scale(1.22) rotate(-4deg);  opacity: 1; filter: brightness(2) saturate(1.4); }
  55%  { transform: scale(1.1) rotate(3deg);    opacity: 1; filter: brightness(1.6); }
  100% { transform: scale(0) rotate(12deg);     opacity: 0; filter: brightness(1.2); }
}
.cell.clearing { box-shadow: inset 0 0 14px rgba(246,234,215,.45); }

/* dragging clone */
.drag-clone {
  position: fixed;
  left: 0; top: 0;               /* moved via transform only — stays on the compositor */
  z-index: 500;
  pointer-events: none;
  display: grid;
  gap: 0;
  will-change: transform;
  filter: drop-shadow(0 10px 14px rgba(0,0,0,.5));
  opacity: .96;
}
.drag-clone .pcell { width: var(--bcs); height: var(--bcs); }

/* ----------------------------- Actions ----------------------------- */
.actions {
  width: 100%;
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  flex: 0 0 auto;
}
.actions .btn { flex: 1 1 auto; min-width: 120px; max-width: 220px; }

/* ----------------------------- SEO content ----------------------------- */
.seo-content {
  max-width: 760px;
  margin: 12px auto 0;
  padding: 26px clamp(16px, 5vw, 34px);
  background: rgba(0,0,0,.28);
  border-radius: 20px 20px 0 0;
  line-height: 1.65;
}
.seo-content h2 { color: var(--gold); margin-top: 0; }
.seo-content h3 { color: var(--cream); margin-top: 1.6em; }
.seo-content a { color: var(--gold); }
.faq dt { font-weight: 700; margin-top: 14px; color: var(--gold); }
.faq dd { margin: 4px 0 0; opacity: .92; }

.site-footer {
  text-align: center;
  padding: 18px 16px 34px;
  font-size: .85rem;
  opacity: .75;
  background: rgba(0,0,0,.28);
}
.site-footer a { color: var(--gold); }

/* ----------------------------- Doc page (How to Play) ----------------------------- */
.doc { max-width: 760px; margin: 0 auto; padding: 10px clamp(12px, 4vw, 24px) 30px; }
.doc-card { border-radius: 20px; margin-top: 8px; }
.doc-card ol, .doc-card ul { line-height: 1.8; }
.crumbs { font-size: .9rem; opacity: .85; padding: 8px 2px; }
.crumbs a { color: var(--gold); }
.more-link { margin-top: 22px; }
.more-link a.btn { padding: 12px 22px; }

/* ----------------------------- Modals ----------------------------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(10,6,2,.72);
  backdrop-filter: blur(3px);
  display: grid; place-items: center;
  padding: 18px;
  z-index: 600;
  animation: fade .2s ease;
}
.modal[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  width: min(440px, 100%);
  max-height: 88vh;
  overflow: auto;
  background: linear-gradient(180deg, #4a2f18, #38220f);
  border-radius: 22px;
  padding: 24px;
  box-shadow: var(--shadow), inset 0 0 0 2px rgba(255,255,255,.06);
  text-align: center;
  animation: rise .25s ease;
}
@keyframes rise { from { transform: translateY(18px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-card h2 { margin: 0 0 6px; color: var(--gold); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h2 { margin: 0; }
.modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 18px; }
.modal-actions .btn { flex: 1; }

.win-card .win-burst { font-size: 3rem; animation: pop .4s ease; }
.win-card #win-sub { opacity: .85; margin: 4px 0 0; }

.how-list { text-align: left; line-height: 1.7; padding-left: 20px; }

/* Levels grid */
.levels-card { width: min(560px, 100%); }
.levels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 8px;
}
.lvl-btn {
  aspect-ratio: 1;
  border: none; border-radius: 10px;
  font-weight: 800; font-size: .95rem;
  cursor: pointer;
  color: #2a1a0d;
  background: linear-gradient(180deg, #f0d49b, var(--gold));
  box-shadow: 0 3px 0 var(--gold-dark);
}
.lvl-btn.cleared { background: linear-gradient(180deg, #8fd98f, var(--green)); box-shadow: 0 3px 0 var(--green-dark); color: #103a10; }
.lvl-btn.current { outline: 3px solid #fff; outline-offset: 1px; }
.lvl-btn.locked {
  background: rgba(255,255,255,.08);
  color: rgba(255,255,255,.4);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.1);
  cursor: not-allowed;
}
.lvl-btn.locked::before { content: "🔒"; }
.lvl-btn.locked span { display: none; }

/* Confetti */
.confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 700; overflow: hidden; }
.confetti {
  position: absolute; top: -14px;
  width: 10px; height: 14px; border-radius: 2px;
  will-change: transform, opacity;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(108vh) rotate(720deg); opacity: .2; }
}

/* Landscape / desktop: board fills the window on the left, tray + actions on the
   right — so the game uses the entire browser instead of a narrow centred column. */
@media (orientation: landscape) and (min-width: 720px) {
  main { max-width: none; }
  .play-area { flex-direction: row; align-items: stretch; gap: 16px; }
  .board-area { flex: 1 1 auto; }
  .side {
    width: auto;
    flex: 0 0 clamp(240px, 26vw, 360px);
    justify-content: flex-start;
  }
  .side .tray-area { flex: 1 1 auto; min-height: 0; display: flex; }
  .side .tray { max-height: none; height: 100%; width: 100%; }
  .actions { flex: 0 0 auto; flex-wrap: wrap; }
  .actions .btn { flex: 1 1 40%; }
}

@media (max-width: 480px) {
  .brand-title { font-size: 1rem; }
  .topnav { gap: 6px; }
  .topnav .btn { padding: 8px 10px; font-size: .82rem; }
  .actions .btn { min-width: 92px; padding: 10px 10px; font-size: .9rem; }
}
@media (max-width: 360px) {
  .brand-logo { display: none; }
  .topnav .btn { padding: 7px 8px; font-size: .76rem; }
}

/* ----------------------------- Ad slots ----------------------------- */
/* Slots reserve no fixed space: if an ad doesn't load (or is skipped for the
   device), the slot collapses and the layout is exactly as before. */
.ad-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  overflow: hidden;
  min-height: 0;
}

/* Bottom banner on the game page — an in-flow flex row inside .app, so
   game.js measures the remaining .board-area space and sizes the board to it. */
.ad-bar { flex: 0 0 auto; padding: 3px 0 5px; }
@media (max-height: 429px) { .ad-bar { display: none; } } /* short landscape phones: game keeps every pixel */

/* Desktop-only side rails in .play-area — flex items, so the board simply
   uses the space left over; hidden entirely on smaller screens. */
.ad-rail { display: none; }
@media (orientation: landscape) and (min-width: 1280px) and (min-height: 620px) {
  #ad-rail-right { display: flex; flex: 0 0 auto; align-items: center; justify-content: center; }
}
@media (orientation: landscape) and (min-width: 1280px) and (min-height: 840px) {
  #ad-rail-left { display: flex; flex: 0 0 auto; align-items: center; justify-content: center; }
}

/* Win-modal 300x250: sits below the buttons; negative margin reclaims card
   padding so the ad fits uncropped on 360px-wide phones. */
.ad-modal { margin: 16px -12px 0; }

/* How-to-Play page */
.doc > .ad-slot { margin: 14px auto; }
.seo-content .ad-slot { margin: 22px auto; }
.ad-native { display: block; }
.ad-native > div { width: 100%; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
