/* ============================================================
   Buttons — chunky, pressable, hard bottom edge (no soft blur)
   ============================================================ */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-5);
  min-height: 52px;
  border-radius: var(--r-lg);
  font-family: var(--font-display);
  font-size: var(--step-1);
  letter-spacing: .02em;
  color: var(--cream);
  background: linear-gradient(180deg, var(--dill-lit), var(--dill) 55%, var(--dill-deep));
  box-shadow: 0 4px 0 var(--dill-deep), 0 9px 16px rgba(34, 64, 14, .4), inset 0 2px 0 rgba(255, 255, 255, .45);
  text-shadow: 0 2px 0 rgba(34, 64, 14, .55);
  transition: transform var(--t-fast) var(--ease-pop), box-shadow var(--t-fast) var(--ease-pop), filter var(--t-fast);
  touch-action: manipulation;
}
.btn::after {
  /* glossy top sheen — the "wet jar" read */
  content: '';
  position: absolute;
  inset: 3px 6px auto 6px;
  height: 38%;
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, rgba(255, 255, 255, .5), rgba(255, 255, 255, 0));
  pointer-events: none;
}
.btn:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 var(--dill-deep), 0 2px 6px rgba(34, 64, 14, .4), inset 0 2px 0 rgba(255, 255, 255, .3);
}
.btn:disabled { filter: grayscale(.7) brightness(.85); cursor: not-allowed; }

.btn--lg { min-height: 66px; padding: var(--sp-4) var(--sp-7); font-size: var(--step-3); border-radius: var(--r-xl); }
.btn--sm { min-height: 40px; padding: var(--sp-2) var(--sp-4); font-size: var(--step-0); border-radius: var(--r-md); }
.btn--block { width: 100%; }

.btn--amber {
  background: linear-gradient(180deg, #FFD877, var(--amber) 55%, var(--amber-deep));
  box-shadow: 0 4px 0 var(--amber-deep), 0 9px 16px rgba(120, 70, 0, .4), inset 0 2px 0 rgba(255, 255, 255, .55);
  color: #5B3200;
  text-shadow: 0 2px 0 rgba(255, 255, 255, .35);
}
.btn--amber:active { box-shadow: 0 0 0 var(--amber-deep), inset 0 2px 0 rgba(255, 255, 255, .35); }

.btn--red {
  background: linear-gradient(180deg, #FF7A66, var(--gingham) 55%, var(--gingham-deep));
  box-shadow: 0 4px 0 var(--gingham-deep), 0 9px 16px rgba(120, 20, 10, .4), inset 0 2px 0 rgba(255, 255, 255, .4);
}
.btn--red:active { box-shadow: 0 0 0 var(--gingham-deep), inset 0 2px 0 rgba(255, 255, 255, .3); }

.btn--sky {
  background: linear-gradient(180deg, #8FE0FA, var(--sky) 55%, var(--sky-deep));
  box-shadow: 0 4px 0 var(--sky-deep), 0 9px 16px rgba(10, 70, 100, .4), inset 0 2px 0 rgba(255, 255, 255, .45);
}
.btn--sky:active { box-shadow: 0 0 0 var(--sky-deep), inset 0 2px 0 rgba(255, 255, 255, .3); }

.btn--ghost {
  background: rgba(245, 230, 200, .16);
  box-shadow: inset 0 0 0 2px rgba(245, 230, 200, .5);
  color: var(--kraft);
  text-shadow: 0 1px 2px rgba(0, 0, 0, .5);
}
.btn--ghost:active { transform: translateY(2px); }
.btn--ghost::after { content: none; }

/* The ghost button is cream-on-dark by default, which turns invisible on a kraft
   panel. Flip it to ink-on-paper wherever it sits on one. */
.panel .btn--ghost {
  background: rgba(34, 64, 14, .07);
  box-shadow: inset 0 0 0 2px rgba(34, 64, 14, .32);
  color: var(--brine-soft);
  text-shadow: none;
}

/* Small round icon button — settings, close, back.
   Never smaller than 44px: that's the minimum a thumb can reliably hit. */
.icon-btn {
  width: clamp(44px, 10.5cqw, 54px);
  height: clamp(44px, 10.5cqw, 54px);
  flex: none;
  display: grid;
  place-items: center;
  border-radius: var(--r-pill);
  background: linear-gradient(180deg, var(--kraft), var(--kraft-dim));
  box-shadow: 0 3px 0 rgba(110, 68, 31, .8), inset 0 2px 0 rgba(255, 255, 255, .6);
  font-size: var(--step-1);
  color: var(--brine);
  transition: transform var(--t-fast) var(--ease-pop);
}
.icon-btn:active { transform: translateY(3px); box-shadow: 0 0 0 rgba(110, 68, 31, .8); }

/* A drawn shape fills a proper share of the button and scales with it, unlike
   the '‹' glyph it replaced — that's a punctuation mark, and it rendered as a
   tiny tick lost in the middle of the circle. */
.icon-btn--shape svg {
  width: 52%;
  height: 52%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  /* Optical centring: a left chevron's mass sits right of its bounding box. */
  margin-right: 6%;
}

/* ============================================================
   Surfaces — kraft label paper and crate wood
   ============================================================ */
.panel {
  position: relative;
  background: linear-gradient(180deg, var(--cream), var(--kraft) 60%, var(--kraft-dim));
  border-radius: var(--r-lg);
  box-shadow: 0 6px 0 rgba(110, 68, 31, .5), 0 14px 34px rgba(0, 0, 0, .35), inset 0 2px 0 rgba(255, 255, 255, .7);
  padding: var(--sp-5);
}
/* Stitched label edge — a printed-label cue rather than a plain border. */
.panel--label::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 2px dashed rgba(110, 68, 31, .35);
  border-radius: calc(var(--r-lg) - 4px);
  pointer-events: none;
}

.crate-bar {
  /* Slatted wood: repeating linear gradient reads as planks at any width. */
  background:
    repeating-linear-gradient(90deg, rgba(0, 0, 0, .06) 0 2px, transparent 2px 26px),
    linear-gradient(180deg, #C98B4E, var(--crate) 60%, var(--crate-deep));
  box-shadow: 0 4px 0 rgba(60, 36, 15, .7), 0 10px 22px rgba(0, 0, 0, .35), inset 0 2px 0 rgba(255, 255, 255, .3);
}

/* ============================================================
   SIGNATURE: the brine meter.
   A progress bar that behaves like liquid in a jar — the surface has a
   wobbling meniscus and bubbles rise through it. Used for score/star
   progress everywhere in the game.
   ============================================================ */
.brine-meter {
  position: relative;
  height: 22px;
  border-radius: var(--r-pill);
  overflow: hidden;
  background: linear-gradient(180deg, #17300B, #26491A);
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, .6), 0 0 0 3px var(--brine), 0 2px 0 4px rgba(255, 255, 255, .18);
}
.brine-meter__fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(180deg, var(--dill-lit), var(--dill) 60%, var(--dill-deep));
  transition: width var(--t-slow) var(--ease-out);
}
/* The meniscus: the liquid's leading edge bulges and wobbles as it advances,
   rather than ending in a flat rectangle. */
.brine-meter__fill::after {
  content: '';
  position: absolute;
  top: -2px;
  bottom: -2px;
  right: -7px;
  width: 14px;
  border-radius: 50%;
  background: var(--dill-lit);
  animation: brine-wobble 1.6s ease-in-out infinite;
}
/* An empty jar has no surface to wobble — without this the meniscus sits as a
   stray blob at the left end at 0%. */
.brine-meter__fill[data-empty='1']::after { display: none; }
.brine-meter__bubbles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle, rgba(255, 255, 255, .7) 40%, transparent 42%),
    radial-gradient(circle, rgba(255, 255, 255, .5) 40%, transparent 42%),
    radial-gradient(circle, rgba(255, 255, 255, .6) 40%, transparent 42%);
  background-size: 5px 5px, 3px 3px, 4px 4px;
  background-position: 12% 80%, 38% 90%, 68% 85%;
  background-repeat: no-repeat;
  animation: brine-bubbles 2.4s linear infinite;
}
@keyframes brine-wobble {
  0%, 100% { transform: scaleX(1) scaleY(1); }
  50% { transform: scaleX(1.6) scaleY(.92); }
}
@keyframes brine-bubbles {
  0% { background-position: 12% 110%, 38% 130%, 68% 120%; opacity: 0; }
  20% { opacity: 1; }
  100% { background-position: 12% -20%, 38% -30%, 68% -25%; opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .brine-meter__fill::after, .brine-meter__bubbles { animation: none; }
}

/* Star pips riding on the meter, marking the 1/2/3-star score thresholds.
   Inset by half a pip so the 100% star doesn't get clipped by the pill edge. */
.brine-meter__pips { position: absolute; inset: 0 9px; pointer-events: none; }
.brine-meter__pip {
  position: absolute;
  top: 50%;
  translate: -50% -50%;
  width: 15px;
  height: 15px;
  filter: grayscale(1) brightness(.42) drop-shadow(0 1px 1px rgba(0, 0, 0, .8));
  transition: filter var(--t-mid), scale var(--t-mid) var(--ease-pop);
}
.brine-meter__pip[data-lit='1'] {
  filter: drop-shadow(0 0 5px rgba(255, 208, 36, .95));
  scale: 1.3;
}

/* ============================================================
   HUD chips — lives, coins, stars
   ============================================================ */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  flex: 0 1 auto;
  min-width: 0;
  white-space: nowrap;
  padding: 4px clamp(6px, 2.6cqw, 12px) 4px 4px;
  border-radius: var(--r-pill);
  background: linear-gradient(180deg, rgba(34, 64, 14, .9), rgba(20, 40, 6, .95));
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .18), 0 2px 0 rgba(0, 0, 0, .45);
  color: var(--cream);
  font-weight: 900;
  font-size: var(--step-0);
  font-variant-numeric: tabular-nums;
}
.chip__icon { width: clamp(20px, 6cqw, 28px); height: clamp(20px, 6cqw, 28px); flex: none; }
.chip__add {
  margin-left: 2px;
  flex: none;
  width: clamp(17px, 4.6cqw, 22px); height: clamp(17px, 4.6cqw, 22px);
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--dill);
  color: var(--cream);
  font-size: 14px;
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 1px 0 var(--dill-deep);
}
.chip__timer { font-size: var(--step--1); opacity: .8; font-weight: 700; margin-left: 2px; }

/* ============================================================
   Modals
   ============================================================ */
.modal-scrim {
  position: absolute;
  inset: 0;
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  padding: var(--sp-5);
  background: rgba(10, 22, 4, .72);
  backdrop-filter: blur(4px);
  animation: fade-in var(--t-mid) var(--ease-out) both;
}
.modal {
  width: 100%;
  max-width: 340px;
  text-align: center;
  animation: modal-pop var(--t-slow) var(--ease-pop) both;
}
.modal__title {
  font-family: var(--font-display);
  font-size: var(--step-3);
  color: var(--brine);
  margin-bottom: var(--sp-2);
}
.modal__body { font-size: var(--step-0); font-weight: 700; color: var(--brine-soft); margin-bottom: var(--sp-5); }
.modal__actions { display: flex; flex-direction: column; gap: var(--sp-3); }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-pop {
  from { opacity: 0; transform: translateY(24px) scale(.86); }
  to { opacity: 1; transform: none; }
}

/* ============================================================
   Toast
   ============================================================ */
.toast {
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--r-pill);
  background: rgba(34, 64, 14, .95);
  color: var(--cream);
  font-weight: 800;
  font-size: var(--step-0);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .4), inset 0 1px 0 rgba(255, 255, 255, .2);
  animation: toast-in var(--t-mid) var(--ease-pop) both;
}
.toast[data-leaving='1'] { animation: toast-out var(--t-mid) var(--ease-in) both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-12px) scale(.9); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-8px) scale(.95); } }

/* ============================================================
   Title banner — a painted stall board
   ============================================================ */
.banner {
  position: relative;
  align-self: center;
  padding: var(--sp-2) var(--sp-5);
  border-radius: var(--r-md);
  font-family: var(--font-display);
  font-size: var(--step-2);
  color: var(--cream);
  text-shadow: 0 3px 0 rgba(34, 64, 14, .8);
  background: linear-gradient(180deg, var(--dill-lit), var(--dill-deep));
  box-shadow: 0 4px 0 rgba(34, 64, 14, .8), 0 10px 24px rgba(0, 0, 0, .4), inset 0 2px 0 rgba(255, 255, 255, .4);
}

/* Last-resort error surface. A tap handler that dies silently is
   indistinguishable from a dead app — say so out loud instead. */
.fatal {
  position: absolute;
  left: 0; right: 0;
  bottom: 0;
  z-index: 999;
  padding: var(--sp-3) var(--sp-4);
  background: var(--gingham-deep);
  color: var(--cream);
  font-weight: 800;
  font-size: var(--step--1);
  text-align: center;
  box-shadow: 0 -4px 18px rgba(0, 0, 0, .5);
}

/* ?trace diagnostic panel. Tap it to copy the log. */
.trace {
  position: absolute;
  left: 0; right: 0; top: 0;
  z-index: 998;
  max-height: 44%;
  overflow: auto;
  padding: 6px 8px;
  background: rgba(0, 0, 0, .86);
  color: #7CFC5A;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 10px;
  line-height: 1.35;
  white-space: pre;
  pointer-events: auto;
}
.trace[data-copied='1']::after {
  content: ' ✓ copied';
  color: #FFD024;
}
