/* =========================================================
   Il Grande Trasloco — arcade knapsack-problem game
   Orbitron (arcade display) + Syne (headings) + DM Sans (body)
========================================================= */
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@700;800;900&family=Syne:wght@600;700;800&family=DM+Sans:wght@300;400;500;600&display=swap');

/* ---------- tokens ---------- */
:root {
  --bg: #0D0B1A;
  --bg-2: #110F22;
  --panel: #15132A;
  --panel-2: #1A1834;
  --border: #2A2545;
  --ink: #E6EBFF;
  --ink-2: #CDD7F3;
  --muted: #8B8AA3;

  --accent: #4ECDC4;
  --coral: #FF6B6B;
  --teal: #4ECDC4;
  --yellow: #FFE66D;
  --magenta: #FF4081;
  --purple: #A78BFA;
  --orange: #F97316;
  --user: #60A5FA;

  --brand-yellow: #FFE66D;
  --brand-yellow-glow: rgba(255,230,109,.45);

  /* --- backpack materials: canvas shell, lining, straps, hardware --- */
  --canvas-1: #354753;
  --canvas-2: #223038;
  --canvas-edge: #162128;
  --lining-1: #131C23;
  --lining-2: #1C2932;
  --stitch: rgba(255,230,109,.40);
  --strap-1: #C87A43;
  --strap-2: #96552A;
  --metal-1: #DBE3EC;
  --metal-2: #8895A3;
  --zip: #A9B8C6;

  /* --- gear card (one item) --- */
  --gear-bg-1: #2B3945;
  --gear-bg-2: #212D36;
  --gear-border: #3D4E5C;
  --gear-ink: #E6EBFF;
  --gear-muted: #9DAEBD;
  --gear-stitch: rgba(255,255,255,.16);

  --font-heading: 'Syne', system-ui, sans-serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
  --font-arcade: 'Orbitron', var(--font-heading), system-ui, sans-serif;
}

/* ---------- light mode ---------- */
:root[data-theme="light"] {
  --bg: #F5F3FF;
  --bg-2: #EDE9FE;
  --panel: #FFFFFF;
  --panel-2: #F9F8FF;
  --border: #D4D0E8;
  --ink: #1E1B34;
  --ink-2: #3B3660;
  --muted: #6B6790;
  --brand-yellow: #B8860B;
  --brand-yellow-glow: rgba(184,134,11,.25);
  --teal: #0D8A80;
  --coral: #D03030;
  --yellow: #A07800;
  --purple: #7C5FC4;
  --orange: #C45A10;

  --canvas-1: #93A9B8;
  --canvas-2: #6E8798;
  --canvas-edge: #55707F;
  --lining-1: #E9EFF4;
  --lining-2: #DAE4EC;
  --stitch: rgba(255,255,255,.75);
  --strap-1: #D98E5A;
  --strap-2: #B06C36;
  --metal-1: #FFFFFF;
  --metal-2: #A9B4C0;
  --zip: #6B7E8D;

  --gear-bg-1: #FFFFFF;
  --gear-bg-2: #F2F5F9;
  --gear-border: #C6D2DD;
  --gear-ink: #1E1B34;
  --gear-muted: #5D6B7A;
  --gear-stitch: rgba(30,27,52,.14);
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-weight: 400;
  line-height: 1.5;
  overflow-x: hidden;
  /* header + main + footer fill the viewport exactly */
  display: flex;
  flex-direction: column;
}

/* =========================================================
   HEADER — CSS grid 1fr / auto / 1fr
========================================================= */
header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #0F0D20 0%, var(--bg) 100%);
}
:root[data-theme="light"] header {
  background: linear-gradient(180deg, #EDE9FE 0%, var(--bg) 100%);
}
header h1 {
  grid-column: 2;
  justify-self: center;
  margin: 0;
  font-family: var(--font-arcade);
  font-size: clamp(22px, 3.4vw, 40px);
  font-weight: 900;
  letter-spacing: .04em;
  color: var(--brand-yellow);
  text-shadow: 0 0 8px var(--brand-yellow-glow), 0 0 28px var(--brand-yellow-glow);
  text-align: center;
  animation: titleGlow 2.4s ease-in-out infinite alternate;
}
@keyframes titleGlow {
  from { text-shadow: 0 0 8px var(--brand-yellow-glow), 0 0 20px var(--brand-yellow-glow); }
  to   { text-shadow: 0 0 12px var(--brand-yellow-glow), 0 0 36px var(--brand-yellow-glow); }
}
.header-right {
  grid-column: 3;
  justify-self: end;
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
.header-emoji {
  grid-column: 1;
  justify-self: start;
  display: inline-flex;
  gap: 12px;
  font-size: 22px;
  line-height: 1;
}
.header-emoji span { display: inline-block; animation: emojiBob 2.2s ease-in-out infinite; }
.header-emoji span:nth-child(2) { animation-delay: .35s; }
.header-emoji span:nth-child(3) { animation-delay: .7s; }
@keyframes emojiBob {
  0%, 100% { transform: translateY(0) rotate(-6deg); }
  50%      { transform: translateY(-7px) rotate(6deg); }
}
@media (max-width: 700px) {
  .header-emoji { display: none; }
}
.header-right button {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--ink-2);
  border-radius: 8px;
  padding: 5px 10px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: all .2s;
}
.header-right button:hover {
  border-color: var(--teal);
  color: var(--ink);
}
/* link back to the arcade home page */
.header-right .home-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-right: 4px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--ink-2);
  border-radius: 8px;
  padding: 5px 10px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13px;
  line-height: 1.3;
  text-decoration: none;
  transition: all .2s;
}
.header-right .home-link:hover { border-color: var(--teal); color: var(--teal); }
.header-right .home-link:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.header-right button[aria-pressed="true"] {
  background: var(--panel);
  border-color: var(--teal);
  color: var(--teal);
}

/* =========================================================
   3-COLUMN LAYOUT — app-like, no body scroll
========================================================= */
main.layout-3col {
  display: grid;
  grid-template-columns: 280px minmax(400px, 1fr) 280px;
  gap: 16px;
  padding: 16px 20px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* sidebar panels */
.left-pane, .right-pane {
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ---------- tagline (left pane, arcade hook) ---------- */
.tagline {
  font-family: var(--font-arcade);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .01em;
  color: var(--teal);
  text-shadow: 0 0 14px rgba(78,205,196,.35);
  line-height: 1.4;
  margin-bottom: 14px;
}

/* ---------- howto (compact icon chips) ---------- */
.howto-arcade {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}
.howto-step {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
}
.howto-icon {
  font-size: 16px;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}

/* ---------- collapsible theory (details/summary) ---------- */
.theory-details {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 12px;
}
.theory-details summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  list-style: none;
}
.theory-details summary::-webkit-details-marker { display: none; }
.theory-details[open] summary { color: var(--ink); margin-bottom: 8px; }
.theory-details p {
  font-size: 13px;
  color: var(--ink-2);
  line-height: 1.5;
  margin: 0 0 8px;
}
.theory-details p:last-child { margin-bottom: 0; }

/* =========================================================
   CENTER PANE — controls + board + feedback
========================================================= */
.center-pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.stage {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* controls bar */
.controls-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.controls-bar label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-2);
}
.controls-bar select {
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-family: var(--font-body);
  font-size: 13px;
  cursor: pointer;
}
.controls-bar select option {
  background: var(--panel);
  color: var(--ink);
}
.controls-bar button {
  background: var(--panel-2);
  color: var(--ink-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 14px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all .2s;
}
.controls-bar button:hover {
  border-color: var(--coral);
  color: var(--coral);
  background: rgba(255,107,107,.08);
}
.controls-bar button#btnFinish:hover {
  border-color: var(--teal);
  color: var(--teal);
  background: rgba(78,205,196,.08);
}

/* HUD chips */
#hud {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.hud-chip {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 999px;
  padding: 4px 12px;
  font-variant-numeric: tabular-nums;
  transition: border-color .2s, box-shadow .2s;
}
.hud-chip b {
  color: var(--ink);
  font-family: var(--font-arcade);
  font-weight: 700;
}
.hud-chip.warn { border-color: var(--coral); box-shadow: 0 0 10px rgba(255,107,107,.25); }
.hud-chip.warn b { color: var(--coral); animation: chipPulse .5s ease infinite alternate; }
.hud-chip.success { border-color: var(--teal); box-shadow: 0 0 10px rgba(78,205,196,.25); }
.hud-chip.success b { color: var(--teal); }
@keyframes chipPulse { from { opacity: 1; } to { opacity: .55; } }

/* timer */
#timer {
  font-family: var(--font-arcade);
  font-weight: 700;
  font-size: 15px;
  color: var(--yellow);
  min-width: 50px;
  text-align: center;
}
#timer.warn {
  color: var(--coral);
  animation: pulse .6s ease infinite alternate;
}
@keyframes pulse { from { opacity: 1; } to { opacity: .5; } }

/* =========================================================
   THE BACKPACK — canvas shell with stitched seams, a grab
   handle + strap buckles on top, a zipped main compartment
   and a front pocket holding the weight gauge
========================================================= */
.board-wrap {
  display: flex;
  justify-content: center;
  position: relative;
  flex: 1;
  min-height: 0;
}

.backpack {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 16px 14px;
  border-radius: 30px 30px 22px 22px;
  border: 1px solid var(--canvas-edge);
  /* woven canvas: two diagonal threads over a vertical dye gradient */
  background:
    repeating-linear-gradient(45deg,  rgba(255,255,255,.030) 0 2px, transparent 2px 4px),
    repeating-linear-gradient(-45deg, rgba(0,0,0,.055) 0 2px, transparent 2px 4px),
    linear-gradient(180deg, var(--canvas-1) 0%, var(--canvas-2) 100%);
  box-shadow:
    0 18px 40px rgba(0,0,0,.45),
    inset 0 1px 0 rgba(255,255,255,.10),
    inset 0 -18px 30px rgba(0,0,0,.22);
}
/* stitched seam running around the shell */
.backpack::before {
  content: "";
  position: absolute;
  inset: 7px;
  border: 2px dashed var(--stitch);
  border-radius: 24px 24px 17px 17px;
  opacity: .55;
  pointer-events: none;
}

/* ---------- top: buckles + grab handle ---------- */
.bp-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  height: 26px;
  flex-shrink: 0;
}
.bp-handle {
  width: 116px;
  height: 15px;
  border-radius: 10px;
  background: linear-gradient(180deg, var(--strap-1), var(--strap-2));
  box-shadow:
    0 3px 6px rgba(0,0,0,.4),
    inset 0 1px 0 rgba(255,255,255,.28),
    inset 0 0 0 1px rgba(0,0,0,.18);
  position: relative;
}
.bp-handle::before,
.bp-handle::after {
  content: "";
  position: absolute;
  left: 8px; right: 8px;
  height: 0;
  border-top: 1px dashed var(--stitch);
  opacity: .8;
}
.bp-handle::before { top: 4px; }
.bp-handle::after  { bottom: 4px; }

.bp-buckle {
  width: 30px;
  height: 17px;
  border-radius: 4px;
  background: linear-gradient(180deg, var(--metal-1), var(--metal-2));
  box-shadow: 0 2px 5px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.6);
  position: relative;
}
.bp-buckle::after {
  content: "";
  position: absolute;
  inset: 4px 6px;
  border-radius: 2px;
  background: var(--canvas-2);
  box-shadow: inset 0 1px 2px rgba(0,0,0,.5);
}

/* ---------- main compartment zipper ---------- */
.bp-zip {
  position: relative;
  height: 10px;
  flex-shrink: 0;
  border-radius: 5px;
  background:
    repeating-linear-gradient(90deg, var(--zip) 0 3px, transparent 3px 7px),
    linear-gradient(180deg, rgba(0,0,0,.45), rgba(0,0,0,.15));
  box-shadow: inset 0 1px 2px rgba(0,0,0,.5);
}
.bp-zip-pull {
  position: absolute;
  top: 1px; right: 14px;
  width: 14px; height: 20px;
  border-radius: 3px 3px 7px 7px;
  background: linear-gradient(180deg, var(--metal-1), var(--metal-2));
  box-shadow: 0 2px 5px rgba(0,0,0,.5);
}

/* ---------- main compartment (packed gear lives here) ---------- */
.bag-zone {
  flex: 1;
  /* flex:1 already claims the free space; keep the floor low so a short
     viewport shrinks the compartment instead of clipping the front pocket */
  min-height: 90px;
  border-radius: 14px;
  padding: 16px 14px;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 12px;
  background: linear-gradient(180deg, var(--lining-1) 0%, var(--lining-2) 100%);
  box-shadow:
    inset 0 14px 26px rgba(0,0,0,.55),
    inset 0 0 0 2px rgba(255,255,255,.04);
  scrollbar-width: thin;
  scrollbar-color: var(--canvas-edge) transparent;
  transition: box-shadow .2s;
}
.bag-empty {
  width: 100%;
  align-self: center;
  text-align: center;
  color: var(--gear-muted);
  font-size: 13px;
  padding: 26px 0;
  opacity: .8;
}

/* ---------- front pocket + weight gauge ---------- */
.bp-pocket {
  position: relative;
  flex-shrink: 0;
  margin-top: 2px;
  padding: 14px 16px 10px;
  border-radius: 6px 6px 16px 16px;
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.025) 0 2px, transparent 2px 4px),
    linear-gradient(180deg, var(--canvas-1), var(--canvas-2));
  border: 1px solid var(--canvas-edge);
  box-shadow: 0 -3px 10px rgba(0,0,0,.3), inset 0 1px 0 rgba(255,255,255,.10);
}
.bp-pocket-zip {
  position: absolute;
  top: 4px; left: 12px; right: 12px;
  height: 6px;
  border-radius: 3px;
  background:
    repeating-linear-gradient(90deg, var(--zip) 0 3px, transparent 3px 7px),
    rgba(0,0,0,.35);
}
.cap-gauge {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}
#capLabel {
  font-family: var(--font-arcade);
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .03em;
  color: var(--brand-yellow);
  text-shadow: 0 1px 3px rgba(0,0,0,.5);
  white-space: nowrap;
}
:root[data-theme="light"] #capLabel { text-shadow: none; }
.cap-bar {
  width: 190px;
  max-width: 45vw;
  height: 10px;
  background: rgba(0,0,0,.45);
  border-radius: 5px;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0,0,0,.6);
  /* scale ticks, like a luggage scale */
  background-image: repeating-linear-gradient(90deg, rgba(255,255,255,.18) 0 1px, transparent 1px 19px);
}
.cap-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--teal), #7FE6DE);
  border-radius: 5px;
  transition: width .25s ease, background .25s ease;
}
.cap-fill.full { background: linear-gradient(90deg, var(--orange), #FFB067); }

/* ---------- "nothing else fits" verdict, under the gauge ---------- */
.bag-status {
  display: none;
  margin-top: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  line-height: 1.5;
  text-align: left;
}
.bag-status.show {
  display: block;
  animation: statusIn .3s cubic-bezier(.34,1.4,.64,1);
}
@keyframes statusIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.bag-status b {
  display: block;
  margin-bottom: 3px;
  font-family: var(--font-arcade);
  font-size: 11.5px;
  letter-spacing: .02em;
  font-variant-numeric: tabular-nums;
}
.bag-status.ok {
  background: rgba(78,205,196,.14);
  border: 1px solid var(--teal);
  color: var(--ink);
}
.bag-status.ok b { color: var(--teal); }
.bag-status.improve {
  background: rgba(255,230,109,.10);
  border: 1px solid rgba(255,230,109,.45);
  color: var(--ink-2);
}
.bag-status.improve b { color: var(--brand-yellow); }
:root[data-theme="light"] .bag-status.improve {
  background: rgba(255,255,255,.75);
  border-color: rgba(160,120,0,.45);
}
:root[data-theme="light"] .bag-status.ok { background: rgba(255,255,255,.8); }

/* =========================================================
   GEAR CARD — one item, styled as a kit tag with an eyelet
   and weight / value badges
========================================================= */
.gear-card {
  --gear-accent: var(--teal);
  position: relative;
  width: 116px;
  padding: 15px 8px 10px;
  border-radius: 12px;
  text-align: center;
  cursor: pointer;
  font-family: var(--font-body);
  color: var(--gear-ink);
  background: linear-gradient(180deg, var(--gear-bg-1), var(--gear-bg-2));
  border: 1px solid var(--gear-border);
  box-shadow: 0 6px 14px rgba(0,0,0,.38), inset 0 1px 0 rgba(255,255,255,.08);
  transition: transform .14s ease, box-shadow .18s ease, border-color .18s ease;
}
/* inner stitch line */
.gear-card::before {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px dashed var(--gear-stitch);
  border-radius: 9px;
  pointer-events: none;
}
/* webbing tab at the top of the tag */
.gear-card::after {
  content: "";
  position: absolute;
  top: -1px; left: 50%;
  transform: translateX(-50%);
  width: 40px; height: 5px;
  border-radius: 0 0 5px 5px;
  background: var(--gear-accent);
  opacity: .85;
}
.gear-card:hover {
  transform: translateY(-3px);
  border-color: var(--gear-accent);
  box-shadow: 0 12px 22px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.10);
}
.gear-card .gear-eyelet {
  position: absolute;
  top: 6px; left: 9px;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--lining-1);
  box-shadow: inset 0 0 0 1.5px var(--metal-2), 0 1px 1px rgba(0,0,0,.4);
}
.gear-card.hint {
  --gear-accent: var(--yellow);
  border-color: var(--yellow);
  box-shadow: 0 0 0 2px var(--yellow), 0 0 22px rgba(255,230,109,.55);
}
.gear-card.suggested { --gear-accent: var(--teal); border-color: var(--teal); }

.gear-card.drop-in { animation: gearDropIn .34s cubic-bezier(.34,1.4,.64,1); }
@keyframes gearDropIn {
  from { transform: translateY(-16px) scale(.9); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}
.gear-card.pop-out { animation: gearPopOut .28s ease; }
@keyframes gearPopOut {
  from { transform: scale(.85); opacity: .3; }
  to   { transform: scale(1); opacity: 1; }
}
.gear-card.no-fit {
  animation: shakeNoFit .45s ease;
  border-color: var(--coral) !important;
  box-shadow: 0 0 0 2px var(--coral), 0 8px 20px rgba(255,23,68,.5) !important;
}
@keyframes shakeNoFit {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}

.item-emoji {
  font-size: 26px;
  line-height: 1;
  animation: emojiWiggle 2.4s ease-in-out infinite;
}
@keyframes emojiWiggle {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50%      { transform: translateY(-3px) rotate(8deg); }
}
.gear-card .item-name {
  font-family: var(--font-arcade);
  font-weight: 800;
  font-size: 10.5px;
  line-height: 1.25;
  margin-top: 6px;
  white-space: normal;
  text-wrap: pretty;
}
.gear-card .item-stats {
  display: flex;
  justify-content: center;
  gap: 5px;
  margin-top: 8px;
}
.gear-card .item-stats .stat {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.gear-card .item-stats .w {
  color: var(--orange);
  background: rgba(249,115,22,.14);
  border: 1px solid rgba(249,115,22,.38);
}
.gear-card .item-stats .v {
  color: var(--yellow);
  background: rgba(255,230,109,.13);
  border: 1px solid rgba(255,230,109,.34);
}
:root[data-theme="light"] .gear-card .item-stats .w { background: rgba(196,90,16,.10); border-color: rgba(196,90,16,.35); }
:root[data-theme="light"] .gear-card .item-stats .v { background: rgba(160,120,0,.10); border-color: rgba(160,120,0,.35); }

.pool-empty {
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
  padding: 6px 4px;
}

/* =========================================================
   FEEDBACK TOAST — frosted glass overlay on board
========================================================= */
.feedback-toast {
  display: none;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(13,11,26,.55);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px 32px;
  text-align: center;
  z-index: 10;
  min-width: 260px;
  animation: fadeIn .3s ease;
}
:root[data-theme="light"] .feedback-toast {
  background: rgba(255,255,255,.82);
  border-color: #D4D0E8;
}
:root[data-theme="light"] .feedback-toast .score {
  color: #0D8A80;
}
:root[data-theme="light"] .feedback-toast .detail {
  color: #3B3660;
}
:root[data-theme="light"] .feedback-toast .comparisons {
  color: #3B3660;
}
.feedback-toast.show { display: block; animation: toastPop .38s cubic-bezier(.34,1.56,.64,1); }
@keyframes toastPop {
  from { opacity: 0; transform: translate(-50%, -50%) scale(.7); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
.feedback-toast .score {
  font-family: var(--font-arcade);
  font-weight: 900;
  font-size: 30px;
  letter-spacing: .03em;
  color: var(--teal);
  text-shadow: 0 0 18px rgba(78,205,196,.5);
}
.feedback-toast .detail {
  font-size: 14px;
  color: var(--ink-2);
  margin-top: 8px;
}
.feedback-toast .comparisons {
  margin-top: 10px;
  font-size: 13px;
  line-height: 1.6;
}
.optimal-badge {
  margin-top: 10px;
  padding: 6px 14px;
  border-radius: 8px;
  font-family: var(--font-arcade);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .02em;
  display: inline-block;
}
.optimal-badge.optimal-yes {
  color: var(--teal);
  background: rgba(78,205,196,.14);
  border: 1px solid var(--teal);
  text-shadow: 0 0 10px rgba(78,205,196,.4);
}
/* not a scolding, an explanation: reads as a note, not as an arcade badge */
.optimal-badge.optimal-no {
  display: block;
  text-align: left;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.45;
  color: var(--ink-2);
  background: rgba(255,230,109,.08);
  border: 1px solid rgba(255,230,109,.35);
}
.feedback-toast button {
  margin-top: 14px;
  background: rgba(78,205,196,.12);
  border: 1px solid var(--teal);
  color: var(--teal);
  border-radius: 8px;
  padding: 6px 18px;
  font-family: var(--font-body);
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
}
.feedback-toast button:hover {
  background: rgba(78,205,196,.22);
}

/* =========================================================
   PROGRESS BAR on board
========================================================= */
/* runs along the main zipper: the algorithm "closes the bag" as it works */
.progress-bar {
  position: absolute;
  top: 44px; left: 24px; right: 24px;
  height: 10px;
  background: rgba(0,0,0,.35);
  border-radius: 5px;
  overflow: hidden;
  z-index: 3;
}
.progress-bar .fill {
  height: 100%;
  background: linear-gradient(90deg, var(--teal), #7FE6DE);
  box-shadow: 0 0 12px rgba(78,205,196,.6);
  border-radius: 5px;
  transition: width .15s linear;
}

/* =========================================================
   POOL — gear still outside the backpack, laid out on a bench
========================================================= */
.pool-bar {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px dashed var(--border);
  background: var(--panel);
  border-radius: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
  min-height: 58px;
  /* the biggest level holds 25 items: cap the bench and scroll it,
     otherwise it squeezes the backpack out of the fixed-height layout */
  flex: 0 1 auto;
  max-height: 32vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.pool-bar .label {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  margin-right: 4px;
  padding-top: 8px;
  flex-shrink: 0;
}
#pool {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  flex-wrap: wrap;
}
/* not packed yet: flat tag, dashed edge, no shadow lifting it off the bench */
#pool .gear-card {
  background: var(--panel-2);
  border: 1.5px dashed var(--muted);
  box-shadow: none;
  opacity: .92;
}
#pool .gear-card:hover {
  opacity: 1;
  border-style: solid;
  box-shadow: 0 8px 16px rgba(0,0,0,.35);
}
#pool .gear-card::after { opacity: .5; }
#pool .gear-card .gear-eyelet { background: var(--panel); }
/* the pool's own box-shadow:none above (id selector) would otherwise beat
   .gear-card.hint/.no-fit (two classes) and hide their glow entirely */
#pool .gear-card.hint {
  border-style: solid;
  border-color: var(--yellow);
  box-shadow: 0 0 0 2px var(--yellow), 0 0 22px rgba(255,230,109,.55);
}
#pool .gear-card.suggested { border-color: var(--teal); }
#pool .gear-card.no-fit {
  border-style: solid;
  box-shadow: 0 0 0 2px var(--coral), 0 8px 20px rgba(255,23,68,.5);
}

/* =========================================================
   SIDEBAR — section headers
========================================================= */
.sidebar h3 {
  margin: 14px 0 6px;
  font-family: var(--font-arcade);
  font-size: 12px;
  font-weight: 800;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: .06em;
  cursor: help;
}
.sidebar h3:first-child { margin-top: 0; }

/* =========================================================
   SIDEBAR — algo buttons (TOGGLE with color dot)
========================================================= */
.sidebar .algo-btn {
  width: 100%;
  margin-bottom: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--ink);
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  transition: all .2s;
}
.sidebar .algo-btn:hover {
  border-color: var(--accent);
  background: rgba(78,205,196,.06);
}
.sidebar .algo-btn .dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.sidebar .algo-btn.active {
  border-color: var(--accent);
  background: rgba(78,205,196,.1);
  box-shadow: 0 0 12px rgba(78,205,196,.12);
}
.sidebar .algo-btn.disabled {
  opacity: .4;
  cursor: not-allowed;
  pointer-events: none;
}
.sidebar .algo-btn.running {
  border-color: var(--yellow);
  box-shadow: 0 0 14px rgba(255,230,109,.3);
  animation: runningPulse 1s ease infinite;
}
@keyframes runningPulse {
  0%, 100% { box-shadow: 0 0 8px rgba(255,230,109,.2); }
  50% { box-shadow: 0 0 18px rgba(255,230,109,.45); }
}

/* algo info box (dynamic description on click) */
.algo-info {
  display: none;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-top: 10px;
  font-size: 13px;
  color: var(--ink-2);
  animation: fadeIn .3s ease;
}
.algo-info.show { display: block; }
.algo-info h4 {
  margin: 0 0 4px;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 14px;
  color: var(--ink);
}

/* =========================================================
   FOOTER
========================================================= */
.footnote {
  text-align: center;
  padding: 10px;
  font-size: 12px;
  color: var(--muted);
  opacity: .7;
}

/* =========================================================
   CONFETTI (canvas-based, just z-index)
========================================================= */
.confetti-canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  border-radius: 12px;
}

/* =========================================================
   ANIMATIONS
========================================================= */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =========================================================
   FOCUS
========================================================= */
button:focus-visible, select:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

/* =========================================================
   RESPONSIVE
========================================================= */
@media (max-width: 1100px) {
  main.layout-3col {
    grid-template-columns: 240px minmax(360px, 1fr) 240px;
    gap: 12px;
    padding: 12px 14px;
  }
}

@media (max-width: 900px) {
  main.layout-3col {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
    padding: 12px;
  }
  .left-pane, .right-pane {
    overflow-y: visible;
    max-height: none;
  }
  .center-pane { order: -1; }
  .board-wrap { min-height: 55vh; }
  /* page scrolls freely below 900px, so the bench needs no cap */
  .pool-bar { max-height: none; overflow-y: visible; }
  header h1 { font-size: 22px; }
}

@media (max-width: 600px) {
  header {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 8px;
    padding: 12px;
  }
  header h1 { grid-column: 1; font-size: 18px; }
  .header-right { grid-column: 1; justify-self: center; }
  .controls-bar { flex-direction: column; align-items: stretch; }
  .pool-bar { justify-content: center; }
  .sidebar .algo-btn { padding: 12px; font-size: 15px; }
  #hud { justify-content: center; }
}

/* =========================================================
   MOBILE — compact controls, touch targets, pane order
========================================================= */
@media (max-width: 900px) {
  body { display: block; height: auto; }
  main.layout-3col { grid-template-columns: minmax(0, 1fr); }
  .center-pane { overflow: visible; min-width: 0; }
  /* the algorithms to challenge come right after the board,
     the instructions (read once) go last */
  .right-pane { order: 1; }
  .left-pane  { order: 2; }
}

@media (max-width: 600px) {
  main.layout-3col { padding: 10px; gap: 10px; }
  header { padding-block: 10px; gap: 6px; }
  /* buttons share a row instead of one full-width row each,
     so the backpack shows up without scrolling */
  .controls-bar { flex-direction: row; justify-content: center; align-items: center; gap: 8px; }
  .controls-bar > label { flex: 1 1 100%; min-width: 0; }
  .controls-bar select { flex: 1; min-width: 0; }
  .controls-bar > button { flex: 1 1 0; padding-inline: 8px; white-space: nowrap; }
  #hud { flex: 1 1 100%; margin-left: 0; }
  /* three tags per row on a phone instead of two */
  #pool, .bag-zone { gap: 8px; justify-content: center; }
  .gear-card { width: 104px; padding-inline: 5px; }
  .gear-card .item-stats { gap: 3px; }
  .gear-card .item-stats .stat { padding: 2px 5px; white-space: nowrap; }
  .bag-zone { padding: 12px 8px; }
  .backpack { padding-inline: 12px; }
  .feedback-toast { min-width: 0; width: calc(100% - 24px); padding: 18px 16px; }
  .feedback-toast .score { font-size: 24px; }
}

@media (pointer: coarse) {
  .header-right button { min-width: 42px; min-height: 40px; font-size: 14px; }
  .header-right .home-link { min-height: 40px; font-size: 14px; }
  .controls-bar button, .controls-bar select { min-height: 42px; }
  /* below 16px iOS zooms the page when the select gets focus */
  .controls-bar select { font-size: 16px; }
  .theory-details summary { padding-block: 8px; }
  .sidebar .algo-btn { min-height: 48px; }
  .feedback-toast button { min-height: 42px; }
}

/* touch screens keep :hover "stuck" after a tap */
@media (hover: none) {
  .gear-card:hover { transform: none; }
  #pool .gear-card:not(.hint):not(.no-fit):hover { border-style: dashed; box-shadow: none; }
  .controls-bar button:hover,
  .controls-bar button#btnFinish:hover { border-color: var(--border); color: var(--ink-2); background: var(--panel-2); }
}

/* =========================================================
   SITE FOOTER — copyright line under the app
========================================================= */
.site-footer {
  flex-shrink: 0;
  padding: 7px 20px 9px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}
.site-footer a {
  color: var(--ink-2);
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
}
.site-footer a:hover { color: var(--teal); }
