/* Leftover Pirates (js/arcade/pirates.js). Every class starts with .lp- */

/* --d: how many pirates; --coin: the size of a coin; --rows: the most coins a column will hold */
.lp-wrap {
  --coin: 22px;
  --deck: color-mix(in srgb, var(--sun-d) 45%, var(--ink));
  --wood: color-mix(in srgb, var(--sun) 34%, white);
  --navy: color-mix(in srgb, var(--grape-d) 35%, var(--ink));
  position: relative; display: grid; gap: 8px; width: min(100%, 600px); margin: 0 auto; padding-bottom: 14px;
}
.lp-wrap.lp-big { --coin: 18px; }

/* ---------- HUD: the question she is on, the stars she can win, the score ---------- */
.lp-hud { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 4px 14px; font: 700 14px var(--font-ui); color: var(--muted); }
.lp-hud b { color: var(--ink); font-size: 19px; }
.lp-stars { display: inline-flex; gap: 3px; }
.lp-star {
  --f: 0%; width: 24px; height: 24px;
  clip-path: polygon(50% 2%, 62% 36%, 98% 37%, 69% 59%, 80% 94%, 50% 73%, 20% 94%, 31% 59%, 2% 37%, 38% 36%);
  background: linear-gradient(90deg, var(--sun) var(--f), var(--tile-shadow) var(--f));
}
.lp-star.lp-half { --f: 50%; }
.lp-star.lp-full { --f: 100%; animation: lp-pop 0.45s; }
@keyframes lp-pop { 0% { transform: scale(0.6); } 60% { transform: scale(1.25); } 100% { transform: none; } }

/* ---------- the question: the number sentence, its check, and the words she reads ---------- */
.lp-ask { display: grid; justify-items: center; gap: 2px; padding: 6px 10px 8px; border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow-soft); text-align: center; }
.lp-sum { font: 900 clamp(24px, 7.4vw, 36px)/1.25 var(--font-ui); color: var(--grape-d); white-space: nowrap; }
.lp-rem { font: 700 0.62em var(--font-read); color: var(--ink); }
.lp-box {
  display: inline-block; min-width: 1.25em; padding: 0 5px; border-radius: 10px; text-align: center;
  border: 3px dashed var(--grape); color: var(--grape); background: color-mix(in srgb, var(--grape) 8%, white);
}
.lp-box.lp-filled { border-style: solid; border-color: var(--green-d); color: var(--green-d); background: color-mix(in srgb, var(--green) 18%, white); animation: lp-pop 0.45s; }
.lp-check { min-height: 26px; font: 800 20px/1.3 var(--font-ui); color: var(--green-d); white-space: nowrap; }
.lp-words { margin: 0; font: 700 17px/1.3 var(--font-read); color: var(--ink); }

/* ---------- the pile of gold (tap it to deal) and the parrot on its perch ---------- */
.lp-deck { display: grid; grid-template-columns: minmax(0, 1fr) 92px; gap: 8px; align-items: stretch; }
.lp-pile {
  position: relative; display: grid; gap: 6px; justify-items: center; align-content: center; width: 100%; min-height: 96px; padding: 10px 8px 12px;
  border: 0; border-radius: var(--radius); cursor: pointer; touch-action: manipulation; font: inherit; color: var(--ink);
  background: var(--wood); box-shadow: inset 0 0 0 3px var(--sun-d), 0 5px 0 var(--sun-d);
}
.lp-pile:active { transform: translateY(3px); box-shadow: inset 0 0 0 3px var(--sun-d), 0 2px 0 var(--sun-d); }
.lp-heap { display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: 2px; max-width: 100%; }
.lp-heap .lp-coin { --coin: 20px; }
.lp-tap { font: 800 17px/1.2 var(--font-ui); color: var(--card); padding: 6px 16px; border-radius: 999px; background: var(--grape); box-shadow: 0 3px 0 var(--grape-d); }
.lp-pile:not(.lp-shut) .lp-tap { animation: lp-nudge 1.8s ease-in-out infinite; }
.lp-pile.lp-shut .lp-tap { background: var(--card); color: var(--muted); box-shadow: 0 3px 0 var(--tile-shadow); }
@keyframes lp-nudge { 0%, 70%, 100% { transform: none; } 80% { transform: scale(1.07); } 90% { transform: scale(0.98); } }

.lp-coin {
  display: block; flex: none; width: var(--coin); height: var(--coin); border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--sun) 50%, white) 0 18%, var(--sun) 19% 58%, color-mix(in srgb, var(--sun) 70%, var(--sun-d)) 59%);
  box-shadow: inset 0 0 0 2px var(--sun-d);
}

.lp-perch { display: grid; justify-items: center; align-content: end; gap: 2px; padding: 4px 2px 6px; border-radius: var(--radius); background: color-mix(in srgb, var(--sky) 22%, white); box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--sky) 55%, white); }
.lp-parrot-art { display: block; width: 62px; height: auto; overflow: visible; }
.lp-dish { display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: 1px; width: 100%; min-height: 36px; }
.lp-dish .lp-coin { --coin: 16px; }
.lp-wood { fill: none; stroke: var(--deck); stroke-width: 6; stroke-linecap: round; }
.lp-plume { fill: var(--green); stroke: var(--green-d); stroke-width: 2.5; }
.lp-wing { fill: var(--sky); stroke: var(--sky-d); stroke-width: 2.5; stroke-linejoin: round; }
.lp-tail, .lp-crest { fill: var(--danger); stroke: var(--danger-d); stroke-width: 2; stroke-linejoin: round; }
.lp-beak { fill: var(--sun); stroke: var(--sun-d); stroke-width: 2; stroke-linejoin: round; }
.lp-claw { fill: none; stroke: var(--sun-d); stroke-width: 3.5; stroke-linecap: round; }
.lp-bird { transform-box: fill-box; transform-origin: 50% 100%; }
/* the parrot bobs: when a coin is his, and when she is right */
.lp-bob .lp-bird { animation: lp-bob 0.7s ease-in-out; }
@keyframes lp-bob { 20% { transform: translateY(-9px) rotate(-8deg); } 45% { transform: translateY(0) rotate(6deg); } 70% { transform: translateY(-6px) rotate(-4deg); } }

/* ---------- the crew: a pirate at the head of each column of coins ---------- */
.lp-crew {
  display: grid; grid-template-columns: repeat(var(--d), minmax(0, 64px)); justify-content: center; gap: 2px; min-height: 216px; padding: 8px 6px 10px;
  border-radius: var(--radius); background: repeating-linear-gradient(90deg, var(--wood) 0 38px, color-mix(in srgb, var(--sun) 46%, white) 38px 40px);
  box-shadow: inset 0 0 0 3px var(--sun-d), var(--shadow-soft);
}
.lp-crew.lp-nobody { grid-template-columns: 1fr; }
.lp-hint { grid-column: 1 / -1; align-self: center; text-align: center; font: 700 16px var(--font-read); color: var(--deck); }
.lp-mate { display: grid; justify-items: center; align-content: start; gap: 4px; min-width: 0; }
.lp-pirate { display: block; width: 100%; max-width: 60px; height: auto; overflow: visible; }
.lp-stack { display: grid; justify-items: center; align-content: start; min-height: 140px; }
.lp-stack .lp-coin + .lp-coin { margin-top: calc(min(var(--coin) + 2px, 138px / var(--rows, 5)) - var(--coin)); }
.lp-wrap.lp-right .lp-crew { box-shadow: inset 0 0 0 4px var(--green-d), var(--shadow-soft); }

.lp-c-sky { --cloth: var(--sky); --cloth-d: var(--sky-d); }
.lp-c-rose { --cloth: var(--rose); --cloth-d: var(--rose-d); }
.lp-c-grape { --cloth: var(--grape); --cloth-d: var(--grape-d); }
.lp-c-lime { --cloth: var(--lime); --cloth-d: var(--lime-d); }
.lp-c-sun { --cloth: var(--sun); --cloth-d: var(--sun-d); }
.lp-c-teal { --cloth: var(--teal); --cloth-d: var(--teal-d); }
.lp-skin-1 { --skin: color-mix(in srgb, var(--sun) 28%, white); --skin-d: color-mix(in srgb, var(--sun-d) 55%, white); }
.lp-skin-2 { --skin: color-mix(in srgb, var(--sun-d) 45%, white); --skin-d: color-mix(in srgb, var(--sun-d) 80%, var(--ink)); }
.lp-skin-3 { --skin: color-mix(in srgb, color-mix(in srgb, var(--sun-d) 60%, var(--danger-d)) 62%, var(--ink)); --skin-d: color-mix(in srgb, var(--sun-d) 30%, var(--ink)); }
.lp-face { fill: var(--skin); stroke: var(--skin-d); stroke-width: 2; }
.lp-cheek { fill: var(--rose); opacity: 0.55; }
.lp-eye { fill: var(--ink); }
.lp-smile { fill: none; stroke: var(--ink); stroke-width: 2.4; stroke-linecap: round; }
.lp-beard { fill: var(--deck); }
.lp-patch { fill: var(--ink); }
.lp-strap { fill: none; stroke: var(--ink); stroke-width: 2; }
.lp-shirt { stroke: var(--navy); stroke-width: 2; stroke-linejoin: round; }
.lp-white { fill: var(--card); }
.lp-cloth { fill: var(--cloth); stroke: var(--cloth-d); stroke-width: 2; stroke-linejoin: round; }
.lp-stripe { fill: none; stroke: var(--cloth-d); stroke-width: 4; }
.lp-belt { fill: none; stroke: var(--navy); stroke-width: 4; }
.lp-hat-dark { fill: var(--navy); stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; }
.lp-trim { fill: none; stroke: var(--sun); stroke-width: 2.5; stroke-linecap: round; }
.lp-band { fill: none; stroke: var(--cloth-d); stroke-width: 5; stroke-linecap: round; }
.lp-gold { fill: var(--sun); stroke: var(--sun-d); stroke-width: 1.5; }
.lp-dot { fill: var(--card); }
.lp-feather { fill: var(--rose); stroke: var(--rose-d); stroke-width: 1.5; stroke-linejoin: round; }
.lp-hat { transform-box: fill-box; transform-origin: 15% 100%; }
/* a pirate tips his hat when she is right */
.lp-tip .lp-hat { animation: lp-tip 0.8s ease-in-out; }
@keyframes lp-tip { 30%, 60% { transform: translateY(-7px) rotate(-24deg); } }

.lp-msg { min-height: 46px; margin: 0; display: grid; place-items: center; text-align: center; font: 700 16px/1.35 var(--font-read); color: var(--ink); }

/* ---------- the answers ---------- */
.lp-answer { display: grid; gap: 6px; }
.lp-label { text-align: center; font: 800 17px/1.2 var(--font-read); color: var(--grape-d); }
.lp-choices { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.lp-choice { min-height: 56px; padding: 8px 4px; color: var(--ink); font: 900 30px/1 var(--font-ui); touch-action: manipulation; }
.lp-choice.lp-gone { opacity: 0.35; }
.lp-choice.lp-yes { background: var(--green); box-shadow: 0 5px 0 var(--green-d); color: var(--card); }

/* a round that can't be dealt, and a wrong answer: a little shake */
.lp-no { animation: lp-no 0.32s; }
@keyframes lp-no { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* iPad: more room */
@media (min-width: 700px) {
  .lp-wrap { gap: 12px; --coin: 26px; }
  .lp-wrap.lp-big { --coin: 22px; }
  .lp-sum { font-size: 50px; }
  .lp-check { font-size: 26px; min-height: 34px; }
  .lp-words { font-size: 21px; }
  .lp-msg { font-size: 19px; }
  .lp-deck { grid-template-columns: minmax(0, 1fr) 130px; }
  .lp-parrot-art { width: 84px; }
  .lp-heap .lp-coin { --coin: 24px; }
  .lp-dish .lp-coin { --coin: 20px; }
  .lp-crew { grid-template-columns: repeat(var(--d), minmax(0, 76px)); min-height: 250px; }
  .lp-pirate { max-width: 72px; }
  .lp-stack { min-height: 160px; }
  .lp-stack .lp-coin + .lp-coin { margin-top: calc(min(var(--coin) + 2px, 158px / var(--rows, 5)) - var(--coin)); }
  .lp-choice { min-height: 66px; font-size: 36px; }
  .lp-label { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .lp-star.lp-full, .lp-box.lp-filled, .lp-no, .lp-bob .lp-bird, .lp-tip .lp-hat, .lp-pile:not(.lp-shut) .lp-tap { animation: none; }
}
