@import url("https://fonts.googleapis.com/css2?family=Caveat:wght@500;700&family=Geist:wght@400;500;600&family=Geist+Mono:wght@500;700&display=swap");

/* Unboxing: one canvas (#c) draws the table, the boxes and the packing. The counter, the paper note and the hint are
   plain DOM on top so they stay crisp and readable. */
:root {
  --font: "Geist", system-ui, -apple-system, sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --ink: #f4e9d8;
  --panel: rgba(34, 22, 12, 0.7);
  --line: rgba(255, 226, 180, 0.2);
}

*,*::before,*::after { box-sizing: border-box; }
html, body {
  -webkit-tap-highlight-color: transparent; height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body { font-family: var(--font); color: var(--ink); touch-action: none; background: #1a110a; }
.inset { position: fixed; left: 0; top: 0; width: 0; height: 0; visibility: hidden; pointer-events: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

canvas#c {
  display: block; position: fixed; inset: 0; width: 100%; height: 100%; z-index: 1; touch-action: none; cursor: grab;
  -webkit-touch-callout: none; -webkit-user-select: none; user-select: none;
}
canvas#c.is-grab { cursor: grabbing; }

/* the counter */
.count {
  position: fixed; z-index: 8; left: 50%; transform: translateX(-50%); pointer-events: none; text-align: center;
  top: calc(max(12px, env(safe-area-inset-top)) + 36px); display: flex; flex-direction: column; align-items: center; gap: 2px;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.7);
}
.count__n { font-family: var(--mono); font-weight: 700; font-size: clamp(2rem, 9vw, 2.9rem); line-height: 1; letter-spacing: -0.02em; color: #fff3de; display: inline-block; transition: transform 0.22s cubic-bezier(0.3, 1.6, 0.5, 1); }
.count__n.is-bump { transform: scale(1.18); transition-duration: 0.07s; }
.count__l { font-size: 0.6rem; font-weight: 600; letter-spacing: 0.22em; text-transform: uppercase; color: rgba(255, 236, 206, 0.62); }

/* the paper note found inside a box */
.note {
  position: fixed; z-index: 9; pointer-events: none; left: 50%; bottom: calc(max(14px, env(safe-area-inset-bottom)) + 52px);
  width: min(84vw, 380px); transform: translate(-50%, 24px) rotate(-1.4deg); opacity: 0;
  padding: 16px 20px 15px; border-radius: 3px; color: #2c2113; text-align: center;
  background:
    repeating-linear-gradient(180deg, transparent 0 25px, rgba(86, 120, 170, 0.16) 25px 26px),
    linear-gradient(170deg, #fbf4e2, #efe3c6);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 12px 28px rgba(0, 0, 0, 0.5), 0 2px 5px rgba(0, 0, 0, 0.35);
  transition: opacity 0.3s ease, transform 0.5s cubic-bezier(0.2, 1.3, 0.4, 1);
}
.note.is-on { opacity: 1; transform: translate(-50%, 0) rotate(-1.4deg); }
.note p { margin: 0; font-family: "Caveat", "Bradley Hand", "Segoe Print", cursive; font-weight: 700; font-size: clamp(1.3rem, 5.6vw, 1.62rem); line-height: 1.22; }
.note__tape { position: absolute; left: 50%; top: -9px; width: 78px; height: 20px; transform: translateX(-50%) rotate(2deg); background: rgba(218, 196, 140, 0.72); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); }

.bar { position: fixed; z-index: 6; left: 50%; bottom: calc(max(14px, env(safe-area-inset-bottom)) + 4px); transform: translateX(-50%); display: flex; }
.bar .opt-share.opt-share {
  appearance: none; cursor: pointer; font-family: var(--font);
  display: inline-flex; align-items: center; gap: 7px; height: 34px; margin: 0; padding: 0 14px;
  border-radius: 999px; font-size: 0.76rem; font-weight: 600; opacity: 1;
  color: var(--ink); background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  touch-action: manipulation;
}
.share-host { display: inline-flex; }
.share-host:empty { display: none; }
.bar .opt-share.opt-share:focus-visible, .sound-btn:focus-visible { outline: 2px dashed rgba(255, 220, 160, 0.9); outline-offset: 2px; }

.sound-btn {
  appearance: none; position: fixed; z-index: 12; cursor: pointer; padding: 0;
  top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right));
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  color: var(--ink); background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  transition: transform 0.12s ease, opacity 0.15s ease;
}
.sound-btn:active { transform: scale(0.94); }
.sound-btn[aria-pressed="false"] { opacity: 0.55; }
.sound-btn[aria-pressed="false"] .sound-btn__wave { opacity: 0; }

.frame { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.frame__corner {
  position: absolute; font-size: clamp(0.58rem, 1.2vw, 0.7rem); font-weight: 600;
  letter-spacing: 0.22em; text-transform: uppercase; color: rgba(255, 236, 206, 0.6);
  white-space: nowrap; font-family: var(--font); text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
}
.frame__corner--tl { top: calc(max(12px, env(safe-area-inset-top)) + 13px); left: max(18px, env(safe-area-inset-left)); }
.frame__corner--tr { top: calc(max(12px, env(safe-area-inset-top)) + 13px); right: calc(max(12px, env(safe-area-inset-right)) + 54px); }
.frame__corner--bl { bottom: max(18px, env(safe-area-inset-bottom)); left: max(18px, env(safe-area-inset-left)); }
.frame__corner a { color: inherit; text-decoration: none; pointer-events: auto; border-bottom: 1px solid transparent; transition: color .14s, border-color .14s; }
.frame__corner a:hover { color: #fff; border-bottom-color: rgba(255, 236, 206, 0.5); }

.hint {
  position: fixed; top: calc(max(12px, env(safe-area-inset-top)) + 104px); left: 50%; transform: translateX(-50%);
  width: min(88vw, 560px); margin: 0; text-align: center; z-index: 9; pointer-events: none;
  font-size: 0.64rem; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; line-height: 1.6;
  color: rgba(255, 236, 206, 0.7); text-shadow: 0 1px 8px rgba(0, 0, 0, 0.95); transition: opacity 0.6s;
}
.hint.is-hidden { opacity: 0; }

.opt-tipjar.opt-tipjar { top: auto; bottom: max(14px, env(safe-area-inset-bottom)); transform: none; }
.opt-fs.opt-fs { top: auto; bottom: max(14px, env(safe-area-inset-bottom)); right: calc(max(14px, env(safe-area-inset-right)) + 54px); transform: none; }
.opt-tipjar.opt-tipjar.tj-nudge { animation: none; }

/* wide screens: the counter moves to the left of the box, the note to its right, the hint to the bottom */
@media (orientation: landscape) {
  .count { left: max(22px, calc(env(safe-area-inset-left) + 8px)); top: 50%; transform: translateY(-50%); align-items: flex-start; }
  .note { left: auto; right: max(22px, calc(env(safe-area-inset-right) + 8px)); bottom: auto; top: 50%; width: min(24vw, 300px); transform: translate(0, calc(-50% + 24px)) rotate(1.6deg); }
  .note.is-on { transform: translate(0, -50%) rotate(1.6deg); }
  .hint { top: calc(max(12px, env(safe-area-inset-top)) + 14px); bottom: auto; width: min(40vw, 520px); }
  .bar { left: auto; right: max(22px, calc(env(safe-area-inset-right) + 8px)); transform: none; bottom: calc(max(14px, env(safe-area-inset-bottom)) + 62px); }
}
@media (orientation: landscape) and (max-height: 500px) {
  .count__n { font-size: 2rem; }
  .note { padding: 11px 14px 10px; width: min(26vw, 230px); }
  .note p { font-size: 1.12rem; }
}
@media (max-width: 380px) { .hint { letter-spacing: 0.08em; font-size: 0.6rem; } }
@media (prefers-reduced-motion: reduce) { .note, .count__n, .hint, .sound-btn { transition: none; } }
