/* Sewing machine minigame (src/ui/sewing.js) */

/* The card is a fixed-height column; the board takes all the room left over
   and the painting covers it (see layout() in sewing.js). */
.card.wide.mg-sew,
body.crafting .card.wide.mg-sew {
  display: flex; flex-direction: column;
  width: min(980px, 100%);
  height: min(860px, calc(100vh - 36px));
  height: min(860px, calc(100dvh - 36px));
  max-height: none;
  overflow: hidden;
  padding: 14px 18px 12px;
  text-align: left;
  touch-action: manipulation;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
body.crafting .card.wide.mg-sew {
  height: min(860px, calc(100vh - 84px));
  height: min(860px, calc(100dvh - 84px - env(safe-area-inset-top, 0px)));
  max-height: calc(100dvh - 84px - env(safe-area-inset-top, 0px)) !important;
}

.mg-sew .sew-head {
  flex: none;
  display: flex; align-items: center; gap: 14px;
  margin: 0 2px 10px;
}
.mg-sew h2 { flex: none; font-size: 26px; margin: 0; }
.mg-sew .sew-skip { flex: none; min-height: 48px; min-width: 84px; margin: 0; padding: 10px 20px; font-size: 16px; }

/* progress: a little tape measure with a spool riding along it */
.mg-sew .sew-tape {
  position: relative; flex: 1 1 auto; min-width: 60px; height: 16px; border-radius: 5px;
  background:
    repeating-linear-gradient(90deg, rgba(94, 70, 63, 0.55) 0 1px, transparent 1px 10px) 0 0 / 100% 5px no-repeat,
    repeating-linear-gradient(90deg, rgba(94, 70, 63, 0.7) 0 1.5px, transparent 1.5px 50px) 0 0 / 100% 9px no-repeat,
    #f6dc96;
  box-shadow: inset 0 -2px 0 rgba(94, 70, 63, 0.12), 0 2px 0 var(--line);
}
.mg-sew .sew-tape-fill {
  position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 5px 0 0 5px;
  background: linear-gradient(90deg, rgba(111, 143, 104, 0.55), rgba(111, 143, 104, 0.85));
}
.mg-sew .sew-tape-spool {
  position: absolute; top: 50%; left: 0; width: 22px; height: 26px; transform: translate(-50%, -50%);
  border-radius: 6px;
  background: linear-gradient(180deg, #e2bf8f 0 4px, var(--rose-deep) 4px calc(100% - 4px), #e2bf8f calc(100% - 4px));
  box-shadow: 0 2px 4px rgba(70, 40, 20, 0.3);
}

/* the board */
.mg-sew .sew-board {
  position: relative;
  flex: 1 1 auto; min-height: 0;
  width: 100%;
  border-radius: 18px; overflow: hidden;
  background: #c98a4e;
  box-shadow: inset 0 0 0 1px rgba(94, 70, 63, 0.15), 0 6px 18px rgba(94, 70, 63, 0.18);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  cursor: pointer;
}
.mg-sew .sew-board:focus { outline: none; }
.mg-sew .sew-board:focus-visible { box-shadow: 0 0 0 3px var(--rose-deep), 0 6px 18px rgba(94, 70, 63, 0.18); }
.mg-sew .sew-board canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.mg-sew kbd {
  display: inline-block; min-width: 1.6em; padding: 0 5px; margin: 0 1px;
  border-radius: 6px; background: var(--paper); box-shadow: 0 2px 0 var(--line), inset 0 0 0 1px var(--line);
  font: 800 0.86em/1.5 "Nunito", system-ui, sans-serif; color: var(--cocoa); text-align: center;
}

/* accuracy dial, on the wood to the left of the fabric */
.mg-sew .sew-dial {
  position: absolute; left: 16px; top: 34%; width: 78px; height: 78px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 50%; background: rgba(255, 250, 243, 0.94);
  box-shadow: 0 6px 14px rgba(70, 40, 20, 0.28), 0 0 0 4px rgba(159, 183, 154, 0.45);
  pointer-events: none;
  transition: box-shadow 0.35s;
}
.mg-sew .sew-dial svg { position: absolute; inset: 5px; width: calc(100% - 10px); height: calc(100% - 10px); transform: rotate(-90deg); }
.mg-sew .sew-dial circle { fill: none; stroke-width: 5; }
.mg-sew .sew-dial .ring-bg { stroke: #efe2d4; }
.mg-sew .sew-dial .ring { stroke: var(--sage-deep, #6f8f68); stroke-linecap: round; stroke-dasharray: 100 100; transition: stroke 0.35s, stroke-dasharray 0.25s; }
.mg-sew .sew-dial b { position: relative; font: 700 17px/1 "Fraunces", Georgia, serif; color: var(--cocoa); }
.mg-sew .sew-dial small {
  position: absolute; top: calc(100% + 7px); left: 50%; transform: translateX(-50%);
  padding: 2px 9px; border-radius: 99px; background: rgba(255, 250, 243, 0.94);
  box-shadow: 0 3px 8px rgba(70, 40, 20, 0.22);
  font-size: 12px; font-weight: 800; white-space: nowrap; color: var(--sage-deep, #6f8f68);
}
.mg-sew .sew-dial.off small { color: var(--rose-deep); }
.mg-sew .sew-dial.off { box-shadow: 0 6px 14px rgba(70, 40, 20, 0.28), 0 0 0 4px rgba(231, 160, 171, 0.6); }
.mg-sew .sew-dial.off .ring { stroke: var(--rose-deep); }

/* "a little left / right" */
.mg-sew .sew-nudge {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -50%) scale(0.85);
  padding: 9px 16px; border-radius: 999px;
  background: #fffaf3; color: var(--rose-dark, #a2556a);
  font-weight: 900; font-size: 18px; white-space: nowrap;
  box-shadow: 0 6px 16px rgba(70, 40, 20, 0.28), inset 0 0 0 2.5px var(--rose);
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.mg-sew .sew-nudge b { font-size: 1.25em; line-height: 0; vertical-align: -0.06em; }
.mg-sew .sew-nudge.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* "hold here" prompt, under the pulsing ring on the lane */
.mg-sew .sew-prompt {
  position: absolute; left: 50%; top: 60%; transform: translate(-50%, 6px);
  width: max-content; max-width: min(440px, calc(100% - 24px));
  padding: 12px 22px; border-radius: 22px;
  background: rgba(255, 250, 243, 0.97); color: var(--cocoa);
  font-weight: 800; font-size: 19px; line-height: 1.3; text-align: center;
  box-shadow: 0 10px 24px rgba(70, 40, 20, 0.3), inset 0 0 0 2px #fff, inset 0 0 0 4px var(--line);
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
}
.mg-sew .sew-prompt::before {
  content: ""; position: absolute; left: 50%; top: -10px; margin-left: -10px;
  border: 10px solid transparent; border-top: 0; border-bottom-color: rgba(255, 250, 243, 0.97);
}
.mg-sew .sew-prompt.show { opacity: 1; transform: translate(-50%, 0); animation: sew-bob 2.4s ease-in-out infinite; }
@keyframes sew-bob { 50% { transform: translate(-50%, -5px); } }

/* all sewn */
.mg-sew .sew-banner {
  position: absolute; inset: 0; display: grid; place-items: center;
  pointer-events: none;
  background: rgba(94, 70, 63, 0.2);
  animation: fade 0.25s ease;
}
.mg-sew .sew-banner > div {
  max-width: calc(100% - 28px);
  padding: 22px 40px 18px; border-radius: 24px; text-align: center;
  background: var(--paper);
  box-shadow: 0 14px 34px rgba(70, 40, 20, 0.3), inset 0 0 0 2px #fff, inset 0 0 0 4px var(--line);
  animation: pop 0.4s cubic-bezier(.2, 1.4, .4, 1);
}
.mg-sew .sew-banner h3 { margin: 0; font-size: 36px; }
.mg-sew .sew-banner .stars { margin: 6px 0 2px; font-size: 38px; line-height: 1; letter-spacing: 4px; }
.mg-sew .sew-banner .stars i { font-style: normal; color: #eadccb; }
.mg-sew .sew-banner .stars i.on { color: #f2bf4a; text-shadow: 0 2px 0 #c9902a; }
.mg-sew .sew-banner p { margin: 4px 0 0; font-weight: 700; color: var(--cocoa-soft); }
.mg-sew .sew-banner .rating { font-family: "Fraunces", Georgia, serif; font-size: 21px; font-weight: 700; color: var(--rose-deep); }
.mg-sew .sew-banner .pct { font-size: 13.5px; }

/* control hints (desktop) */
.mg-sew .sew-hints { flex: none; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 8px; margin-top: 10px; }
.mg-sew .sew-hints span {
  padding: 4px 12px; border-radius: 99px; background: #f7ebdf;
  font-size: 13px; font-weight: 700; color: var(--cocoa-soft);
}
.mg-sew.touch .sew-hints { display: none; }
.mg-sew.touch .sew-board { cursor: default; }

body.reduce-motion .mg-sew .sew-prompt.show,
body.reduce-motion .mg-sew .sew-banner,
body.reduce-motion .mg-sew .sew-banner > div { animation: none; }
body.reduce-motion .mg-sew .sew-nudge,
body.reduce-motion .mg-sew .sew-prompt { transition: none; }

@media (max-width: 760px) {
  .card.wide.mg-sew, body.crafting .card.wide.mg-sew { padding: 10px 10px 10px; border-radius: 22px; }
  .mg-sew .sew-head { display: grid; grid-template-columns: 1fr auto; gap: 8px 10px; margin: 0 2px 8px; }
  .mg-sew h2 { font-size: 21px; align-self: center; }
  .mg-sew .sew-tape { grid-column: 1 / -1; grid-row: 2; height: 14px; margin: 0 10px 2px; }
  .mg-sew .sew-board { border-radius: 14px; }
  .mg-sew .sew-dial { left: auto; right: 10px; top: 12px; width: 60px; height: 60px; }
  .mg-sew .sew-dial b { font-size: 13px; }
  .mg-sew .sew-dial small { font-size: 10.5px; top: calc(100% + 5px); padding: 1px 7px; }
  .mg-sew .sew-nudge { font-size: 16px; padding: 8px 13px; }
  .mg-sew .sew-prompt { font-size: 17px; padding: 11px 16px; }
  .mg-sew .sew-banner > div { padding: 16px 20px 14px; }
  .mg-sew .sew-banner h3 { font-size: 28px; }
  .mg-sew .sew-banner .stars { font-size: 32px; }
  .mg-sew .sew-hints span { font-size: 11.5px; padding: 3px 10px; }
}
@media (max-height: 560px) {
  .card.wide.mg-sew, body.crafting .card.wide.mg-sew { padding-top: 8px; padding-bottom: 8px; }
  .mg-sew .sew-head { margin-bottom: 6px; }
  .mg-sew h2 { font-size: 20px; }
  .mg-sew .sew-hints { display: none; }
}
