/* The Ice Cave. Its layout (the fixed overlay, the two-sided grid, the room layers
   and the creature slot) is shared with the other rooms in potions.css, and the
   pantry, plate and dish styles come from kitchen.css; this file is only what is
   the cave's own. See ICE-CAVE-PLAN.md. */

/* The frame rock and the floor around the edges, cooled to ice. */
#icecave {
  --rock-far: #16264d; --rock: #1d3166; --rock-lit: #3a6fae; --rock-edge: #5d93c9; --rock-fore: #10203f;
  --ice-edge: #bfe9ff;
}

/* ---------------------------------------------------------------- the room */

.icicle       { fill: #e9f8ff; opacity: 0.92; }
.ice-ceiling  { fill: #24427c; }
.ice-ripple   { fill: none; stroke: rgba(255, 255, 255, 0.16); stroke-width: 6; stroke-linecap: round; }
.ice-shard    { fill: #8fd3f5; opacity: 0.75; }
.ice-shard-lit { fill: #ffffff; opacity: 0.55; }
.ice-disc-rim { fill: none; stroke: rgba(255, 255, 255, 0.75); stroke-width: 3; stroke-dasharray: 4 8; }

.ice-block-top   { fill: #e6f6ff; }
.ice-block-front { fill: #9fd3f2; }
.ice-block-crack { fill: none; stroke: rgba(255, 255, 255, 0.7); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.ice-block-shine { fill: none; stroke: rgba(255, 255, 255, 0.6); stroke-width: 10; stroke-linecap: round; }
.ice-counter { filter: drop-shadow(0 -4px 18px rgba(191, 233, 255, 0.35)); }

#icecave .creature-slot { width: 30%; }

/* --------------------------------------------------------------- the benches */

/* Bases on the left in cream, flavours on the right in pink, each with a tab on
   its inner edge pointing at the bowl between them, the Zap Lab's way. */
.ice-shelf { grid-template-columns: repeat(3, 1fr); }
.bench-ice-bases {
  --bench-edge: #f3e3c3;
  background: linear-gradient(180deg, #4d5d86, #2b375a);
  box-shadow: 0 12px 30px rgba(7, 4, 15, 0.45), inset 0 0 0 3px var(--bench-edge);
}
.bench-ice-flavours {
  --bench-edge: #ff9ec4;
  background: linear-gradient(180deg, #5a3f78, #33244d);
  box-shadow: 0 12px 30px rgba(7, 4, 15, 0.45), inset 0 0 0 3px var(--bench-edge);
}
.bench-ice-bases, .bench-ice-flavours { position: relative; overflow-y: auto; }
.bench-ice-bases .ice-item { border-color: rgba(243, 227, 195, 0.6); background: linear-gradient(180deg, #6a7aa6, #3e4b74); }
.bench-ice-flavours .ice-item { border-color: rgba(255, 158, 196, 0.55); background: linear-gradient(180deg, #7a5598, #4a3366); }
.ice-item[aria-pressed="true"] { border-color: #ffffff; box-shadow: 0 0 0 2px #ffffff, 0 0 14px rgba(191, 233, 255, 0.8); }
.ice-item.bump { animation: bowl-bump 0.35s cubic-bezier(.3, 1.5, .5, 1); }

/* ------------------------------------------------------------- the bowl */

/* Anchored by its foot on the ice block. The back holds the inside of the bowl
   and the batter; the front is drawn over whatever is in it. */
.icebowl {
  position: absolute; aspect-ratio: 200 / 120; transform: translate(-50%, -100%);
  pointer-events: auto; touch-action: none; cursor: grab;
  --batter: 0; --b1: #ffffff; --b2: #ffffff;
}
.icebowl .bowl-back, .icebowl .bowl-front { position: absolute; inset: 0; pointer-events: none; }
.icebowl svg { width: 100%; height: 100%; display: block; overflow: visible; }
.bowl-back  { filter: drop-shadow(0 8px 8px rgba(7, 4, 15, 0.35)); }
.icebowl.bump .bowl-back, .icebowl.bump .bowl-front { animation: bowl-bump 0.35s cubic-bezier(.3, 1.5, .5, 1); }
.icebowl.over .bowl-front, .icebowl.can-drop .bowl-front { filter: drop-shadow(0 0 16px rgba(191, 233, 255, 0.95)); }
.batter { opacity: var(--batter); transition: opacity 0.2s ease; }
.batter-fill  { fill: var(--b1); }
.batter-swirl { fill: none; stroke: var(--b2); stroke-width: 6; stroke-linecap: round; opacity: 0.85; }
.bowl-band { stroke: var(--b1); opacity: calc(0.25 + var(--batter) * 0.5); }
/* mixed: the swirl flows along itself (a turn would carry it out of the flat oval
   of batter) and the bowl bobs to be carried to the freezer */
.icebowl.mixed .batter-swirl { stroke-dasharray: 16 9; animation: batter-flow 1.6s linear infinite; }
@keyframes batter-flow { to { stroke-dashoffset: -50; } }
.icebowl.mixed { animation: bowl-ready 1.4s ease-in-out infinite; }
@keyframes bowl-ready { 50% { translate: 0 -6px; } }
.icebowl.carried { animation: none; z-index: 20; scale: 1.05; }

.icebowl-contents { position: absolute; left: 10%; right: 10%; top: -30%; height: 52%; pointer-events: none; }
.in-icebowl {
  position: absolute; width: 26%; height: auto; transform: translateX(-50%) scale(var(--s, 1));
  transform-origin: 50% 100%; transition: transform 0.25s cubic-bezier(.3, 1.4, .5, 1);
  filter: drop-shadow(0 3px 3px rgba(7, 4, 15, 0.35));
}

/* The spoon, pointing up from its bowl end at the middle of the bowl. */
.spoon {
  /* its bowl end (95% down its box) at the middle of the bowl, 28% down */
  position: absolute; width: 14%; left: 43%; top: -93%;
  transform-origin: 50% 95%; transform: rotate(22deg);
  transition: transform 0.3s ease; pointer-events: none;
  filter: drop-shadow(0 6px 5px rgba(7, 4, 15, 0.35));
}
.spoon svg { width: 100%; height: auto; display: block; overflow: visible; }
.spoon-handle { fill: #d9a96a; }
.spoon-head   { fill: #c98f4e; }
.spoon-dip    { fill: #a8733a; }
.spoon-shine  { fill: none; stroke: rgba(255, 255, 255, 0.5); stroke-width: 3; stroke-linecap: round; }
.icebowl.stirring .spoon { transition: transform 0.06s linear; }
.icebowl.ready .spoon svg { animation: pestle-wiggle 1.6s ease-in-out infinite; transform-origin: 50% 95%; }
.icebowl.mixed .spoon { opacity: 0; }
.spoon.dip svg { animation: pestle-pound 0.28s ease-out; transform-origin: 50% 95%; }
.bowl-fx { position: absolute; inset: -40% 0 0; pointer-events: none; }
.icebowl .stir-hint { top: -40%; stroke: #ffffff; }

.ice-clear {
  position: absolute; transform: translate(-50%, -50%); z-index: 3;
  width: max(44px, 5%); aspect-ratio: 1; border-radius: 50%; padding: 0;
  font-size: clamp(1rem, 1.8vw, 1.4rem); line-height: 1;
  color: #1d3166; background: linear-gradient(180deg, #ffffff, #cfe6f8);
  border: 2px solid #8fbfe6; pointer-events: auto;
}
.ice-clear[hidden] { display: none; }

/* ---------------------------------------------------------- the freezer */

.freezer {
  position: absolute; aspect-ratio: 260 / 380; transform: translate(-50%, -100%);
  /* fitFreezer() may grow it with `scale`, about its left foot */
  transform-origin: 0 100%;
  pointer-events: auto; --frost: 0;
}
.freezer > svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block;
  filter: drop-shadow(0 10px 14px rgba(7, 4, 15, 0.45)); }
.freezer.over > svg, .freezer.can-drop > svg { filter: drop-shadow(0 0 18px rgba(191, 233, 255, 0.95)); }
.freezer.bump > svg, .freezer.nudge > svg { animation: bowl-bump 0.35s cubic-bezier(.3, 1.5, .5, 1); }
.frz-body   { stroke: #a9c7e6; stroke-width: 3; }
.frz-foot   { fill: #6f8fb5; }
.frz-panel  { fill: #d3e6f7; }
.frz-screen { fill: #0f2340; stroke: #6f8fb5; stroke-width: 3; }
.frz-seam   { stroke: #a9c7e6; stroke-width: 4; stroke-linecap: round; }
.frz-door-face { fill: #eef6fe; }
.frz-window { stroke: #8fbfe6; stroke-width: 4; }
.frz-inside { opacity: 0; transition: opacity 0.2s ease; }
.frz-glint  { fill: #ffffff; opacity: 0.35; }
.frz-handle { fill: #8fa9c8; }
/* the door flashes open on the ding: the window lights up from inside */
.freezer.open .frz-inside { opacity: 1; }
.freezer.open .frz-door { animation: door-open 1.2s ease; transform-origin: 6% 50%; transform-box: fill-box; }
@keyframes door-open { 15%, 70% { transform: scaleX(0.82) skewY(-3deg); } }

.frz-display {
  position: absolute; transform: translate(-50%, -50%);
  display: grid; place-items: center; pointer-events: none;
  font: 800 clamp(1.4rem, 3.6vw, 2.6rem)/1 ui-rounded, 'SF Pro Rounded', system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  color: #7dffb0; text-shadow: 0 0 10px rgba(125, 255, 176, 0.8);
}
/* its own keyframe on `scale`: bowl-bump's transform would undo the centring */
.frz-display.bump { animation: num-bump 0.3s cubic-bezier(.3, 1.5, .5, 1); }
@keyframes num-bump { 40% { scale: 1.18; } }
.freezer.running .frz-display { color: #8ff3ff; text-shadow: 0 0 12px rgba(143, 243, 255, 0.9); }

.frz-step, .frz-start {
  position: absolute; transform: translate(-50%, -50%); aspect-ratio: 1; border-radius: 50%; padding: 0;
  pointer-events: auto; touch-action: none;
}
.frz-step {
  min-width: 44px;
  font: 900 clamp(1.6rem, 3.8vw, 2.8rem)/1 ui-rounded, system-ui, sans-serif;
  color: #ffffff; background: radial-gradient(circle at 38% 32%, #8fd3ff, #2f7fd0 70%);
  border: 3px solid #ffffff; box-shadow: 0 4px 0 #1d4f8a, 0 6px 10px rgba(7, 4, 15, 0.35);
  transition: filter 0.2s ease;
}
.frz-step:active { transform: translate(-50%, -46%); box-shadow: 0 1px 0 #1d4f8a; }
.frz-step.off { filter: saturate(0.4) brightness(0.85); }
.frz-step.nudge { animation: zap-nudge 0.4s ease; }

/* The snowflake: sunk and pale until a bowl is in, then raised on a white ring and
   pulsing, like the Zapper's button. */
.frz-start {
  min-width: 48px;
  background: radial-gradient(circle at 38% 32%, #e9fbff, #7cc4ec 60%, #3a6fae);
  border: 3px solid #2f5f99; box-shadow: 0 1px 0 #1d3166;
  filter: saturate(0.4) brightness(0.8);
  transition: filter 0.2s ease, box-shadow 0.2s ease;
}
.frz-start svg { width: 74%; height: 74%; display: block; margin: auto; }
.frz-start .flake path { fill: none; stroke: #ffffff; stroke-width: 7; stroke-linecap: round; }
.frz-start.ready {
  filter: none; transform: translate(-50%, -54%);
  box-shadow: 0 0 0 4px #ffffff, 0 5px 0 #1d3166, 0 8px 14px rgba(7, 4, 15, 0.4);
  animation: frz-ready 1.1s ease-in-out infinite;
}
.frz-start.ready .flake { animation: flake-spin 6s linear infinite; transform-origin: 0 0; }
.frz-start:active { transform: translate(-50%, -46%); }
.frz-start.nudge { animation: zap-nudge 0.4s ease; }
.freezer.running .frz-start .flake { animation: flake-spin 1.6s linear infinite; transform-origin: 0 0; }
@keyframes frz-ready { 50% { box-shadow: 0 0 0 4px #ffffff, 0 5px 0 #1d3166, 0 0 26px 8px rgba(143, 243, 255, 0.85); } }
@keyframes flake-spin { to { rotate: 360deg; } }

/* The bowl in the window while it freezes, frosting over as the seconds go. */
.frz-load, .frz-frost { position: absolute; transform: translate(-50%, -50%); pointer-events: none; border-radius: 8%; overflow: hidden; }
.frz-load[hidden] { display: none; }
.mini-bowl { position: absolute; left: 18%; right: 18%; bottom: 10%; aspect-ratio: 200 / 120; }
.mini-bowl > svg, .mini-front { position: absolute; inset: 0; }
.mini-bowl svg { width: 100%; height: 100%; display: block; }
.mini-bowl .batter { opacity: 1; }
.mini-bowl .batter-fill { fill: var(--b1); }
.mini-bowl .batter-swirl { stroke: var(--b2); }
.mini-bowl .bowl-band { stroke: var(--b1); opacity: 0.6; }
.frz-frost {
  opacity: var(--frost); transition: opacity 0.9s linear;
  background:
    radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.9) 0 6%, transparent 18%),
    radial-gradient(circle at 80% 70%, rgba(255, 255, 255, 0.85) 0 5%, transparent 16%),
    radial-gradient(circle at 60% 20%, rgba(255, 255, 255, 0.7) 0 4%, transparent 14%),
    linear-gradient(160deg, rgba(240, 250, 255, 0.85), rgba(200, 232, 255, 0.55));
}
.freezer-fx { position: absolute; inset: -20%; pointer-events: none; }

/* ---------------------------------------------------------------- the treat */

.result-box-ice {
  background: radial-gradient(ellipse at 50% 45%, #3a6fae, #1d3166 72%);
  box-shadow: inset 0 0 0 3px rgba(191, 233, 255, 0.55), 0 10px 24px rgba(7, 4, 15, 0.35);
}
.result-reset-ice { color: #e9f8ff; border-color: rgba(191, 233, 255, 0.6); background: linear-gradient(180deg, #3a6fae, #1d3166); }
.dish.treat { filter: drop-shadow(0 10px 10px rgba(7, 4, 15, 0.45)) drop-shadow(0 0 20px var(--glow, #bfe9ff)); }
.treat-bits img {
  position: absolute; width: 30%; height: 30%;
  transform: translate(-50%, -50%) rotate(var(--r, 0deg));
  filter: drop-shadow(0 1px 2px rgba(7, 4, 15, 0.45));
}

/* Smaller iPads: three 54 px tiles and their gaps are 12 px wider than the 162 px
   inside a 196 px bench, so the tiles come down to 50 px (still over 44). */
@media (max-width: 1100px), (max-height: 560px) {
  .ice-shelf { gap: 4px; }
  .ice-item { width: 50px; height: 50px; }
}

/* Tall and narrow: the benches sit side by side beneath the scene. */
@media (max-aspect-ratio: 5/6) {
  .ice-shelf { grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  .icebowl.mixed, .icebowl.mixed .batter-swirl, .icebowl.ready .spoon svg,
  .frz-start.ready, .frz-start.ready .flake, .freezer.running .frz-start .flake { animation: none; }
}
