.valentine-workspace {
  grid-template-columns: clamp(74px, 10vw, 145px) minmax(0, 1fr);
  gap: 8px clamp(7px, 1.5vw, 20px);
  padding: 6px clamp(10px, 3vw, 44px) 0 8px;
  color: #57302a;
}
.luvi-stage .luvi-actor {
  width: clamp(148px, 20vw, 315px);
  height: clamp(148px, 20vw, 315px);
  bottom: 0;
}
.task-brief {
  width: auto;
  min-width: min(100%, 360px);
  padding: 4px 13px 5px;
  box-shadow: none;
}
.task-brief h2 { font-size: clamp(21px, 2.25vw, 30px); margin-bottom: 3px; }
.task-brief p { font-size: clamp(16px, 1.65vw, 22px); }
.task-model { container-type: size; display: block; }
.task-feedback {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.jigsaw-station {
  --trim: clamp(7px, 1.6cqw, 18px);
  --piece-gap: clamp(2px, 0.6cqw, 9px);
  --tray-padding: clamp(1px, 0.5cqw, 7px);
  --tray-chrome: calc(2 * (var(--trim) + var(--tray-padding)) + (var(--rows) - 1) * var(--piece-gap));
  width: min(100%, 1120px);
  height: 100%;
  margin-inline: auto;
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
  align-items: center;
  gap: clamp(8px, 2cqw, 22px);
}
.jigsaw-frame,
.jigsaw-tray {
  border: var(--trim) solid transparent;
  border-image: url('../shared-shell/assets/images/board-tray.webp') 17% fill / 1 round;
  box-shadow: 0 9px 18px #471d2244;
}
.jigsaw-frame {
  justify-self: center;
  width: min(100%, calc((100cqh - 2 * var(--trim)) * 4 / 3 + 2 * var(--trim)));
}
.jigsaw-picture {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #fff3d8;
  overflow: hidden;
  isolation: isolate;
}
.jigsaw-picture .jigsaw-guide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  opacity: var(--guide);
  user-select: none;
  pointer-events: none;
}
.jigsaw-picture.is-complete .jigsaw-guide { opacity: 1; }
.jigsaw-picture.is-complete .fitted { visibility: hidden; }
.jigsaw-space {
  position: absolute;
  width: calc(100% / var(--cols));
  height: calc(100% / var(--rows));
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
}
.jigsaw-space.fitted { z-index: 1; pointer-events: none; }
.jigsaw-space:focus-visible { z-index: 2; outline-offset: -4px !important; }
.jigsaw-space svg,
.jigsaw-ghost svg {
  position: absolute;
  width: 146%;
  height: 146%;
  left: -23%;
  top: -23%;
  pointer-events: none;
}
.jigsaw-cut { fill: none; stroke: #6b423d; stroke-width: 1.2; stroke-linejoin: round; }
.jigsaw-space:not(.fitted) .jigsaw-cut { stroke: #7d5647b0; }
.jigsaw-space.fitted .jigsaw-cut { stroke: #5932238c; }
.jigsaw-tray {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows), minmax(0, 1fr));
  align-self: center;
  gap: var(--piece-gap);
  padding: var(--tray-padding);
  user-select: none;
}
.jigsaw-piece {
  width: 100%;
  min-width: 0;
  aspect-ratio: calc(4 * var(--rows) / (3 * var(--cols)));
  display: block;
  position: relative;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  cursor: grab !important;
  -webkit-tap-highlight-color: transparent;
}
.jigsaw-piece svg {
  display: block;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 3px 2px #502b2859);
  pointer-events: none;
}
.jigsaw-piece.is-dragging { opacity: 0.28; }
.jigsaw-piece.is-selected {
  outline: 3px solid #933851;
  outline-offset: -1px;
  background: #f8d6d2;
}
.jigsaw-ghost { position: fixed; z-index: 10; transform: translate(-50%, -50%); pointer-events: none; }
.jigsaw-ghost svg { width: 100%; height: 100%; inset: 0; filter: drop-shadow(0 6px 5px #461e2259); }

@media (orientation: portrait) {
  .valentine-workspace { grid-template-columns: 1fr; padding: 3px 9px 0; gap: 6px; }
  .valentine-task-head { display: grid; grid-column: 1; grid-row: 1; grid-template-columns: 64px minmax(0, 1fr); min-height: 64px; align-items: center; }
  .luvi-stage { grid-row: 1; height: 66px; }
  .luvi-stage .luvi-actor { width: 106px; height: 106px; bottom: -12px; }
  .task-brief { grid-column: 2; min-width: 0; width: 100%; border-width: 7px; }
  .task-model, .task-feedback { grid-column: 1; }
  .jigsaw-station {
    --piece-height: clamp(44px, 13cqh, 96px);
    --between: 9px;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-content: center;
    justify-items: center;
    gap: var(--between);
  }
  .jigsaw-frame {
    width: min(100%, calc((100cqh - var(--rows) * var(--piece-height) - var(--tray-chrome) - var(--between) - 2 * var(--trim)) * 4 / 3 + 2 * var(--trim)));
  }
  .jigsaw-tray { width: min(100%, 440px, calc(100cqh * 1.08)); }
  .jigsaw-tray .jigsaw-piece { aspect-ratio: auto; height: var(--piece-height); }
  .jigsaw-piece svg { width: auto; max-width: 100%; height: 100%; aspect-ratio: calc(4 * var(--rows) / (3 * var(--cols))); margin: auto; }
}
@media (orientation: portrait) and (max-height: 720px) {
  .valentine-task-head { grid-template-columns: 44px minmax(0, 1fr); min-height: 44px; }
  .luvi-stage { height: 44px; }
  .luvi-stage .luvi-actor { width: 84px; height: 84px; bottom: -13px; }
  .task-brief { padding-block: 3px; }
  .task-brief h2 { display: none; }
  .task-brief p { font-size: 16px; }
}
@media (orientation: landscape) and (max-height: 600px) {
  .valentine-workspace { grid-template-columns: clamp(44px, 9vw, 93px) minmax(0, 1fr); padding: 1px 12px 0 4px; gap: 3px 8px; }
  .luvi-stage .luvi-actor { width: clamp(125px, 21vw, 214px); height: clamp(125px, 21vw, 214px); bottom: -12px; }
  .task-brief { min-width: 0; border-width: 6px; padding: 2px 8px; }
  .task-brief p { font-size: 15px; }
  .jigsaw-station { --trim: 7px; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 8px; }
  .jigsaw-tray { width: min(100%, calc(120cqh - 10px)); justify-self: start; }
  .jigsaw-piece { height: clamp(44px, calc((100cqh - var(--tray-chrome)) / var(--rows)), 82px); aspect-ratio: auto; }
  .jigsaw-piece svg { width: auto; height: 100%; max-width: 100%; margin: auto; aspect-ratio: calc(4 * var(--rows) / (3 * var(--cols))); }
}

