/* ==========================================================================
   Shared look for index.html, create.html and box.html
   ========================================================================== */

/* Fonts are kept in the project (no requests to Google). SIL Open Font License. */
@font-face {
  font-family: "Caveat";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("../assets/fonts/caveat-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Caveat";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("../assets/fonts/caveat-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Nunito";
  font-style: normal;
  font-weight: 600 800;
  font-display: swap;
  src: url("../assets/fonts/nunito-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Nunito";
  font-style: normal;
  font-weight: 600 800;
  font-display: swap;
  src: url("../assets/fonts/nunito-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --cream: #FFF8F0;
  --blue: #A9C1D9;
  --rose: #C94A6B;
  --brown: #6B3A22;
  --ink: #4E2B1A;                  /* handwriting */
  --shadow: 74, 40, 20;            /* warm brown for every shadow */

  --hand: "Caveat", "Bradley Hand", cursive;
  --ui: "Nunito", -apple-system, system-ui, sans-serif;

  --vh: 1vh;
  /* Keep clear of the notch / Dynamic Island and the home bar. */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  /* Pages are drawn on a 390 × 690 phone canvas. --px is one canvas pixel,
     scaled so the whole canvas fits inside the safe part of the screen. */
  --px: min(
    (100vw - var(--safe-l) - var(--safe-r)) / 390,
    (100 * var(--vh) - var(--safe-t) - var(--safe-b)) / 690,
    1.5px
  );

  --rest-shadow:
    drop-shadow(0 calc(1 * var(--px)) calc(1.5 * var(--px)) rgba(var(--shadow), .24))
    drop-shadow(calc(2 * var(--px)) calc(5 * var(--px)) calc(7 * var(--px)) rgba(var(--shadow), .15));
  --held-shadow:
    drop-shadow(0 calc(2 * var(--px)) calc(4 * var(--px)) rgba(var(--shadow), .16))
    drop-shadow(calc(6 * var(--px)) calc(16 * var(--px)) calc(20 * var(--px)) rgba(var(--shadow), .18));
}

@supports (height: 1svh) {
  :root { --vh: 1svh; }
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

html {
  background: var(--cream);
  color: var(--brown);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;   /* no grey flash on iPhone taps */
  touch-action: manipulation;
}

body {
  font-family: var(--ui);
  -webkit-font-smoothing: antialiased;
  background: var(--cream) url("../assets/web/bg-table.webp") center / cover no-repeat;
  user-select: none;
  -webkit-user-select: none;
}

[hidden] { display: none !important; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus { outline: none; }
:focus-visible {
  outline: 2px dashed rgba(107, 58, 34, .5);
  outline-offset: 4px;
  border-radius: 8px;
}

img {
  display: block;
  max-width: 100%;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
}

/* ---------- the phone canvas ---------- */

/* Full screen, centred, kept inside the safe area (notch, home bar). */
.scene {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
}

.stage {
  position: relative;
  width: calc(390 * var(--px));
  height: calc(690 * var(--px));
}

.layer {
  position: absolute;
  inset: 0;
}

/* Place anything on the canvas: --x / --y / --w in canvas px, --r in degrees. */
.u {
  position: absolute;
  left: calc(var(--x) * var(--px));
  top: calc(var(--y) * var(--px));
  width: calc(var(--w) * var(--px));
  rotate: calc(var(--r, 0) * 1deg);
}

.u.c  { translate: -50% -50%; }        /* --x / --y is the centre */
.u.hh { height: calc(var(--h) * var(--px)); }

/* ---------- buttons drawn as paper ---------- */

.btn {
  display: block;
  container-type: inline-size;
  filter: drop-shadow(0 calc(2 * var(--px)) calc(3 * var(--px)) rgba(var(--shadow), .18));
  transition: scale .15s ease;
}

.btn:not(.u) { position: relative; }

.btn:active { scale: .96; }

.btn > img { width: 100%; }

.btn > span {
  position: absolute;
  inset: 0 6% 8%;
  display: grid;
  place-items: center;
  font: 700 15cqw/1 var(--hand);
  color: var(--cream);
  white-space: nowrap;
}

.btn.secondary > span { color: var(--brown); }

/* ---------- the box ---------- */

.box-img {
  filter:
    drop-shadow(0 calc(2 * var(--px)) calc(2 * var(--px)) rgba(var(--shadow), .2))
    drop-shadow(calc(4 * var(--px)) calc(10 * var(--px)) calc(16 * var(--px)) rgba(var(--shadow), .16));
}

/* The floor of the open box, where things lie (positions are fractions of it). */
.pile { height: calc(var(--h) * var(--px)); }

.in-pile {
  left: calc(var(--fx) * 100%);
  top: calc(var(--fy) * 100%);
  translate: -50% -50%;
  z-index: var(--z);
}

/* An item placed on the canvas by its centre */
.at {
  left: calc(var(--x) * var(--px));
  top: calc(var(--y) * var(--px));
  translate: -50% -50%;
}

/* ---------- the sealed box: tape, stickers, shipping label (js/label.js) ---------- */

.tape {
  object-fit: fill;
  filter: drop-shadow(0 1px 1px rgba(var(--shadow), .14));
}

.decal { filter: drop-shadow(0 1px 1.5px rgba(var(--shadow), .2)); }

.postmark {
  mix-blend-mode: multiply;
  opacity: .82;
  filter: none;
}

.ship-label {
  container-type: inline-size;
  filter: drop-shadow(0 1px 1.5px rgba(var(--shadow), .2));
}

.ship-label > img { width: 100%; }

.ship-text {
  position: absolute;
  left: 8%;
  right: 15%;
  top: 15%;
  bottom: 14%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1.8cqw;
}

.ship-row {
  display: flex;
  align-items: baseline;
  gap: 2cqw;
  border-bottom: 1px solid rgba(107, 58, 34, .22);
  padding-bottom: .4cqw;
}

.ship-key {
  flex: none;
  width: 18cqw;
  font: 800 5cqw/1 var(--ui);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: #56769A;
}

/* Font sizes of names and city are fitted in js (applyFit). */
.ship-name {
  flex: 1;
  min-width: 0;
  font-family: var(--hand);
  font-weight: 700;
  line-height: 1.02;
  color: var(--ink);
  white-space: nowrap;
}

.ship-city {
  padding-left: 20cqw;
  font-family: var(--hand);
  font-weight: 600;
  line-height: 1;
  color: var(--brown);
  white-space: nowrap;
}

/* ---------- items (see makeThing in js/items.js) ---------- */

.thing {
  position: absolute;
  width: calc(var(--w) * var(--px));
  container-type: inline-size;
  filter: var(--rest-shadow);
}

.thing-rot {
  position: relative;
  transform: rotate(calc(var(--r, 0) * 1deg));
}

.thing-img { width: 100%; }

.deco { position: absolute; pointer-events: none; }

.deco-photo { object-fit: cover; }

/* Writing on items. Font sizes are set by applyFit() in js/items.js (in cqw,
   so they scale with the item). Overflow stays visible so writing is never clipped. */
.deco-text {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-family: var(--hand);
  font-weight: 600;
  color: var(--ink);
  line-height: 1.05;
  white-space: pre-line;
  overflow: visible;
}

.note-words {
  font-size: 12.5cqw;
  line-height: .9;
  rotate: -5deg;
}

.cassette-title,
.cassette-artist {
  color: #26364c;
  white-space: nowrap;
}

.cassette-title  { align-items: flex-end; font-weight: 700; }
.cassette-artist { align-items: flex-start; }

.item-words { font-weight: 700; }

.card-caption { white-space: nowrap; }

/* Words stamped on the brass token */
.token-arc {
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.token-arc text {
  font-family: var(--hand);
  font-weight: 700;
  font-size: 9.6px;
}

/* Kraft gift tag tied on to an item. Its width is set per item in makeThing(). */
.gift-tag {
  position: absolute;
  left: 66%;
  top: -10%;
  width: calc(72 * var(--px));
  container-type: inline-size;
  transform-origin: 3% 50%;
  rotate: -16deg;
  filter: drop-shadow(0 1px 1.5px rgba(var(--shadow), .28));
}

.gift-tag > img { width: 100%; }

.gift-tag-text {
  font-weight: 700;
  color: #3A2214;
  white-space: nowrap;
}

/* ---------- toast (with an optional undo) ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(22px, calc(env(safe-area-inset-bottom) + 12px));
  z-index: 70;
  translate: -50% 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  width: max-content;
  max-width: 92vw;
  min-height: 44px;
  padding: 0 6px 0 18px;
  border-radius: 99px;
  font: 600 19px/1.2 var(--hand);
  color: var(--cream);
  background: rgba(78, 43, 26, .94);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, translate .25s cubic-bezier(.2, .8, .2, 1);
}

.toast.is-shown { opacity: 1; translate: -50% 0; pointer-events: auto; }

.toast > span { padding: 10px 12px 10px 0; }

.toast-undo {
  min-width: 64px;
  min-height: 44px;
  font: 700 19px/1 var(--hand);
  color: #F3C9D4;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---------- small helpers ---------- */

.hint {
  font: 700 12.5px/1.3 var(--ui);
  letter-spacing: .14em;
  text-align: center;
  color: rgba(107, 58, 34, .78);
  opacity: 0;
  transition: opacity .3s ease;
  pointer-events: none;
}

.hint.is-shown { opacity: 1; }

.hint.hand {
  font: 600 calc(30 * var(--px))/1 var(--hand);
  letter-spacing: 0;
  word-spacing: .1em;
  color: var(--rose);
}
