/* Masterpiece Swap. Safari 14.0 (iOS 14) has to draw all of this: no inset, no flex gap, no
   aspect-ratio, and svh only inside @supports. The stage has no size here; the script sets it. */
.game-root[data-game="masterpiece-swap"] {
  padding: clamp(12px, 2.4vw, 22px);
  background: linear-gradient(180deg, #f7f2e8 0%, #ede4d4 100%);
  border-color: #dccfb9;
  text-align: left;
}
.msw { position: relative; width: 100%; display: flex; flex-direction: column; align-items: center; }
/* Level on the left, the painting's name in the middle, the count on the right. The outer
   columns are equal so the name sits on the board's centre line. */
.msw-bar {
  width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) minmax(0, 1fr);
  align-items: baseline; column-gap: 12px; margin-bottom: 10px;
}
.msw-level { grid-column: 1; margin: 0; color: #3b3025; font: 700 1.02rem/1.2 Georgia, 'Iowan Old Style', 'Times New Roman', serif; }
.msw-title {
  grid-column: 2; margin: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; text-align: center;
  color: #2e251b; font: italic 700 1.12rem/1.3 Georgia, 'Iowan Old Style', 'Times New Roman', serif;
  /* Georgia stops at bold, so the extra weight is a hairline stroke. */
  -webkit-text-stroke: .35px currentColor;
}
.msw-count { grid-column: 3; justify-self: end; margin: 0; color: #8a7a66; font-size: .85rem; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* The box the board is fitted into. measure() reads max-height back as the board's height
   budget, so it has to stay a length that resolves to pixels. */
.msw-fit {
  width: 100%; display: flex; justify-content: center; align-items: center;
  max-height: max(260px, min(660px, calc(100vh - 250px)));
}
@supports (height: 1svh) {
  .msw-fit { max-height: max(260px, min(660px, calc(100svh - 250px))); }
}

.msw-stage {
  position: relative; flex: none; overflow: hidden; border-radius: 6px;
  background: #2b241c; box-shadow: 0 10px 28px rgba(60, 44, 26, .28);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.msw-tile {
  position: absolute; left: 0; top: 0; z-index: 1; cursor: grab; touch-action: none;
  transition: transform .24s cubic-bezier(.2, .8, .3, 1);
}
.msw-tile.is-lift { z-index: 30; cursor: grabbing; transition: none; }
.msw-tile.is-drop { z-index: 20; }
/* background-position moves with the edges: a seam opening or closing must not slide the picture. */
.msw-face {
  position: absolute; top: 0; right: 0; bottom: 0; left: 0; background-repeat: no-repeat;
  transition: top .2s ease, right .2s ease, bottom .2s ease, left .2s ease,
    background-position .2s ease, border-radius .2s ease, box-shadow .2s ease;
}
.msw-stage.is-still .msw-tile, .msw-stage.is-still .msw-face { transition: none; }
.msw-stage::after {
  content: ''; position: absolute; top: 0; bottom: 0; left: 0; z-index: 40; width: 45%;
  pointer-events: none; opacity: 0; transform: translateX(-110%);
  background: linear-gradient(100deg, rgba(255, 255, 255, 0) 0%, rgba(255, 250, 235, .4) 50%, rgba(255, 255, 255, 0) 100%);
}
.msw-stage.is-whole::after { animation: msw-sheen 1.1s ease-out .1s both; }
@keyframes msw-sheen {
  0% { opacity: 1; transform: translateX(-110%); }
  100% { opacity: 1; transform: translateX(260%); }
}
.msw-stage .jj-confetti { top: 0; left: 0; }

/* The first level's lesson: a faint copy of the pieces the hand drags, and the hand. */
.msw-ghost { position: absolute; left: 0; top: 0; z-index: 32; pointer-events: none; }
.msw-ghost > div { position: absolute; filter: drop-shadow(0 8px 12px rgba(0, 0, 0, .35)); }
.msw-hand {
  position: absolute; left: 0; top: 0; z-index: 34; pointer-events: none; width: 46px; height: 49px;
  margin: -3px 0 0 -16px; transform-origin: 34.4% 5.9%; transition: transform .12s ease;
}
.msw-hand.is-down { transform: scale(.86); }
.msw-hand[hidden], .msw-ghost[hidden] { display: none; }
.msw-hand svg { display: block; width: 100%; height: 100%; filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .4)); }
.msw-guide { transition: transform .25s ease, text-shadow .25s ease; }
.msw-guide.is-cue { transform: translateY(-3px); text-shadow: 0 0 10px rgba(92, 201, 141, .6); }

.msw-guide { margin: 12px 0 0; min-height: 1.4em; color: #6f604e; font-size: .9rem; text-align: center; }
.msw-controls { display: flex; flex-wrap: wrap; justify-content: center; margin: 2px -4px 0; }
.msw-controls > * { margin: 8px 4px 0; }
.msw-ctl {
  border: 1px solid #d6c8b1; border-radius: 10px; padding: 8px 14px; background: #fffaf1; color: #4a3d2f;
  font: inherit; font-size: .86rem; font-weight: 700; cursor: pointer;
}
.msw-ctl:hover:not(:disabled) { background: #fff3df; }
.msw-ctl:disabled { opacity: .35; cursor: default; }
.msw-nav { display: inline-flex; align-items: center; }
.msw-nav > * + * { margin-left: 6px; }
.msw-step { display: inline-flex; align-items: center; padding: 7px 10px; }
/* A level arrow that cannot be pressed is not shown, but keeps its room: with display: none the
   board would change size and shift sideways from level to level. */
.msw-step:disabled, .msw-side:disabled { visibility: hidden; }
.msw-where { min-width: 4.2em; color: #4a3d2f; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }
/* The arrows beside the board, on a computer only; the small ones in the row below stand in
   for them on a phone. measure() takes their width and margins off the board's room. */
.msw-side { display: none; }
@media (min-width: 1000px) {
  .msw-side {
    display: flex; flex: none; align-items: center; justify-content: center;
    width: 54px; height: 54px; margin: 0 18px; padding: 0;
    border: 1px solid #d6c8b1; border-radius: 50%; background: #fffaf1; color: #4a3d2f;
    box-shadow: 0 3px 10px rgba(60, 44, 26, .16); cursor: pointer;
  }
  .msw-side:hover:not(:disabled) { background: #fff3df; }
  .msw-side:disabled { opacity: .3; cursor: default; box-shadow: none; }
  .msw-side .msw-icon { width: 30px; height: 30px; stroke-width: 3; }
  .msw-nav .msw-step { display: none; }
  .msw-nav .msw-where { margin-left: 0; }
}

/* The end of a level, laid over the whole game rather than the board: the board can be shorter
   than the card. */
.msw-win {
  position: absolute; top: 0; right: 0; bottom: 0; left: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 10px;
  background: rgba(43, 36, 28, .35);
}
.msw-win:empty { display: none; }
.msw-card {
  width: 100%; max-width: 360px; max-height: 100%; overflow-y: auto; padding: 18px 20px 16px;
  border-radius: 18px; background: #fffaf1; color: #3b3025; text-align: center;
  box-shadow: 0 16px 40px rgba(40, 28, 16, .35);
  animation: msw-pop .34s cubic-bezier(.3, 1.4, .5, 1);
}
@keyframes msw-pop { from { opacity: 0; transform: scale(.88); } to { opacity: 1; transform: scale(1); } }
.msw-card-title { margin: 0 0 8px; color: #8a5a17; font-size: .95rem; font-weight: 800; }
.msw-card-pic {
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  margin: 0; color: #2e251b; font: italic 700 1.2rem/1.3 Georgia, 'Iowan Old Style', 'Times New Roman', serif;
}
.msw-card-by { margin: 4px 0 0; color: #6f604e; font-size: .88rem; }
.msw-card-link { display: inline-block; margin-top: 6px; font-size: .84rem; }
.msw-card-small { margin: 8px 0 0; color: #a3968a; font-size: .8rem; }
.msw-card-btns { display: flex; flex-wrap: wrap; justify-content: center; margin: 6px -4px 0; }
.msw-card-btns > * { margin: 8px 4px 0; }
.msw-card-btn { display: inline-flex; align-items: center; }
.msw-icon { flex: none; width: 18px; height: 18px; }
.msw-card-btn > .msw-icon { margin-right: 6px; }
.msw-feel { margin: 14px 0 0; color: #6f604e; font-size: .86rem; font-weight: 700; }
.msw-moods { display: flex; flex-wrap: wrap; justify-content: center; margin: 2px -3px 0; }
.msw-moods > * { margin: 6px 3px 0; }
.msw-mood {
  display: inline-flex; align-items: center; padding: 6px 11px; border: 1px solid #d6c8b1; border-radius: 999px;
  background: #fff; color: #4a3d2f; font: inherit; font-size: .82rem; font-weight: 700; cursor: pointer;
}
.msw-mood > .msw-icon { margin-right: 5px; }
.msw-mood.is-on { border-color: #8a5a17; background: #fdf0d6; color: #8a5a17; }
.msw-note { min-height: 1.3em; margin: 8px 0 0; color: #6f604e; font-size: .8rem; line-height: 1.4; }
.msw-note kbd { padding: 1px 5px; border: 1px solid #d6c8b1; border-radius: 4px; background: #fff; font: inherit; font-size: .78rem; }

/* Mode 3 — phone: the panel sheds its card and reaches the page gutter. */
@media (max-width: 640px) {
  .game-root[data-game="masterpiece-swap"] {
    padding: 10px 8px 14px; margin-left: -8px; margin-right: -8px;
    border-left: 0; border-right: 0; border-radius: 0; box-shadow: none;
  }
  /* Too narrow for three columns: the name takes its own line on top, up to two lines long. */
  .msw-bar { grid-template-columns: minmax(0, 1fr) auto; row-gap: 4px; }
  .msw-title {
    grid-column: 1 / -1; grid-row: 1; white-space: normal;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  }
  .msw-level { grid-row: 2; }
  .msw-count { grid-column: 2; grid-row: 2; }
  .msw-fit { max-height: max(220px, min(62vh, calc(100vh - 230px))); }
  @supports (height: 1svh) {
    .msw-fit { max-height: max(220px, min(62svh, calc(100svh - 230px))); }
  }
}

/* Mode 2 — page-filling. The panel is game-layout.css's; the board takes what the rows leave. */
/* The rows stay together as one group in the middle; measure() sizes the board from the panel. */
html.fills-window .game-root[data-game="masterpiece-swap"] .msw { height: 100%; justify-content: center; }
html.fills-window .game-root[data-game="masterpiece-swap"] .msw > * { flex: none; }
html.fills-window .game-root[data-game="masterpiece-swap"] .msw-fit { max-height: none; }
