/* ==========================================================================
   DryScout.org — Package Patrol: Pack the Truck (V1)
   Builds on ../styles.css (tokens, header, buttons, type). Game-only rules here.
   The board is the approved truck shell (transparent cargo bay) laid over a
   cargo grid; boxes are CSS-drawn so any grid size works. Cell size is set by
   package-patrol.js as --cell-w / --cell-h from the cargo's rendered size.
   ========================================================================== */

.pk-body {
  min-height: 100vh;
  background:
    radial-gradient(ellipse 60% 42% at 12% 6%, rgba(23, 163, 218, 0.10), transparent 70%),
    radial-gradient(ellipse 52% 36% at 88% 10%, rgba(15, 27, 61, 0.08), transparent 70%),
    linear-gradient(180deg, #EEF5FC 0%, #FFFFFF 460px);
}
.pk-body .site-header { background: rgba(255, 255, 255, 0.86); backdrop-filter: blur(6px); }

.pk-back { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; color: var(--navy); min-height: 44px; white-space: nowrap; flex: none; }
.pk-back:hover { color: var(--blue); }

.pk-main { padding: 0 0 56px; }
.pk-screen[hidden] { display: none; }
.pk-body button:focus-visible, .pk-body a:focus-visible { outline: 3px solid var(--cyan); outline-offset: 3px; }
.pk-body button, .pk-body a { -webkit-tap-highlight-color: transparent; }

/* ---------- SCREEN 1: START ---------- */
.pk-start-inner {
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  align-items: center; column-gap: 40px;
  min-height: calc(100vh - 76px - 56px);
  padding-top: 24px; padding-bottom: 24px;
}
.pk-title { font-family: var(--font-display); font-weight: 800; font-size: clamp(40px, 4.6vw, 64px); line-height: 1.08; letter-spacing: -0.02em; color: var(--navy); margin-top: 22px; }
.pk-lede { font-size: 22px; color: var(--text-soft); margin-top: 14px; }
.pk-btn-start { font-size: 20px; padding: 18px 30px; margin-top: 34px; border-radius: 14px; min-height: 56px; }
.pk-start-art { width: clamp(300px, 36vw, 540px); margin-right: clamp(0px, 3vw, 40px); pointer-events: none; }
.pk-start-art img { width: 100%; height: auto; }

/* ---------- SCREEN 2: GAME PANEL ---------- */
.pk-game .container { padding-top: 22px; }
.pk-panel {
  position: relative; max-width: 1100px; margin: 0 auto;
  background: var(--surface);
  border: 1px solid rgba(15, 27, 61, 0.08);
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(15, 27, 61, 0.07);
  overflow: hidden;
}
.pk-panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 16px 26px;
  background: linear-gradient(100deg, var(--navy) 0%, var(--navy-soft) 100%);
  color: #fff;
}
.pk-game-title { font-family: var(--font-display); font-weight: 800; font-size: 22px; letter-spacing: -0.01em; line-height: 1.1; }
.pk-objective { font-size: 15px; color: rgba(255, 255, 255, 0.82); margin-top: 3px; }
.pk-stats { display: flex; gap: 8px; flex: none; }
.pk-stat {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 96px; padding: 7px 14px;
  border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
}
.pk-stat-label { font-size: 11px; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; color: rgba(255, 255, 255, 0.72); }
.pk-stat-value { font-family: var(--font-display); font-weight: 800; font-size: 22px; line-height: 1.15; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pk-stat-value.is-low { color: #FFD166; }

/* ---------- BOARD ---------- */
.pk-board { padding: 14px 20px 4px; overflow: hidden; }
.pk-truck {
  position: relative; margin: 0 auto;
  width: min(900px, 100%, calc((100vh - 505px) * 2.389));
  min-width: 560px;
  aspect-ratio: 1400 / 586;
  user-select: none; -webkit-user-select: none;
}
.pk-shell { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; }
/* The cargo opening, measured from the shell art */
.pk-cargo {
  position: absolute; left: 10.29%; top: 11.6%; width: 60%; height: 48.12%;
  background: linear-gradient(180deg, #F3F6FA 0%, #E9EEF5 100%);
  box-shadow: inset 0 0 0 1px rgba(15, 27, 61, 0.06);
  z-index: 1; touch-action: none;
}
.pk-grid {
  position: absolute; inset: 0; opacity: .55; transition: opacity .2s ease; pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(15, 27, 61, 0.09) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(15, 27, 61, 0.09) 1px, transparent 1px);
  background-size: var(--cell-w, 40px) var(--cell-h, 40px);
  background-position: -1px -1px;
}
.pk-cargo.is-active .pk-grid { opacity: 1; }

/* Placement preview */
.pk-ghost {
  position: absolute; z-index: 2; pointer-events: none; border-radius: 6px;
  border: 3px dashed var(--blue); background: rgba(30, 111, 230, 0.12);
}
.pk-ghost.is-invalid { border: 3px solid #C0392B; background: rgba(192, 57, 43, 0.12); }
.pk-ghost[hidden] { display: none; }

/* ---------- BOXES (CSS-drawn kraft cardboard, sized in grid cells) ---------- */
.pk-box {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  box-sizing: border-box; padding: 0; border: 0; cursor: pointer;
  width: calc(var(--w) * var(--cell-w, 40px) - 4px);
  height: calc(var(--h) * var(--cell-h, 40px) - 4px);
  border-radius: 7px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0) 45%, rgba(0, 0, 0, 0.05)),
    linear-gradient(180deg, #E1BB86 0%, #D3A66B 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35), inset 0 -3px 0 rgba(90, 55, 20, 0.14), inset 0 0 0 1px rgba(90, 55, 20, 0.18),
    0 3px 8px rgba(15, 27, 61, 0.18);
  transition: box-shadow .15s ease, transform .15s ease;
  color: var(--navy);
}
.pk-box::before { /* tape across the top flap */
  content: ""; position: absolute; left: 0; right: 0; top: 16%; height: 14%; min-height: 6px; max-height: 12px;
  background: rgba(255, 248, 230, 0.55);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), inset 0 -1px 0 rgba(90, 55, 20, 0.12);
}
.pk-box::after { /* forgiving tap area on small cells */
  content: ""; position: absolute; inset: -5px;
}
.pk-box .pk-mark {
  width: calc(min(var(--w) * var(--cell-w, 40px), var(--h) * var(--cell-h, 40px)) * 0.42);
  max-width: 64px; height: auto; opacity: .92; pointer-events: none;
  position: relative; top: 8%;
}
.pk-box.is-selected {
  box-shadow:
    0 0 0 3px #fff, 0 0 0 6px var(--blue),
    inset 0 1px 0 rgba(255, 255, 255, 0.35), inset 0 -3px 0 rgba(90, 55, 20, 0.14),
    0 8px 18px rgba(15, 27, 61, 0.22);
  transform: translateY(-2px);
  z-index: 5;
}
.pk-box.is-ghosting { opacity: .35; }
.pk-box.is-shake { animation: pk-shake .32s ease-in-out; }
@keyframes pk-shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.pk-box.is-pop { animation: pk-pop .22s ease-out; }
@keyframes pk-pop { 0% { transform: scale(.94); } 60% { transform: scale(1.03); } 100% { transform: scale(1); } }

/* Placed boxes sit on the grid inside the cargo */
.pk-cargo .pk-box { position: absolute; margin: 2px; left: calc(var(--x) * var(--cell-w, 40px)); top: calc(var(--y) * var(--cell-h, 40px)); z-index: 2; }

/* Floating clone while dragging */
.pk-drag { position: fixed; z-index: 100; pointer-events: none; opacity: .92; transform: scale(1.04); box-shadow: 0 14px 30px rgba(15, 27, 61, 0.3); }

/* ---------- STAGING ---------- */
.pk-staging { padding: 10px 20px 16px; border-top: 1px solid var(--line-soft); background: #F7FAFE; }
.pk-tools { display: flex; gap: 10px; margin-bottom: 10px; }
.pk-tool {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--navy);
  font-family: var(--font-display); font-weight: 700; font-size: 15px; cursor: pointer;
  transition: border-color .15s ease, color .15s ease, opacity .15s ease;
}
.pk-tool svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.pk-tool:hover:not(:disabled) { border-color: var(--blue); color: var(--blue); }
.pk-tool:disabled { opacity: .45; cursor: not-allowed; }
.pk-tray {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px;
  min-height: calc(var(--cell-h, 40px) * 2 + 8px);
}
.pk-tray .pk-box { margin: 2px; }
.pk-tray.is-target { outline: 3px dashed rgba(30, 111, 230, 0.35); outline-offset: 6px; border-radius: 12px; }

/* ---------- SUCCESS BEAT ---------- */
.pk-truck.is-packed .pk-cargo { box-shadow: inset 0 0 0 3px rgba(30, 111, 230, 0.55), 0 0 0 10px rgba(30, 111, 230, 0.12); }
.pk-truck.is-packed { animation: pk-bounce .6s ease-out; }
@keyframes pk-bounce { 0% { transform: translateY(0); } 30% { transform: translateY(-8px); } 60% { transform: translateY(3px); } 100% { transform: translateY(0); } }
.pk-banner {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); z-index: 30;
  padding: 16px 30px; border-radius: 999px;
  background: #fff; color: var(--navy);
  font-family: var(--font-display); font-weight: 800; font-size: clamp(22px, 2.6vw, 32px); letter-spacing: 0.02em; white-space: nowrap;
  box-shadow: 0 14px 40px rgba(15, 27, 61, 0.20);
  animation: pk-banner-in .28s cubic-bezier(.2, .9, .3, 1.3);
}
.pk-banner[hidden] { display: none; }
.pk-banner .tick { color: #1B7F4B; }
@keyframes pk-banner-in { from { opacity: 0; transform: translate(-50%, -50%) scale(.7); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }

/* ---------- SCREEN 3: RESULTS ---------- */
.pk-results-inner {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  min-height: calc(100vh - 76px - 56px); justify-content: center;
  padding-top: 24px; padding-bottom: 24px;
}
.pk-results-title { font-family: var(--font-display); font-weight: 800; font-size: clamp(38px, 4.2vw, 56px); line-height: 1.1; letter-spacing: -0.02em; color: var(--navy); }
.pk-results-sub { font-size: 20px; color: var(--text-soft); margin-top: 8px; }
.pk-results-stats { display: flex; gap: 14px; margin-top: 22px; }
.pk-results-stats > div { min-width: 132px; padding: 12px 22px; background: #fff; border: 1px solid var(--line); border-radius: 14px; }
.pk-results-stats > div[hidden] { display: none; }
.pk-results-stats dt { font-size: 12px; font-weight: 700; letter-spacing: 0.22em; text-transform: uppercase; color: var(--text-soft); }
.pk-results-stats dd { font-family: var(--font-display); font-weight: 800; font-size: 34px; color: var(--blue); line-height: 1.1; margin-top: 2px; font-variant-numeric: tabular-nums; }
.pk-results-art { width: clamp(240px, 26vw, 340px); margin-top: 16px; }
.pk-results-art img { width: 100%; height: auto; }
.pk-btn-again { font-size: 20px; padding: 18px 34px; margin-top: 18px; border-radius: 14px; min-height: 56px; }

/* ---------- Motion preference ---------- */
@media (prefers-reduced-motion: reduce) {
  .pk-box, .pk-grid { transition: none; }
  .pk-box.is-shake, .pk-box.is-pop, .pk-truck.is-packed, .pk-banner { animation: none; }
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */
@media (max-width: 980px) {
  .pk-start-inner { grid-template-columns: 1fr; justify-items: center; text-align: center; min-height: 0; padding-top: 28px; }
  .pk-start-art { width: min(70vw, 420px); margin: 20px 0 0; }
  .eyebrow-bar { justify-content: center; }
  .pk-truck { width: 100%; min-width: 0; }
}

@media (max-width: 640px) {
  .pk-main { padding-bottom: 32px; }
  .pk-back { font-size: 14px; }
  .pk-back-long { display: none; }
  .pk-title { font-size: 40px; }
  .pk-lede { font-size: 18px; }
  .pk-btn-start { width: 100%; max-width: 360px; }
  .pk-start-art { width: min(82vw, 340px); }

  .pk-game .container { padding: 14px 12px 0; }
  .pk-panel { border-radius: 16px; }
  .pk-panel-head { flex-direction: column; align-items: stretch; gap: 12px; padding: 14px 16px; }
  .pk-game-title { font-size: 20px; }
  .pk-objective { font-size: 14px; }
  .pk-stats { justify-content: space-between; }
  .pk-stat { flex: 1 1 0; min-width: 0; padding: 6px 10px; }
  .pk-stat-value { font-size: 21px; }

  /* Scale the truck up so the cargo bay fills ~92% of the panel; the cab is cropped on the right. */
  .pk-board { padding: 12px 0 4px; }
  .pk-truck { width: 153%; min-width: 0; margin-left: -11.5%; }

  .pk-staging { padding: 8px 12px 16px; }
  .pk-tools { gap: 8px; }
  .pk-tool { flex: 1 1 0; justify-content: center; padding: 0 10px; font-size: 14px; }
  .pk-tray { gap: 8px; }
  .pk-box { border-radius: 5px; }
  .pk-box .pk-mark { top: 6%; }

  .pk-results-inner { min-height: 0; padding-top: 32px; }
  .pk-results-sub { font-size: 17px; }
  .pk-results-stats { width: 100%; max-width: 360px; }
  .pk-results-stats > div { flex: 1 1 0; min-width: 0; padding: 10px 12px; }
  .pk-results-stats dd { font-size: 28px; }
  .pk-results-art { width: min(70vw, 280px); }
  .pk-btn-again { width: 100%; max-width: 360px; }
}
