:root {
  --k: 0.4;              /* масштаб листівки: одиниці макета → пікселі екрана */
  --ink: #141414;
  --orange: #ff4b1b;
  --teal: #8ee3d6;
  --paper: #dedad1;
  --bg: #1c1c1c;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  display: grid;
  grid-template-columns: clamp(250px, 26vw, 360px) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: #eee;
  font-family: Montserrat, system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

body.is-holding, body.is-holding * { cursor: grabbing !important; }

/* ───────── аркуш з наліпками ───────── */

.tray {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  padding: 24px 20px;
  overflow-y: auto;
  border-right: 1px solid #2c2c2c;
}

.tray__title {
  margin: 0;
  font: 600 12px/1 Montserrat, sans-serif;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #8a8a8a;
}

.tabs {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  gap: 6px;
}

.tab {
  flex: none;
  padding: 7px 11px;
  border: 1px solid #3a3a3a;
  border-radius: 999px;
  background: transparent;
  color: #bdbdbd;
  font: 600 12px/1 Montserrat, sans-serif;
  cursor: pointer;
}

.tab:hover { border-color: #666; color: #fff; }
.tab.is-on { border-color: var(--teal); background: var(--teal); color: var(--ink); }

.sheet {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 20px 16px;
  padding: 26px 18px;
  border-radius: 14px;
  background: var(--paper);
}

.cell {
  position: relative;
  flex: none;
  width: calc(var(--w) * var(--k) * 1px);
  height: calc(var(--h) * var(--k) * 1px);
  rotate: var(--a);
}

.cell .st {
  transform: scale(var(--k));
  transform-origin: 0 0;
}

/* слід на підкладці, з якої вже зняли наліпку */
.st--ghost {
  pointer-events: none;
  filter: brightness(0) opacity(0.1);
  --sh: 0 0 0 transparent;
}

.cell.is-empty .st--tray { visibility: hidden; }

.cell.is-growing .st--tray .st__tilt {
  animation: grow 0.45s cubic-bezier(0.3, 1.6, 0.5, 1);
}

@keyframes grow {
  from { transform: scale(0) rotate(-35deg); }
  to   { transform: none; }
}

@media (hover: hover) {
  .cell:not(.is-pressed) .st--tray .st__tilt {
    transition: transform 0.2s cubic-bezier(0.3, 1.6, 0.5, 1);
  }
  .cell:not(.is-pressed):hover .st--tray .st__tilt {
    transform: perspective(700px) rotate3d(1, -1, 0, 14deg) scale(1.05);
  }
}

/* ───────── сцена ───────── */

.stage {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  touch-action: none;
}

.stage__area {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 24px 24px 8px;
}

.card-wrap {
  width: calc(1080px * var(--k));
  height: calc(1920px * var(--k));
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}

.card {
  position: relative;
  width: 1080px;
  height: 1920px;
  transform: scale(var(--k));
  transform-origin: 0 0;
}

.card__surface {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--orange);
  color: var(--ink);
}

.card__stickers {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

/* ───────── вміст листівки (V5.3, одиниці макета) ───────── */

.c-logo {
  position: absolute;
  left: 62px;
  top: 40px;
  font: 800 36px/1 Montserrat, sans-serif;
  letter-spacing: 0.06em;
}

.c-tab {
  position: absolute;
  right: 0;
  top: 0;
  width: 660px;
  height: 112px;
  padding: 26px 62px 0 0;
  background: var(--ink);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50px 100%);
  color: #fff;
  font: 500 22px/28px Montserrat, sans-serif;
  text-align: right;
}

.c-tab b {
  display: block;
  font-weight: 600;
  letter-spacing: 1.32px;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.c-mascot {
  position: absolute;
  left: 58px;
  top: 190px;
  width: 200px;
  height: 145px;
  pointer-events: none;
}

.c-title {
  position: absolute;
  left: 62px;
  top: 182px;
  margin: 0;
  font: 800 88px/91px Montserrat, sans-serif;
  letter-spacing: -0.01em;
  text-transform: uppercase;
}

.c-title span { display: block; white-space: nowrap; }
.c-title .in { padding-left: 205px; }

.c-chip {
  display: inline-block;
  margin-left: 16px;
  padding: 12px 20px;
  border: 4px solid #fff;
  border-radius: 14px;
  background: var(--ink);
  color: #fff;
  font: 700 34px/1 Montserrat, sans-serif;
  letter-spacing: 0.02em;
  vertical-align: middle;
  rotate: -5deg;
  translate: 0 -8px;
}

.c-folder {
  position: absolute;
  left: 62px;
  top: 690px;
  width: 956px;
  height: 600px;
}

.c-folder svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.c-folder__line { fill: none; stroke: var(--ink); stroke-width: 3; }

.c-folder__label {
  position: absolute;
  left: 30px;
  top: 15px;
  font: 700 30px/1 Montserrat, sans-serif;
  rotate: -0.9deg;
}

.zone {
  fill: none;
  stroke: rgba(20, 20, 20, 0.55);
  stroke-width: 2.5;
  stroke-dasharray: 11 9;
}

.zone-n {
  fill: rgba(20, 20, 20, 0.6);
  font: 700 38px Caveat, cursive;
  text-anchor: middle;
}

.zone-n--note { font-size: 36px; }

.zone-arrow {
  fill: none;
  stroke: rgba(20, 20, 20, 0.6);
  stroke-width: 2.5;
  stroke-linecap: round;
}

/* поки наліпка висить над листівкою — пунктир «біжить» */
.card.is-armed .zone {
  stroke: var(--ink);
  animation: march 0.5s linear infinite;
}

@keyframes march { to { stroke-dashoffset: -20; } }

.c-note {
  --r: 10px;
  position: absolute;
  left: 62px;
  top: 1338px;
  width: 956px;
  height: 510px;
  padding: 46px 58px;
  background: #fff;
  -webkit-mask:
    linear-gradient(#000 0 0) center / calc(100% - 2 * var(--r)) calc(100% - 2 * var(--r)) no-repeat,
    radial-gradient(circle var(--r), #000 96%, #0000) 0 0 / calc(2.5 * var(--r)) calc(2.5 * var(--r)) round;
  mask:
    linear-gradient(#000 0 0) center / calc(100% - 2 * var(--r)) calc(100% - 2 * var(--r)) no-repeat,
    radial-gradient(circle var(--r), #000 96%, #0000) 0 0 / calc(2.5 * var(--r)) calc(2.5 * var(--r)) round;
}

.c-note__lead {
  margin: 0 0 22px;
  color: rgba(20, 20, 20, 0.72);
  font: 500 34px/1.2 Montserrat, sans-serif;
}

.c-note__text {
  width: 840px;
  margin: 0;
  font: italic 500 40px/52px Montserrat, sans-serif;
}

.c-note__from {
  position: absolute;
  right: 70px;
  bottom: 44px;
  display: flex;
  align-items: flex-end;
  gap: 14px;
  color: rgba(20, 20, 20, 0.72);
  font: 500 30px/1 Montserrat, sans-serif;
}

.c-note__line {
  display: block;
  min-width: 330px;
  padding: 0 0 2px 18px;
  border-bottom: 2px solid rgba(20, 20, 20, 0.45);
}

.c-note__sign {
  display: inline-block;
  color: var(--ink);
  font: 700 70px/0.9 Caveat, cursive;
  rotate: -4deg;
}

/* ───────── наліпка ───────── */

.st {
  position: absolute;
  left: 0;
  top: 0;
  cursor: grab;
  touch-action: none;
  will-change: transform;
}

.st__tilt {
  width: 100%;
  height: 100%;
  filter: drop-shadow(var(--sh, 0 3px 3px rgba(0, 0, 0, 0.38)));
}

/* наліпка «напіввідклеєна», поки її крутять за кутик */
.st.is-loose .st__tilt {
  transform: scale(1.06);
  transition: transform 0.15s ease-out;
}

.st__body {
  position: relative;
  width: 100%;
  height: 100%;
}

.st__body img {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  -webkit-user-drag: none;
}

.st__body--tag {
  display: grid;
  place-items: center;
  padding: 16px 30px 18px;
  overflow: hidden;
  border: 5px solid #fff;
  font: 700 40px/1 Montserrat, sans-serif;
  white-space: nowrap;
}

.tag--orange    { border-radius: 999px; background: var(--orange); color: #fff; }
.tag--teal      { border-radius: 16px;  background: var(--teal);   color: var(--ink); }
.tag--teal-pill { border-radius: 999px; background: var(--teal);   color: var(--ink); }
.tag--ink       { border-radius: 12px;  background: var(--ink);    color: #fff; }
.tag--paper     { border-radius: 999px; background: #fff; color: var(--ink); box-shadow: inset 0 0 0 3px var(--ink); }

/* відблиск, що пробігає після приклеювання */
.st__gloss {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  background: linear-gradient(115deg, #fff0 35%, #fffc 50%, #fff0 65%) no-repeat;
  background-size: 250% 100%;
  background-position: 120% 0;
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
}

/* слід клею на місці, звідки наліпку відірвали */
.st--residue {
  pointer-events: none;
  filter: brightness(0) invert(1);
  --sh: 0 0 0 transparent;
}

.tag--gold   { border-radius: 999px; background: #ffd23f; color: var(--ink); box-shadow: inset 0 0 0 3px var(--ink); }
.tag--secret { border-radius: 16px;  background: #fff; color: var(--orange); box-shadow: inset 0 0 0 3px var(--orange); }

/* характер: серце б'ється, поки його тримають */
.st.is-held.t-pulse .st__body { animation: pulse 0.55s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { scale: 1; }
  30%      { scale: 1.14; }
  55%      { scale: 0.97; }
}

/* утікаюча наліпка на аркуші */
.cell { transition: translate 0.2s cubic-bezier(0.3, 1.5, 0.5, 1); }
.cell.is-shy-moved { z-index: 2; }

/* маскот: тягнеться до наліпки в руці, а заклеєний — сіріє й хилиться */
.c-mascot {
  transform-origin: 50% 90%;
  transition: transform 0.15s, filter 0.3s, rotate 0.3s, translate 0.3s;
}

.c-mascot.is-sad {
  filter: grayscale(0.75) brightness(0.85);
  rotate: -10deg;
  translate: 0 8px;
}

.confetti {
  position: absolute;
  left: 0;
  top: 0;
  width: 9px;
  height: 6px;
  border-radius: 1px;
}

.measure {
  position: absolute;
  left: -9999px;
  top: 0;
  visibility: hidden;
}

.measure .st__body {
  position: absolute;
  width: max-content;
  height: auto;
}

/* ───────── шар «у руці» та виділення ───────── */

.float {
  position: fixed;
  inset: 0;
  z-index: 50;
  overflow: hidden;
  pointer-events: none;
}

.float .st { pointer-events: none; }

.sel {
  position: absolute;
  left: 0;
  top: 0;
  border: 1.5px dashed #fff;
  border-radius: 6px;
  filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.9));
  pointer-events: none;
}

.sel[hidden] { display: none; }

.sel.is-snapped { border-style: solid; border-color: var(--teal); }

.sel__h {
  position: absolute;
  width: 18px;
  height: 18px;
  margin: -9px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: #fff;
  pointer-events: auto;
  touch-action: none;
  cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke-linecap='round' stroke-linejoin='round'><g stroke='white' stroke-width='5'><path d='M19 12a7 7 0 1 1-2.5-5.4'/><path d='M17.5 2.5v5h-5'/></g><g stroke='%23141414' stroke-width='2.2'><path d='M19 12a7 7 0 1 1-2.5-5.4'/><path d='M17.5 2.5v5h-5'/></g></svg>") 12 12, grab;
  transition: scale 0.15s, background 0.15s;
  animation: handle-in 0.35s both;
}

/* зона попадання більша за саму ручку */
.sel__h::after { content: ""; position: absolute; inset: -12px; }

.sel__h:hover,
.sel.is-turning .sel__h { scale: 1.35; background: var(--teal); }

.sel__h[data-c="nw"] { left: 0;    top: 0; }
.sel__h[data-c="ne"] { left: 100%; top: 0; }
.sel__h[data-c="se"] { left: 100%; top: 100%; }
.sel__h[data-c="sw"] { left: 0;    top: 100%; }

@keyframes handle-in {
  0%   { scale: 0; }
  60%  { scale: 1.6; }
  100% { scale: 1; }
}

.sel__badge {
  position: absolute;
  left: 50%;
  top: -42px;
  padding: 6px 9px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font: 700 12px/1 Montserrat, sans-serif;
  white-space: nowrap;
  opacity: 0;
  translate: -50% 0;
  transition: opacity 0.15s;
}

.sel.is-turning .sel__badge { opacity: 1; }

/* ───────── панель знизу, підказка, тост ───────── */

.bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 10px 24px 18px;
}

.btn {
  flex: none;
  padding: 13px 22px;
  border: 0;
  border-radius: 999px;
  background: var(--teal);
  color: var(--ink);
  font: 700 14px/1 Montserrat, sans-serif;
  cursor: pointer;
  transition: scale 0.12s;
}

.btn--main { background: var(--orange); color: #fff; }
.btn:disabled { opacity: 0.5; pointer-events: none; }

/* ───────── фінал: листівка їде в конверт ───────── */

.post {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  overflow: hidden;
  perspective: 900px;
}

.env {
  position: relative;
  width: 340px;
  height: 220px;
}

.env__back,
.env__front {
  position: absolute;
  inset: 0;
  border-radius: 10px;
}

.env__back { background: #cfc8b8; }

.env__front {
  z-index: 3;
  background: #f3efe6;
  clip-path: polygon(0 0, 50% 48%, 100% 0, 100% 100%, 0 100%);
}

.env__card {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;
  width: 150px;
  height: 267px;
  margin: -133px 0 0 -75px;
}

.env__flap {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 1;
  width: 100%;
  height: 56%;
  background: #e4ddcd;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform: rotateX(180deg);
  transform-origin: 50% 0;
}

.env__stamp {
  position: absolute;
  right: 22px;
  bottom: 22px;
  z-index: 5;
  padding: 8px 10px;
  border: 3px solid var(--orange);
  border-radius: 6px;
  color: var(--orange);
  font: 800 15px/1 Montserrat, sans-serif;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0;
  rotate: -10deg;
}

.btn:hover { scale: 1.04; }
.btn:active { scale: 0.94; }

.hint {
  margin: 0;
  min-height: 1.3em;
  color: #8f8f8f;
  font: 500 13px/1.3 Montserrat, sans-serif;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  z-index: 60;
  padding: 12px 18px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  color: var(--ink);
  font: 600 14px/1.2 Montserrat, sans-serif;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  translate: -50% 20px;
  transition: opacity 0.2s, translate 0.25s cubic-bezier(0.3, 1.5, 0.5, 1);
}

.toast.is-on { opacity: 1; translate: -50% 0; }

/* ───────── вузькі екрани: аркуш їде вниз стрічкою ───────── */

@media (max-width: 760px) {
  body {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .tray {
    order: 2;
    gap: 8px;
    padding: 10px 12px;
    overflow: hidden;
    border-top: 1px solid #2c2c2c;
    border-right: 0;
  }

  .tray__title { display: none; }

  .tabs {
    flex-wrap: nowrap;
    overflow: auto hidden;
    scrollbar-width: none;
  }

  .sheet {
    flex-wrap: nowrap;
    justify-content: flex-start;
    padding: 14px 18px;
    overflow: auto hidden;
  }

  /* горизонтальний свайп гортає стрічку, рух угору — відклеює */
  .tray .st { touch-action: pan-x; }

  .stage__area { padding: 12px 12px 4px; }
  .bar { padding: 8px 12px 10px; }
  .hint { font-size: 11px; }
  .toast { bottom: 160px; }
}
