/* Cutting table minigame (src/ui/cutting.js). Everything is scoped under .mg-cut. */

.layer:has(> .mg-cut) { padding: 14px; }

.card.wide.mg-cut {
  width: min(1260px, 100%);
  height: min(880px, calc(100vh - 28px));
  max-height: none;
  display: flex; flex-direction: column; gap: 10px;
  padding: 14px 18px 16px;
  overflow: hidden;
  background: #e2b98a url(img/cutting-table.webp) center / cover no-repeat;
  box-shadow: 0 24px 70px rgba(70, 40, 25, 0.38), inset 0 0 0 1px rgba(255, 240, 220, 0.25);
  text-align: left;
}

/* ---------- header note ---------- */
.mg-cut .mgc-head { display: flex; justify-content: center; flex: none; }
.mg-cut .mgc-note {
  position: relative;
  background: var(--paper);
  background-image: linear-gradient(transparent 0 calc(100% - 3px), rgba(201, 111, 128, 0.18) 0);
  padding: 9px 26px 10px;
  border-radius: 6px 6px 14px 14px;
  box-shadow: 0 6px 14px rgba(70, 40, 25, 0.22);
  transform: rotate(-0.6deg);
  text-align: center;
}
.mg-cut .mgc-note::before {
  content: ""; position: absolute; top: -5px; left: 50%; width: 12px; height: 12px; margin-left: -6px;
  border-radius: 50%; background: radial-gradient(circle at 35% 35%, #f6c3cc, var(--rose-deep) 70%);
  box-shadow: 0 2px 2px rgba(70, 40, 25, 0.35);
}
.mg-cut .mgc-note h2 { font-size: 24px; margin: 0; }
.mg-cut .mgc-note p { margin: 2px 0 0; font-size: 14px; color: var(--cocoa-soft); }

/* ---------- stage ---------- */
.mg-cut .mgc-stage {
  position: relative; flex: 1; min-height: 0;
  touch-action: none; user-select: none; -webkit-user-select: none;
  outline: none;
}
.mg-cut .mgc-stage > * { position: absolute; }
.mg-cut .mgc-holes, .mg-cut .mgc-pieces { inset: 0; pointer-events: none; }
.mg-cut .mgc-cutlines { left: 0; top: 0; pointer-events: none; overflow: visible; z-index: 6; }

/* tray: a pattern envelope on the table */
.mg-cut .mgc-tray {
  background: rgba(255, 250, 243, 0.62);
  border: 2px dashed rgba(122, 90, 70, 0.32);
  border-radius: 18px;
  box-shadow: 0 4px 14px rgba(70, 40, 25, 0.14), inset 0 0 0 4px rgba(255, 250, 243, 0.35);
  backdrop-filter: blur(1.5px);
  transition: background 0.2s, border-color 0.2s;
}
.mg-cut .mgc-tray.hover { background: rgba(255, 250, 243, 0.85); border-color: var(--sage-deep); }
.mg-cut .mgc-tray-label {
  position: absolute; top: 5px; left: 14px;
  font-size: 11px; font-weight: 800; letter-spacing: 0.09em; text-transform: uppercase; color: var(--cocoa-soft);
  white-space: nowrap; max-width: calc(100% - 20px); overflow: hidden; text-overflow: ellipsis;
}
.mg-cut .mgc-tray-empty {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-family: "Fraunces", Georgia, serif; font-style: italic; font-size: 16px; color: var(--cocoa-soft);
  opacity: 0; transition: opacity 0.3s;
}
.mg-cut .mgc-tray.empty .mgc-tray-empty { opacity: 1; }
.mg-cut .mgc-tray.empty .mgc-slot { opacity: 0.5; }
.mg-cut .mgc-slot { position: absolute; overflow: visible; }
.mg-cut .mgc-slot path { fill: rgba(122, 90, 70, 0.05); stroke: rgba(122, 90, 70, 0.3); stroke-width: 1.2; stroke-dasharray: 4 4; }

/* tape measure */
.mg-cut .mgc-ruler {
  background: linear-gradient(#f8e19a, #ecc66a);
  border-radius: 3px;
  box-shadow: 0 2px 3px rgba(70, 40, 20, 0.3);
}
.mg-cut .mgc-stage.vert .mgc-ruler { background: linear-gradient(90deg, #ecc66a, #f8e19a); }
.mg-cut .mgc-ruler svg { display: block; overflow: visible; }
.mg-cut .mgc-ruler line { stroke: #7a5a2e; stroke-width: 1; }
.mg-cut .mgc-ruler text { font: 800 10.5px "Nunito", system-ui, sans-serif; fill: #6b4a25; }

/* fabric */
.mg-cut .mgc-board { filter: drop-shadow(0 7px 9px rgba(70, 40, 20, 0.36)); }
.mg-cut .mgc-cloth { position: absolute; inset: 0; }
.mg-cut .mgc-cloth svg { position: absolute; left: 0; top: 0; display: block; }
.mg-cut .mgc-grid .g { stroke: rgba(70, 45, 30, 0.1); stroke-width: 1; }
.mg-cut .mgc-grid .gm { stroke: rgba(70, 45, 30, 0.22); stroke-width: 1; stroke-dasharray: 5 4; }
.mg-cut .mgc-grid.dark .g { stroke: rgba(255, 245, 230, 0.1); }
.mg-cut .mgc-grid.dark .gm { stroke: rgba(255, 245, 230, 0.24); }
.mg-cut .mgc-grid .sv { fill: rgba(255, 252, 245, 0.34); }
.mg-cut .mgc-grid .svd { stroke: rgba(94, 70, 63, 0.32); stroke-width: 1.4; stroke-dasharray: 1 3.5; }
.mg-cut .mgc-grid.dark .svd { stroke: rgba(255, 245, 230, 0.4); }
.mg-cut .mgc-grid .mill { font-family: "Nunito", system-ui, sans-serif; font-weight: 800; letter-spacing: 0.12em; fill: rgba(94, 70, 63, 0.4); }
.mg-cut .mgc-grid.dark .mill { fill: rgba(255, 245, 230, 0.45); }
.mg-cut .mgc-bolt { position: absolute; overflow: hidden; border-radius: 9px; box-shadow: 2px 0 6px rgba(70, 40, 20, 0.3); }
.mg-cut .mgc-bolt[hidden] { display: none; }
.mg-cut .mgc-bolt svg { display: block; width: 100%; height: 100%; }
.mg-cut .mgc-bolt::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, rgba(60, 35, 20, 0.3), rgba(255, 255, 255, 0.3) 35%, rgba(255, 255, 255, 0.05) 55%, rgba(60, 35, 20, 0.38));
}
.mg-cut .mgc-bolt.down::after { background: linear-gradient(180deg, rgba(60, 35, 20, 0.3), rgba(255, 255, 255, 0.3) 35%, rgba(255, 255, 255, 0.05) 55%, rgba(60, 35, 20, 0.38)); }

/* where the cut pieces came from */
.mg-cut .mgc-holes svg { position: absolute; overflow: visible; }
.mg-cut .mgc-holes path { fill: #c08349; stroke: rgba(70, 40, 20, 0.35); stroke-width: 1.5; animation: mgc-fade 0.3s ease both; }

/* chalk line at the end of what's used */
.mg-cut .mgc-used {
  z-index: 1; pointer-events: none;
  border-left: 2px dashed rgba(255, 255, 255, 0.92);
  filter: drop-shadow(0 0 1px rgba(94, 70, 63, 0.55));
  transition: left 0.3s ease, top 0.3s ease;
}
.mg-cut .mgc-used.down { border-left: 0; border-top: 2px dashed rgba(255, 255, 255, 0.92); }
.mg-cut .mgc-used[hidden] { display: none; }
.mg-cut .mgc-used span {
  position: absolute; top: 1px; left: -1px; transform: translateX(-50%);
  background: var(--rose-deep); color: #fff; font-size: 11px; font-weight: 800; line-height: 1;
  padding: 3px 6px; border-radius: 999px; white-space: nowrap; filter: none;
}
.mg-cut .mgc-used.down span { top: -1px; left: 0; transform: translate(-30%, -50%); }

/* landing preview */
.mg-cut .mgc-ghost { z-index: 2; pointer-events: none; opacity: 0; transition: opacity 0.12s, left 0.07s, top 0.07s; }
.mg-cut .mgc-ghost.on { opacity: 1; }
.mg-cut .mgc-ghost svg { display: block; width: 100%; height: 100%; overflow: visible; }
.mg-cut .mgc-ghost path { fill: rgba(159, 210, 150, 0.5); stroke: #4f7f48; stroke-width: 2.2; stroke-dasharray: 6 4; }
.mg-cut .mgc-ghost.bad path { fill: rgba(240, 160, 172, 0.55); stroke: var(--rose-deep); }

/* ---------- paper pieces ---------- */
.mg-cut .mgc-piece {
  position: absolute; pointer-events: none;
  filter: drop-shadow(0 2px 1.5px rgba(70, 45, 25, 0.3));
  transition: left 0.3s cubic-bezier(.25, .9, .3, 1.08), top 0.3s cubic-bezier(.25, .9, .3, 1.08),
    width 0.3s ease, height 0.3s ease, transform 0.2s ease, filter 0.2s ease;
  z-index: 3;
}
.mg-cut .mgc-piece > svg { display: block; width: 100%; height: 100%; overflow: visible; transition: opacity 0.5s ease; }
.mg-cut .mgc-piece .hit { pointer-events: visiblePainted; cursor: grab; }
.mg-cut .mgc-piece text {
  font-family: "Nunito", system-ui, sans-serif; font-weight: 800; fill: #6b4a30;
  text-anchor: middle; dominant-baseline: central;
}
.mg-cut .mgc-piece .edge { stroke: #a77848; stroke-width: 1.2; }
.mg-cut .mgc-piece .tint { fill: #f2909f; opacity: 0; transition: opacity 0.2s; }
.mg-cut .mgc-piece.bad .tint { opacity: 0.5; }
.mg-cut .mgc-piece.bad .edge { stroke: var(--rose-deep); stroke-width: 2.2; }
.mg-cut .mgc-piece.sel .edge { stroke: var(--rose-deep); stroke-width: 2.6; }
.mg-cut .mgc-piece.sel { filter: drop-shadow(0 3px 3px rgba(70, 45, 25, 0.32)) drop-shadow(0 0 4px rgba(255, 245, 230, 0.9)); }
.mg-cut .mgc-stage.instant .mgc-piece,
.mg-cut .mgc-stage.instant .mgc-used { transition: none !important; }
.mg-cut .mgc-piece.intro { animation: mgc-in 0.42s cubic-bezier(.2, 1.3, .4, 1) both; }
.mg-cut .mgc-piece.held { z-index: 5; }
.mg-cut .mgc-piece.dragging {
  z-index: 8;
  transition: width 0.16s ease, height 0.16s ease, filter 0.15s ease, transform 0.15s ease;
  transform: scale(1.035);
  filter: drop-shadow(0 14px 10px rgba(70, 45, 25, 0.3));
}
.mg-cut .mgc-piece.dragging .hit { cursor: grabbing; }
.mg-cut .mgc-piece.glide { transition-duration: 0.55s; }
.mg-cut .mgc-piece.spin { animation: mgc-spin 0.3s ease-in-out; }
.mg-cut .mgc-piece.land { animation: mgc-land 0.26s ease-out; }
.mg-cut .mgc-piece.wiggle { animation: mgc-wiggle 0.45s ease; }
.mg-cut .mgc-piece.cut {
  transform: translateY(-5px);
  filter: drop-shadow(0 10px 7px rgba(60, 35, 20, 0.34));
  transition: transform 0.35s cubic-bezier(.2, 1.4, .4, 1), filter 0.35s ease;
}
.mg-cut .mgc-fab { position: absolute; left: 0; top: 0; width: 100%; height: 100%; }
.mg-cut .mgc-fab svg { display: block; width: 100%; height: 100%; }
.mg-cut.mgc-allcut .mgc-piece > svg { opacity: 0; }
.mg-cut .mgc-board, .mg-cut .mgc-holes { transition: opacity 0.5s ease, filter 0.5s ease; }
.mg-cut.mgc-allcut .mgc-board { opacity: 0.45; filter: saturate(0.6) drop-shadow(0 4px 6px rgba(70, 40, 20, 0.2)); }
.mg-cut.mgc-allcut .mgc-holes { opacity: 0; }
.mg-cut.mgc-allcut .mgc-piece.cut { transform: translateY(-7px) scale(1.02); }
.mg-cut.mgc-cutting .mgc-piece .hit { cursor: default; }

/* scissors and the finale */
.mg-cut .mgc-scissors {
  left: 0; top: 0; width: 84px; height: 84px; z-index: 9; pointer-events: none;
  opacity: 0; transition: opacity 0.2s;
  filter: drop-shadow(0 4px 3px rgba(60, 35, 20, 0.35));
}
.mg-cut .mgc-scissors.on { opacity: 1; }
.mg-cut .mgc-scissors svg { display: block; overflow: visible; }
.mg-cut .mgc-scissors g { transform-box: view-box; transform-origin: 50% 50%; }
.mg-cut .mgc-scissors .b1 { animation: mgc-snip1 0.2s ease-in-out infinite alternate; }
.mg-cut .mgc-scissors .b2 { animation: mgc-snip2 0.2s ease-in-out infinite alternate; }
.mg-cut .mgc-cutlines path { fill: none; stroke: rgba(70, 45, 30, 0.75); stroke-width: 1.6; stroke-linejoin: round; }
.mg-cut .mgc-done {
  left: 50%; top: 50%; z-index: 10; pointer-events: none;
  transform: translate(-50%, -50%) scale(0.7); opacity: 0;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: var(--paper); padding: 16px 38px 18px; border-radius: 22px;
  box-shadow: 0 16px 40px rgba(70, 40, 25, 0.35);
  transition: transform 0.4s cubic-bezier(.2, 1.5, .4, 1), opacity 0.25s ease;
}
.mg-cut .mgc-done.on { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.mg-cut .mgc-done b { white-space: nowrap; font-family: "Fraunces", Georgia, serif; font-size: 36px; color: var(--rose-deep); line-height: 1.1; }
.mg-cut .mgc-done span { white-space: nowrap; font-size: 14px; color: var(--cocoa-soft); }

/* ---------- footer ---------- */
.mg-cut .mgc-foot {
  flex: none; display: flex; align-items: center; gap: 14px;
  background: rgba(255, 250, 243, 0.94);
  border-radius: 18px; padding: 10px 12px 10px 20px;
  box-shadow: 0 6px 18px rgba(70, 40, 25, 0.2);
}
.mg-cut .mgc-status { flex: 1; min-width: 0; }
.mg-cut .mgc-line { font-size: 15.5px; color: var(--cocoa); line-height: 1.35; }
.mg-cut .mgc-line b { color: var(--rose-dark); }
.mg-cut .mgc-hint { font-size: 13.5px; color: var(--cocoa-soft); min-height: 1.3em; margin-top: 1px; }
.mg-cut .mgc-hint.warn { color: var(--rose-dark); font-weight: 700; }
.mg-cut .mgc-hint.good { color: var(--sage-deep); font-weight: 800; }
.mg-cut .mgc-actions { display: flex; gap: 10px; align-items: center; flex: none; transition: opacity 0.2s; }
.mg-cut .mgc-actions .btn { margin-top: 0; }
.mg-cut .mgc-go { padding: 11px 28px; font-size: 17px; }
.mg-cut .mgc-go[aria-disabled="true"] { background: #d9b8b8; box-shadow: 0 4px 0 #c29b9e; cursor: default; }
.mg-cut .mgc-go[aria-disabled="true"]:hover { transform: none; }
.mg-cut .mgc-go.ready { animation: pulse 1.6s ease-in-out infinite; }
.mg-cut.mgc-cutting .mgc-actions { opacity: 0.35; pointer-events: none; }
.mg-cut.mgc-cutting .mgc-go { animation: none; }

@keyframes mgc-in { from { opacity: 0; transform: translateY(14px) scale(0.85); } }
@keyframes mgc-spin { to { transform: rotate(180deg); } }
@keyframes mgc-land { 0% { transform: scale(1.05); } 60% { transform: scale(0.985); } 100% { transform: scale(1); } }
@keyframes mgc-wiggle { 20% { transform: rotate(-4deg); } 45% { transform: rotate(3.5deg); } 70% { transform: rotate(-2deg); } }
@keyframes mgc-snip1 { from { transform: rotate(-16deg); } to { transform: rotate(-2deg); } }
@keyframes mgc-snip2 { from { transform: rotate(16deg); } to { transform: rotate(2deg); } }
@keyframes mgc-fade { from { opacity: 0; } }

.reduce-motion .mg-cut .mgc-piece.intro, .reduce-motion .mg-cut .mgc-go.ready { animation: none; }

/* ---------- phones: the roll runs top to bottom ---------- */
@media (max-width: 760px) {
  .layer:has(> .mg-cut) { padding: 6px; }
  .card.wide.mg-cut {
    height: calc(100vh - 12px); height: calc(100dvh - 12px);
    padding: 8px 8px 10px; gap: 8px; border-radius: 20px;
  }
  .mg-cut .mgc-note { padding: 6px 16px 7px; }
  .mg-cut .mgc-note h2 { font-size: 19px; }
  .mg-cut .mgc-note p { font-size: 12.5px; }
  .mg-cut .mgc-foot { flex-direction: column; align-items: stretch; gap: 8px; padding: 9px 10px 10px; text-align: center; }
  .mg-cut .mgc-line { font-size: 14px; }
  .mg-cut .mgc-hint { font-size: 12.5px; }
  .mg-cut .mgc-actions .btn { flex: 1; }
  .mg-cut .mgc-go { padding: 10px 18px; font-size: 16px; }
  .mg-cut .mgc-tray-label { font-size: 9.5px; left: 9px; letter-spacing: 0.05em; }
  .mg-cut .mgc-done { padding: 14px 26px 16px; }
  .mg-cut .mgc-done b { font-size: 30px; }
}

/* the exact cells a piece covers, chalked faintly around the paper */
.mg-cut .mgc-piece .cells { fill: rgba(255, 252, 245, 0.1); stroke: rgba(255, 255, 255, 0.6); stroke-width: 1; stroke-dasharray: 3 3; }
.mg-cut .mgc-piece.cut .cells { opacity: 0; }
.mg-cut .mgc-tray { transition: background 0.2s, border-color 0.2s, opacity 0.4s; }
.mg-cut.mgc-cutting .mgc-tray { opacity: 0.35; }

/* short landscape screens: give the table the room */
@media (max-height: 520px) {
  .layer:has(> .mg-cut) { padding: 6px; }
  .card.wide.mg-cut { height: calc(100vh - 12px); height: calc(100dvh - 12px); padding: 6px 10px 8px; gap: 6px; }
  .mg-cut .mgc-note { padding: 4px 16px 5px; }
  .mg-cut .mgc-note h2 { font-size: 17px; }
  .mg-cut .mgc-note p { display: none; }
  .mg-cut .mgc-foot { padding: 6px 8px 6px 14px; }
  .mg-cut .mgc-line { font-size: 13.5px; }
  .mg-cut .mgc-hint { font-size: 12px; }
  .mg-cut .mgc-go { padding: 8px 20px; font-size: 15px; }
}

/* Touch screens: no iOS long-press callout or scroll chaining while dragging pieces. */
.mg-cut .mgc-stage { -webkit-touch-callout: none; overscroll-behavior: contain; }
