@font-face {
  font-family: "P052";
  src: url("fonts/P052-Bold.otf") format("opentype");
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: "Z003";
  src: url("fonts/Z003-MediumItalic.otf") format("opentype");
  font-style: italic;
  font-display: swap;
}
:root {
  color-scheme: light;
  font-family: "DM Sans", "Trebuchet MS", Arial, sans-serif;
  color: #204c45;
  background: #f8f2f3;
  --ink: #204c45;
  --muted: #4d625d;
  --berry: #863653;
  --brand-cherry: #81304e;
  --mint-border: #a5cfc2;
  --grain: url("paper-grain.webp");
  --room-height: max(100svh, 810px);
  --mint-paper: linear-gradient(135deg, #f3fff8 3%, #d9efe4 70%, #cce7dd);
  --rose-paper: linear-gradient(135deg, #fff4ef, #f4d9e4 74%, #efd0de);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  position: relative;
  isolation: isolate;
  background: #dba28b;
}
button { font: inherit; cursor: pointer; color: inherit; }
button:focus-visible, a:focus-visible, .board:focus-visible {
  outline: 2px solid #a03c68;
  outline-offset: 3px;
}
[hidden] { display: none !important; }

.winter-room {
  position: absolute;
  z-index: -1;
  inset: 0 0 auto;
  height: var(--room-height);
  pointer-events: none;
  background: url("winter-window-room.webp") center center / cover no-repeat;
}
.page {
  position: relative;
  width: min(100% - 56px, 1160px);
  margin: 0 auto;
}
.masthead {
  display: grid;
  justify-items: center;
  text-align: center;
  padding: clamp(18px, 2.8vh, 34px) 0 clamp(18px, 2.7vh, 30px);
  background: radial-gradient(ellipse at center, #fff9f2ce 0%, #fff8f2a8 37%, #fff8f200 72%);
}
.brand {
  color: #a74971;
  font-size: 13px;
  line-height: 16px;
}
h1 {
  display: flex;
  align-items: baseline;
  gap: .22em;
  margin: 7px 0 0;
  color: var(--brand-cherry);
  font: 700 clamp(37px, 5.1vw, 75px)/1.02 "P052", Georgia, serif;
  letter-spacing: -.04em;
  text-shadow: 0 1px 0 #fffdf3, 0 0 20px #fff7ed;
}
h1 span {
  position: relative;
  top: -.07em;
}
h1 em {
  position: relative;
  top: .10em;
  color: #408575;
  font: italic 400 .94em/1 "Z003", cursive;
  letter-spacing: 0;
}
#instructions {
  margin: 11px 0 0;
  max-width: 48ch;
  color: #364e47;
  font-size: .91rem;
  line-height: 1.45;
}
.layout {
  --game-width: clamp(365px, calc(80svh - 210px), 530px);
  display: grid;
  grid-template-columns: minmax(170px, 1fr) minmax(0, var(--game-width)) minmax(170px, 1fr);
  grid-template-areas: "controls game shelf" "picker game shelf" ". game shelf" ". celebration .";
  grid-template-rows: auto auto 1fr 0;
  column-gap: clamp(20px, 3.2vw, 50px);
  row-gap: 15px;
  align-items: start;
  padding-bottom: 30px;
}
.layout:has(.celebration:not([hidden])) { grid-template-rows: auto auto 1fr auto; }
.panel {
  min-width: 0;
  border: 1px solid #a3c5b7;
  border-radius: 21px;
  background: var(--grain), var(--mint-paper);
  box-shadow:
    0 4px 0 #8cb7a63e,
    0 11px 26px #4a756c29,
    inset 0 0 0 3px #ffffff77,
    inset 0 0 0 4px #8fb7a338;
}
.controls, .picker {
  --glass-edge: #faffffdc;
  --glass-glow: #bdfdf4a8;
  --glass-ink: #163934;
  border-color: var(--glass-edge);
  background: linear-gradient(148deg, #fff9, #f3fff449 52%, #dcfff258);
  backdrop-filter: blur(5px) saturate(.86);
  box-shadow:
    inset 0 1px 0 #fff,
    inset 0 0 0 2px #eafffa2d,
    0 0 13px var(--glass-glow),
    0 5px 15px #33314b34;
  color: var(--glass-ink);
}
.controls { grid-area: controls; padding: 17px; display: grid; gap: 13px; }
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.metrics > div {
  min-width: 0;
  padding: 10px 9px;
  border-radius: 12px;
  border: 1px solid #faffffbf;
  background: linear-gradient(150deg, #fff8, #dcfff648);
  box-shadow: inset 0 1px 0 #fff9, 0 0 5px #d9fff86b;
}
.metrics > div + div {
  background: linear-gradient(150deg, #fff9, #ffd6e562);
}
.caption {
  color: var(--muted);
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .11em;
  text-transform: uppercase;
}
.metrics .caption { display: block; margin-bottom: 5px; }
.metrics strong { font: 400 26px/1 Georgia, serif; font-variant-numeric: tabular-nums; }
.total { color: var(--muted); font-size: .74rem; white-space: nowrap; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 9px 13px;
  border: 1px solid var(--mint-border);
  border-radius: 12px;
  text-decoration: none;
  text-align: center;
  font-size: .83rem;
  font-weight: 700;
}
.button-secondary {
  color: #255248;
  background: var(--grain), linear-gradient(#fcfff9, #cce9dd);
  box-shadow: inset 0 1px 1px #fff9, 0 2px 0 #7da8933d;
}
.button-secondary:hover { background: var(--grain), linear-gradient(#f8fff6, #b8e3d3); border-color: #80b5a5; }
.button-primary {
  color: #fff;
  background: var(--grain), linear-gradient(#a75178, #84395c);
  border-color: #873453;
}
.button-primary:hover { background: var(--grain), linear-gradient(#974368, #803254); }
.controls .caption, .controls .total {
  color: var(--glass-ink);
  text-shadow: 0 0 4px #fff;
}
#reset, .levels button {
  color: var(--glass-ink);
  border-color: var(--glass-edge);
  background: linear-gradient(160deg, #fff9, #f5fff750 65%, #effffe62);
  box-shadow: inset 0 1px 0 #fff8, 0 0 5px #f8fffd75, 0 2px 3px #33314b1f;
  text-shadow: 0 0 4px #fff;
}
#reset:hover, .levels button:hover {
  border-color: #fff;
  background: linear-gradient(160deg, #fffc, #edfff8a0);
  box-shadow: inset 0 1px 0 #fff, 0 0 9px var(--glass-glow);
}
#reset span { font-size: 19px; line-height: 1; }
.picker {
  grid-area: picker;
  padding: 10px 12px;
  --glass-glow: #ffdeedb8;
  background: linear-gradient(148deg, #fff9, #ffeff058 55%, #ffe3f16b);
}
.panel-title {
  margin: 0 0 12px;
  color: var(--glass-ink);
  font: 400 23px/1.13 Georgia, serif;
  text-shadow: 0 0 6px #fff, 0 0 11px #fff;
}
.picker .panel-title {
  margin-bottom: 7px;
  font-size: 20px;
  text-align: center;
}
.levels { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; }
.levels button {
  position: relative;
  min-height: 30px;
  padding: 2px 0;
  border: 1px solid var(--glass-edge);
  border-radius: 10px;
  font-size: .84rem;
  font-weight: 800;
}
.levels button[data-complete]::after {
  content: "";
  position: absolute;
  top: 5px;
  right: 5px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
}
.levels button[aria-current="step"] {
  background: linear-gradient(155deg, #ffe7f5d6, #f5b3d593);
  border-color: #fff5fd;
  color: #692645;
  box-shadow: inset 0 0 0 1px #ad5d8a80, 0 0 8px #fff1fa, 0 0 13px #ed8fbf9c;
}

.postcard-shelf {
  grid-area: shelf;
  position: relative;
  padding: 17px 16px 23px;
  border-color: #fff6f1e8;
  border-radius: 19px 19px 11px 11px;
  background: linear-gradient(155deg, #fff9f1dc, #ffe7e8a3 65%, #f7d2c08f);
  backdrop-filter: blur(5px);
  box-shadow: inset 0 1px 0 #fff, inset 0 0 0 3px #fff5ed62, 0 7px 19px #4d354631;
}
.postcard-shelf::after {
  content: "";
  position: absolute;
  inset: auto -4px -4px;
  height: 13px;
  border: 1px solid #ecc0a4;
  border-radius: 4px 4px 7px 7px;
  background: linear-gradient(#ffe4c9 0 25%, #deb094 27%, #cd977b 75%, #e5b99c);
  box-shadow: 0 4px 7px #6646313b;
  pointer-events: none;
}
.postcard-shelf .panel-title {
  width: fit-content;
  margin: 0 auto 13px;
  padding: 4px 15px 5px;
  border: 1px solid #e8bda5;
  border-radius: 8px;
  background: linear-gradient(#fff1de, #f3d5c2);
  box-shadow: inset 0 1px #fff9, 0 2px 4px #71433326;
  color: #753a4e;
  font-size: clamp(19px, 1.8vw, 24px);
}
.shelf-empty {
  margin: 0;
  padding: 4px 0 13px;
  color: #4b514d;
  font-size: .83rem;
  line-height: 1.45;
}
.shelf-cards {
  --card-width: clamp(53px, 6vw, 76px);
  --card-height: calc(var(--card-width) * 1402 / 1122 + 4px);
  --row-gap: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--card-width), 1fr));
  grid-auto-rows: var(--card-height);
  justify-items: center;
  gap: var(--row-gap) 7px;
  max-height: calc(2 * var(--card-height) + var(--row-gap) + 22px);
  margin: 0;
  padding: 16px 7px 6px;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
  scrollbar-color: #a3677c #fff3ed;
  list-style: none;
}
.shelf-cards li { position: relative; }
.shelf-cards li:nth-child(3n + 1) { --card-tilt: -2.5deg; }
.shelf-cards li:nth-child(3n) { --card-tilt: 2.5deg; }
.shelf-cards button {
  display: block;
  width: var(--card-width);
  padding: 0;
  border: 2px solid #fff7ef;
  border-radius: 6px;
  background: #fffbf7;
  box-shadow: 0 3px 7px #683a482c;
  transform: rotate(var(--card-tilt, 0deg));
  transition: transform 180ms ease, box-shadow 180ms ease;
}
.shelf-cards li:focus-within { z-index: 1; }
.shelf-cards button:focus-visible { border-color: #d69cb2; }
@media (hover: hover) and (pointer: fine) {
  .shelf-cards li:hover { z-index: 2; }
  .shelf-cards button:hover {
    border-color: #d69cb2;
    box-shadow: 0 6px 12px #683a4850;
    transform: translateY(-5px) scale(1.12);
  }
}
.shelf-cards img { display: block; width: 100%; height: auto; border-radius: 4px; }

.postcard-preview {
  position: fixed;
  width: min(70vw, 290px, 55svh);
  max-height: calc(100svh - 24px);
  padding: 12px;
  border: 1px solid #fff8ee;
  border-radius: 18px;
  background: var(--rose-paper);
  color: #71364e;
  text-align: center;
  box-shadow: 0 9px 36px #5731455c;
}
.postcard-preview::backdrop { background: #34212c54; }
.postcard-preview img { display: block; width: 100%; height: auto; border-radius: 8px; }
.postcard-close {
  position: absolute;
  top: 15px;
  right: 15px;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid #fff;
  border-radius: 50%;
  background: #fff7efee;
  color: #71364e;
  font-size: 23px;
}
.postcard-save {
  margin-top: 10px;
  padding-inline: 22px;
  border-color: #d3a1b5;
  color: #71364e;
  background: linear-gradient(#fffcf4, #efd5e2);
  box-shadow: 0 2px 4px #683a4825;
}
.postcard-save:hover { background: #fff9f6; }
.download-error, .celebration .download-error {
  margin: 6px 0 0;
  color: #75334c;
  font: 500 .78rem/1.35 system-ui, sans-serif;
}

.table-notebook {
  --room-image-height: max(var(--room-height), 100vw * 941 / 1672);
  position: absolute;
  top: calc(var(--room-height) * .5 + var(--room-image-height) * .391);
  right: calc(50% + var(--game-width) / 2 + 8px);
  display: block;
  width: clamp(260px, 35vw, 570px);
  max-width: calc((100vw - var(--game-width)) / 2 + 48px);
  height: auto;
  /* Turn the notebook on the tabletop, accounting for foreshortening. */
  --notebook-turn: scaleY(.65) rotate(-20deg) scaleY(1.53846);
  transform: translateY(-50%) var(--notebook-turn);
  filter: drop-shadow(1px 3px 2px #74432448);
  pointer-events: none;
}
.game { grid-area: game; min-width: 0; }
.frame {
  --rail: clamp(24px, 2.35vw, 34px);
  position: relative;
  isolation: isolate;
  padding: var(--rail);
  border-radius: 27px;
  border: 1px solid #fff;
  background:
    linear-gradient(134deg, #ffffffc9, #b0ebda54 22%, #ffffff61 42%, #f5afca50 74%, #fff8);
  backdrop-filter: blur(2px) saturate(1.13);
  box-shadow:
    0 6px 0 #55776c7a,
    0 8px 2px #fff7,
    0 15px 17px -7px #59453b8a,
    0 24px 40px -14px #75524565,
    inset 0 0 0 3px #fff9,
    inset 0 0 0 7px #9fd3c648,
    inset 0 0 20px 8px #fff9;
}
.frame::before {
  content: "";
  position: absolute;
  inset: 9px;
  border: 1px solid #fff;
  border-radius: 19px;
  box-shadow: 0 0 0 1px #92c4b43d, inset 0 0 0 1px #f7c6d166;
  pointer-events: none;
}
.frame-frost {
  position: absolute;
  z-index: 2;
  width: calc(var(--rail) * 1.7);
  height: calc(var(--rail) * 1.7);
  pointer-events: none;
  background:
    radial-gradient(circle, #fff 0 1.2px, transparent 2px) 33% 39% / 12px 12px,
    radial-gradient(circle, #fff 0 1px, transparent 1.7px) 65% 33% / 10px 10px,
    radial-gradient(circle, #fff 0 1px, transparent 1.7px) 34% 63% / 10px 10px;
  background-repeat: no-repeat;
}
.frame-frost::before {
  content: "";
  position: absolute;
  inset: 16% 44% 44% 16%;
  background: #fff;
  clip-path: polygon(50% 0, 59% 41%, 100% 50%, 59% 59%, 50% 100%, 41% 59%, 0 50%, 41% 41%);
}
.top-left, .top-right { top: 2px; }
.bottom-left, .bottom-right { bottom: 2px; }
.top-left, .bottom-left { left: 2px; }
.top-right, .bottom-right { right: 2px; }
.top-right { transform: scaleX(-1); }
.bottom-left { transform: scaleY(-1); }
.bottom-right { transform: rotate(180deg); }
.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1122 / 1402;
  border-radius: 7px;
  background: radial-gradient(ellipse at 34% 23%, #b1d9cf, #88b6ab 90%);
  outline: 1px solid #77a99b;
  box-shadow: 0 0 0 3px #f9fffaac, 0 0 0 4px #89b6a98a, inset 0 2px 9px #4e7c7052;
  touch-action: manipulation;
}
.tile {
  position: absolute;
  top: 0;
  left: 0;
  width: calc(100% / var(--columns));
  height: calc(100% / var(--rows));
  padding: 0;
  border: 0;
  background: none;
  transform: translate(calc(var(--x) * 100%), calc(var(--y) * 100%));
  transition: transform 165ms cubic-bezier(.2,.7,.25,1);
  -webkit-tap-highlight-color: transparent;
}
.tile:focus-visible { z-index: 3; outline-offset: -4px; border-radius: 8px; }
.face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: clamp(4px, 1vw, 10px);
  border: 1px solid #4e2a2266;
  background: var(--card-image) no-repeat;
  background-size: calc(var(--columns) * 100%) calc(var(--rows) * 100%);
  background-position: var(--image-x) var(--image-y);
  background-origin: border-box;
  box-shadow: inset 0 2px 3px #fff7e9b3, inset 0 -3px 3px #3116086b, inset 1px 0 2px #fff7e97d;
}
.tile[data-movable]:hover .face { filter: brightness(1.095); }
.tile[data-movable]:active .face { filter: brightness(.92); }
.final-card {
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
  border-radius: inherit;
  opacity: 0;
  pointer-events: none;
  transition: opacity 280ms ease 150ms;
}
.board[data-won] .final-card { opacity: 1; z-index: 4; }
.board-meta {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 5px 14px;
  margin: 17px 2px 0;
  color: #324a43;
  text-shadow: 0 1px 4px #fff8e5;
  font-size: .71rem;
  font-weight: 700;
  letter-spacing: .065em;
  text-transform: uppercase;
}
.keyboard-tip { text-transform: none; letter-spacing: 0; font-weight: 500; }
.celebration {
  grid-area: celebration;
  margin-top: 15px;
  padding: 15px;
  border: 1px solid #fff;
  border-radius: 17px;
  background: var(--grain), var(--mint-paper);
}
.celebration p { margin: 0 0 10px; color: var(--berry); font: 400 23px Georgia, serif; }
.win-actions { display: flex; flex-wrap: wrap; gap: 7px; }

.game-info {
  display: grid;
  justify-items: center;
  gap: 9px;
  padding: 4px 10px 25px;
  color: #30170e;
  text-align: center;
  text-shadow: 0 1px 4px #ffeed7a6;
}
.game-info p {
  margin: 0;
  font: italic 400 16px/1.24 "Z003", Georgia, serif;
}
.game-info-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 5px 16px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: .75rem;
}
.vk-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 11px;
}
.vk-community {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 8px 14px 8px 10px;
  border: 1px solid #fff7ece0;
  border-radius: 13px;
  background: linear-gradient(155deg, #fff7ed88, #ffe9ec38);
  backdrop-filter: blur(5px);
  box-shadow: inset 0 1px 0 #fff8, 0 0 7px #fff1d36e;
  color: #034f9d;
  font-size: .88rem;
  font-weight: 700;
  text-decoration: none;
}
.vk-community:hover { background: #fff4ef9c; }

@media (min-width: 1001px) {
  :root { --room-height: 100svh; }
  .masthead { padding: clamp(28px, 4svh, 40px) 0 9px; }
  h1 { font-size: clamp(38px, 4.4vw, 63px); }
  #instructions { margin-top: 7px; max-width: none; }
  .layout {
    --game-width: clamp(225px, calc(80svh - 320px), 460px);
    padding-bottom: 5px;
    row-gap: 9px;
  }
  .frame { --rail: 21px; }
  .table-notebook {
    --notebook-width: min(clamp(260px, 35vw, 570px), calc((100vw - var(--game-width)) / 2 + 48px));
    /* Allow for the notebook's rotated bounds at the bottom of the viewport. */
    top: min(calc(var(--room-height) * .5 + var(--room-image-height) * .391), calc(100svh - .265 * var(--notebook-width)));
  }
  .board-meta { margin-top: 12px; }
  .celebration {
    margin-top: 8px;
    padding: 6px;
    text-align: center;
  }
  .celebration p { margin-bottom: 4px; font-size: 16px; }
  .win-actions { justify-content: center; gap: 4px; }
  .win-actions .button { min-height: 34px; padding: 4px 7px; font-size: .72rem; }
  .game-info { gap: 4px; padding: 3px 10px 10px; }
  .vk-links { margin-top: 16px; }
}

@media (min-width: 1001px) and (max-height: 850px) {
  .masthead { padding-top: 26px; }
  h1 { font-size: clamp(38px, 3.5vw, 48px); }
  .layout, .layout:has(.celebration:not([hidden])) {
    --game-width: clamp(245px, calc(80svh - 295px), 460px);
    grid-template-areas: "controls game shelf" "picker game shelf" "celebration game shelf" ". game shelf";
    grid-template-rows: auto auto auto 1fr;
  }
  .frame { --rail: 16px; }
  .board-meta { margin-top: 8px; }
  .game-info { padding-bottom: 6px; }
  .vk-community { min-height: 38px; }
}

@media (max-width: 1000px) {
  :root { --room-height: max(100svh, 860px); }
  .page { width: min(100% - 36px, 550px); }
  .layout, .layout:has(.celebration:not([hidden])) {
    position: relative;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "controls" "game" "celebration" "picker" "shelf";
    grid-template-rows: auto;
    gap: 12px;
  }
  .layout:not(:has(.celebration:not([hidden]))) {
    grid-template-areas: "controls" "game" "picker" "shelf";
  }
  .controls { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 11px; }
  .metrics { gap: 6px; }
  .metrics > div { padding: 6px 8px; }
  .metrics .caption { margin-bottom: 2px; font-size: .62rem; }
  .metrics strong { font-size: 22px; }
  .frame { --rail: clamp(20px, 5.6vw, 30px); border-radius: 23px; }
  .frame::before { inset: 6px; border-radius: 16px; }
  .board-meta { margin-top: 15px; }
  .keyboard-tip { display: none; }
  .levels { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .shelf-cards { --card-width: clamp(57px, 19vw, 76px); }
  .winter-room {
    background-image: url("winter-window-room-mobile.webp");
    background-position: 67% top;
  }
  .table-notebook {
    inset: auto 16px -5px auto;
    grid-area: game;
    width: clamp(72px, 22vw, 95px);
    max-width: none;
    transform: var(--notebook-turn);
  }
}
@media (max-width: 440px) {
  .page { width: calc(100% - 28px); }
  .masthead { padding: 18px 0 16px; }
  h1 { font-size: clamp(25px, 8.6vw, 38px); }
  #instructions { margin-top: 7px; font-size: .83rem; }
  #reset { padding: 7px 9px; font-size: .75rem; }
  .picker { padding-inline: 9px; }
}
@media (prefers-reduced-motion: reduce) {
  .tile, .final-card, .shelf-cards button { transition: none; }
}
