  :root {
    --white: #ffffff;
    --paper: #f6f5f3;
    --ink: #19110b;
    --ink-soft: #6f6862;
    --line: rgba(25, 17, 11, 0.14);
    --gold: #c9a35a;
    --gold-soft: #e9d6a6;
    --night: #0b0806;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
    --sans: Jost, "Futura", "Century Gothic", system-ui, sans-serif;
    --serif: "Cormorant Garamond", Georgia, serif;
  }
  * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
  html, body { margin: 0; height: 100%; overflow: hidden; }
  body {
    font-family: var(--sans); font-weight: 400; color: var(--ink); background: var(--night);
    display: flex; flex-direction: column; user-select: none; -webkit-user-select: none;
  }

  /* header floats over the scene */
  header {
    position: absolute; top: 0; left: 0; right: 0; z-index: 6;
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
    padding: calc(14px + env(safe-area-inset-top)) 18px 10px; gap: 8px;
    background: linear-gradient(180deg, rgba(0,0,0,0.45), rgba(0,0,0,0));
  }
  .hl { display: flex; gap: 6px; }
  .hr { display: flex; gap: 8px; justify-content: flex-end; }
  .brand { text-align: center; color: #fff; line-height: 1.1; }
  .brand .wm { font-size: 15px; letter-spacing: 0.42em; font-weight: 400; padding-left: 0.42em; white-space: nowrap; }
  .brand .sub { font-family: var(--serif); font-style: italic; font-size: 14px; color: var(--gold-soft); letter-spacing: 0.02em; margin-top: 2px; }

  button {
    font: inherit; cursor: pointer; border-radius: 999px; border: 1px solid transparent;
    padding: 10px 18px; font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; font-weight: 500;
    background: var(--white); color: var(--ink); transition: background 0.2s, color 0.2s, transform 0.1s;
  }
  button:active { transform: scale(0.97); }
  button.primary { background: var(--ink); color: #fff; }
  header button { background: rgba(255,255,255,0.08); color: #fff; border-color: rgba(255,255,255,0.45); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
  header button:hover { background: rgba(255,255,255,0.18); }
  header button.primary { background: #fff; color: var(--ink); border-color: #fff; }
  button.icon { width: 38px; height: 38px; padding: 0; display: grid; place-items: center; font-size: 15px; letter-spacing: 0; }

  #stage { position: relative; flex: 1; min-height: 0; }
  #stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }

  #hint {
    position: absolute; left: 50%; top: calc(84px + env(safe-area-inset-top)); transform: translateX(-50%);
    color: rgba(255,255,255,0.85); font-size: 10px; letter-spacing: 0.22em; text-transform: uppercase;
    transition: opacity 0.6s; pointer-events: none; white-space: nowrap; text-shadow: 0 1px 8px rgba(0,0,0,0.6);
  }

  #toolbar {
    position: absolute; display: none; gap: 0; padding: 4px;
    background: var(--white); border-radius: 999px; box-shadow: var(--shadow);
    transform: translate(-50%, -100%); z-index: 4;
  }
  #toolbar button { padding: 8px 12px; font-size: 10px; background: transparent; }
  #toolbar button:hover { background: var(--paper); }

  /* tray */
  #tray { background: var(--white); padding: 14px 0 calc(12px + env(safe-area-inset-bottom)); z-index: 5; }
  .tabs { display: flex; gap: 22px; padding: 0 20px 12px; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar, .items::-webkit-scrollbar { display: none; }
  .tab {
    padding: 4px 0; font-size: 10px; border-radius: 0; background: transparent; color: var(--ink-soft);
    border-bottom: 1px solid transparent; white-space: nowrap;
  }
  .tab.on { color: var(--ink); border-bottom-color: var(--ink); }
  .items { display: flex; gap: 10px; padding: 2px 20px 4px; overflow-x: auto; scrollbar-width: none; }
  .item {
    flex: 0 0 auto; width: 84px; display: flex; flex-direction: column; align-items: center;
    gap: 6px; padding: 8px 4px 8px; background: var(--paper); touch-action: pan-x; cursor: grab;
    transition: background 0.2s;
  }
  .item:hover { background: #efede9; }
  .item img { width: 66px; height: 66px; pointer-events: none; -webkit-user-drag: none; }
  .item span { font-size: 9px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink); text-align: center; }
  .item .new { position: absolute; }

  /* sheets */
  .sheet-wrap {
    position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: none;
    align-items: flex-end; justify-content: center; z-index: 20;
  }
  .sheet-wrap.open { display: flex; animation: fade 0.25s ease; }
  @keyframes fade { from { opacity: 0; } }
  .sheet {
    width: 100%; max-width: 520px; background: var(--white);
    padding: 26px 22px calc(22px + env(safe-area-inset-bottom)); max-height: 88vh; overflow-y: auto;
    animation: rise 0.35s cubic-bezier(.2,.8,.2,1);
  }
  @keyframes rise { from { transform: translateY(30px); opacity: 0; } }
  .sheet h2 { font-family: var(--serif); font-style: italic; font-weight: 500; margin: 0 0 4px; font-size: 30px; }
  .sheet .kicker { font-size: 10px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 14px; }
  .row { margin: 16px 0; }
  .row label { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.2em; color: var(--ink-soft); margin-bottom: 8px; }
  .seg { display: flex; gap: 6px; flex-wrap: wrap; }
  .seg button { background: var(--white); border-color: var(--line); padding: 9px 14px; font-size: 10px; }
  .seg button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
  input[type=text] {
    width: 100%; font-family: var(--serif); font-style: italic; font-size: 20px; padding: 10px 2px; border: 0;
    border-bottom: 1px solid var(--ink); background: transparent; color: var(--ink); border-radius: 0; outline: none;
  }
  .sheet .actions { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
  .sheet .actions button { flex: 1; min-width: 120px; border-color: var(--line); }
  .sheet .actions button.primary { border-color: var(--ink); }
  .linkbox { font-size: 11px; color: var(--ink-soft); word-break: break-all; background: var(--paper); padding: 10px; max-height: 64px; overflow: auto; }
  #shareImg { width: 100%; margin-bottom: 12px; display: block; background: var(--paper); }

  /* receiver view */
  #viewBar {
    display: none; justify-content: center; gap: 8px; flex-wrap: wrap; background: var(--white);
    padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); z-index: 5;
  }
  #viewMsg {
    position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%);
    font-family: var(--serif); font-style: italic; font-size: 26px; color: #fff; display: none;
    max-width: 90%; text-align: center; text-shadow: 0 2px 16px rgba(0,0,0,0.7); animation: fade 1.2s ease;
  }
  body.view #tray, body.view .edit-only, body.view #hint { display: none !important; }
  body.view #viewBar { display: flex; }
  #gate {
    position: fixed; inset: 0; z-index: 30; display: none; align-items: center; justify-content: center;
    background: rgba(11, 8, 6, 0.94);
  }
  #gate.open { display: flex; }
  #gate .card { text-align: center; color: #fff; width: min(360px, calc(100% - 40px)); }
  #gate .kicker { font-size: 10px; letter-spacing: 0.32em; text-transform: uppercase; color: var(--gold-soft); }
  #gate h2 { font-family: var(--serif); font-style: italic; font-weight: 500; font-size: 40px; line-height: 1.05; margin: 14px 0 10px; }
  #gate p { color: rgba(255,255,255,0.7); margin: 0 0 26px; font-size: 13px; letter-spacing: 0.04em; }
  #gate .seal {
    width: 64px; height: 64px; margin: 0 auto 18px; border-radius: 50%;
    background: var(--gold); box-shadow: inset 0 0 0 3px var(--gold), inset 0 0 0 4px rgba(25, 17, 11, 0.35);
    display: grid; place-items: center;
    font-family: var(--serif); font-style: italic; font-size: 26px; color: var(--ink);
  }
  #toast {
    position: fixed; left: 50%; top: calc(90px + env(safe-area-inset-top)); transform: translateX(-50%);
    background: var(--white); color: var(--ink); padding: 10px 16px; font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase;
    opacity: 0; transition: opacity 0.3s; pointer-events: none; z-index: 40; box-shadow: var(--shadow);
  }
  @media (max-width: 480px) {
    header { padding-left: 12px; padding-right: 12px; }
    .brand .wm { font-size: 12px; letter-spacing: 0.32em; }
    .brand .sub { font-size: 12px; }
    header button { padding: 9px 12px; font-size: 9px; }
    header .hide-sm { display: none; }
  }

  /* atelier sheet: shorter so the globe stays visible while choosing */
  #styleSheet { background: rgba(0,0,0,0.12); }
  #styleSheet .sheet { max-height: 58vh; }
  .sheet h3 { font-size: 10px; letter-spacing: 0.26em; text-transform: uppercase; font-weight: 500; color: var(--ink); margin: 22px 0 2px; padding-top: 14px; border-top: 1px solid var(--line); }
  .sheet .row { margin: 12px 0; }
  .seg button { display: inline-flex; align-items: center; gap: 7px; }
  .seg .sw { width: 12px; height: 12px; border-radius: 50%; display: inline-block; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.18); }
  .seg button.on .sw { box-shadow: 0 0 0 1px #fff; }
  .sheet .tip { font-family: var(--serif); font-style: italic; font-size: 16px; color: var(--ink-soft); margin: 18px 0 0; }

  /* message */
  #message {
    width: 100%; font-family: var(--serif); font-style: italic; font-size: 20px; line-height: 1.35; padding: 12px 2px;
    border: 0; border-bottom: 1px solid var(--ink); background: transparent; color: var(--ink); border-radius: 0; outline: none; resize: none;
  }
  .sheet .count { font-size: 10px; letter-spacing: 0.18em; color: var(--ink-soft); text-align: right; margin-top: 6px; font-variant-numeric: tabular-nums; }
  #viewMsg {
    font-style: normal; text-shadow: none; color: var(--ink); background: var(--white);
    padding: 18px 22px 20px; width: min(420px, calc(100% - 32px)); max-width: none; bottom: 18px; box-shadow: var(--shadow);
  }
  #viewMsg .kicker { font-family: var(--sans); font-size: 9px; letter-spacing: 0.26em; text-transform: uppercase; color: var(--ink-soft); }
  #viewMsg p { margin: 8px 0 0; font-family: var(--serif); font-style: italic; font-size: 21px; line-height: 1.3; white-space: pre-wrap; text-wrap: balance; }

  /* ---- handcrafted note ---- */
  :root {
    --card: #f6efe1;
    --card-ink: #3a2a1d;
    --card-rule: rgba(58, 42, 29, 0.14);
    --wax: #7d1f26;
    --hand: "La Belle Aurore", "Segoe Script", "Bradley Hand", cursive;
    /* paper fibre: fractal noise, no gradients */
    --fibre: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .26 0 0 0 0 .16 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  }
  .paper {
    background-color: var(--card); background-image: var(--fibre); color: var(--card-ink);
    position: relative; box-shadow: 0 1px 0 rgba(0,0,0,0.04), 0 14px 34px rgba(0,0,0,0.38);
  }
  .paper::before { /* letterpress border */
    content: ""; position: absolute; inset: 9px; border: 1px solid var(--card-rule); pointer-events: none;
  }
  .wax { width: 46px; height: 46px; color: #f1d9c4; }
  .wax path { fill: var(--wax); }
  .wax text { font-family: var(--serif); font-style: italic; font-size: 34px; fill: currentColor; opacity: .55; }

  #viewMsg {
    background-color: var(--card); padding: 26px 30px 24px; width: min(400px, calc(100% - 40px)); bottom: 20px;
    transform: translateX(-50%) rotate(-1.6deg); animation: tuck 1.1s cubic-bezier(.2,.8,.2,1) both;
  }
  @keyframes tuck { from { opacity: 0; transform: translateX(-50%) translateY(40px) rotate(2deg); } }
  #viewMsg .wax { position: absolute; top: -18px; right: 18px; transform: rotate(12deg); }
  #viewMsg .kicker { color: rgba(58, 42, 29, 0.6); }
  #viewMsg p {
    font-family: var(--hand); font-style: normal; font-size: 23px; line-height: 1.55; color: var(--card-ink);
    margin: 10px 0 0; text-wrap: pretty;
  }

  /* writing the note: same paper, faint ruled lines */
  .note-sheet { background-color: var(--card); }
  .note-sheet .wax { position: absolute; top: 18px; right: 22px; transform: rotate(-8deg); }
  .note-sheet .kicker { color: rgba(58, 42, 29, 0.6); }
  .note-sheet h2 { color: var(--card-ink); }
  #message {
    font-family: var(--hand); font-style: normal; font-size: 23px; line-height: 38px; color: var(--card-ink);
    border-bottom: 0; padding: 4px 2px 0;
    background-image: repeating-linear-gradient(transparent 0 37px, var(--card-rule) 37px 38px);
    background-attachment: local;
  }
  #message::placeholder { color: rgba(58, 42, 29, 0.35); }
  .note-sheet .count { color: rgba(58, 42, 29, 0.55); }

  /* gift screen: wax seal instead of the gold disc */
  #gate .gate-wax { width: 70px; height: 70px; display: block; margin: 0 auto 18px; transform: rotate(-6deg); }

  /* zoom controls */
  #zoomCtl {
    position: absolute; right: max(14px, env(safe-area-inset-right, 0px)); top: 50%; transform: translateY(-50%);
    display: flex; flex-direction: column; gap: 6px; z-index: 4;
  }
  #zoomCtl button {
    width: 38px; height: 38px; padding: 0; display: grid; place-items: center; letter-spacing: 0;
    font-size: 18px; font-weight: 400; line-height: 1; background: rgba(255,255,255,0.08); color: #fff;
    border: 1px solid rgba(255,255,255,0.4); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  }
  #zoomCtl button:hover { background: rgba(255,255,255,0.2); }
  #zoomCtl button:focus-visible, button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
  @media (max-width: 900px) { header .hide-sm { display: none; } }

  /* Magnific-designed lockup + festive script headings */
  :root { --script: "Pinyon Script", "Snell Roundhand", cursive; }
  .brand .lockup { display: block; height: 58px; width: auto; margin: 0 auto; filter: drop-shadow(0 1px 6px rgba(0,0,0,0.55)); }
  #gate .gate-lockup { display: block; width: min(240px, 70%); height: auto; margin: 0 auto 6px; }
  #gate h2, .sheet h2 { font-family: var(--script); font-style: normal; font-weight: 400; letter-spacing: 0; }
  #gate h2 { font-size: 46px; line-height: 1.15; margin-top: 8px; }
  .sheet h2 { font-size: 38px; line-height: 1.1; }
  @media (max-width: 480px) { .brand .lockup { height: 44px; } }

  .linkbox { user-select: text; -webkit-user-select: text; }

  /* modern lockup: taller mark, clean sans headings */
  .brand .lockup { height: 64px; filter: none; }
  #gate h2, .sheet h2 { font-family: var(--sans); font-weight: 300; text-transform: none; letter-spacing: 0.01em; }
  #gate h2 { font-size: 34px; line-height: 1.2; }
  .sheet h2 { font-size: 28px; }
  @media (max-width: 480px) { .brand .lockup { height: 50px; } }


  /* lockup without the snowflake: wordmark + tagline only */
  .brand .lockup { height: 30px; }
  #gate .gate-lockup { width: min(260px, 72%); margin-bottom: 14px; }
  @media (max-width: 480px) { .brand .lockup { height: 24px; } }

  /* wordmark only */
  .brand .lockup { height: 20px; }
  #gate .gate-lockup { width: min(240px, 66%); }
  @media (max-width: 480px) { .brand .lockup { height: 16px; } }

  /* one place for Atelier + Message: the tray tabs (no duplicate header buttons) */
  #atelierBtn, #styleBtn { display: none !important; }
  /* fixed tray height so switching sections never resizes the 3D view */
  .tabs { height: 34px; flex-wrap: nowrap; align-items: center; }
  .items { height: 112px; align-items: flex-start; overflow-y: hidden; }
  .item { height: 104px; }

  /* handwritten moments share the note card's hand */
  #gate h2, .note-sheet h2 { font-family: var(--hand); font-weight: 400; letter-spacing: 0; text-transform: none; }
  #gate h2 { font-size: 44px; line-height: 1.3; }
  .note-sheet h2 { font-size: 34px; line-height: 1.25; }

  /* ornate-modern white wordmark (didone with swashes) */
  .brand .lockup { height: 34px; }
  #gate .gate-lockup { width: min(300px, 78%); }
  @media (max-width: 480px) { .brand .lockup { height: 26px; } }

  /* thinner fine-pen script for every handwritten moment */
  :root { --hand: "Italianno", "Snell Roundhand", cursive; }
  #gate h2 { font-size: 58px; line-height: 1.05; }
  .note-sheet h2 { font-size: 46px; line-height: 1.05; }
  #viewMsg p { font-size: 32px; line-height: 1.2; }
  #message { font-size: 30px; line-height: 38px; }

/* ===== embed: live preview inside lylahuang.com Projects ===== */
.embed header, .embed #tray, .embed #zoomCtl, .embed #hint, .embed .sheet-wrap, .embed #gate, .embed #toast { display: none !important; }
.embed body { cursor: pointer; }

/* ===== loading veil (models + textures stream in on phones) ===== */
#veil {
  position: fixed; inset: 0; z-index: 200; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  background: radial-gradient(ellipse at 50% 40%, #3a2618 0%, #1a110b 60%, #0f0a07 100%);
  transition: opacity 0.8s ease, visibility 0.8s;
}
#veil.gone { opacity: 0; visibility: hidden; }
.veil-lockup { width: min(320px, 66vw); height: auto; animation: veilBreathe 2.4s ease-in-out infinite alternate; }
.veil-bar { width: min(220px, 52vw); height: 2px; background: rgba(255,255,255,0.15); border-radius: 2px; overflow: hidden; }
.veil-bar i { display: block; height: 100%; width: 4%; background: #e8c98a; transition: width 0.3s ease; }
#veil p { margin: 0; font-family: "Jost", sans-serif; font-size: 11px; letter-spacing: 0.22em; text-transform: uppercase; color: rgba(255,240,220,0.7); }
@keyframes veilBreathe { from { opacity: 0.75; } to { opacity: 1; } }
.embed #veil { display: none; }

/* ===== receiver view: overlay controls, no shake/snow buttons ===== */
body.view #viewBar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  background: transparent; padding: 0 16px calc(18px + env(safe-area-inset-bottom));
  pointer-events: none;
}
body.view #viewBar button { pointer-events: auto; }
body.view #viewBar button.primary {
  background: rgba(255,255,255,0.14); color: #fff; border: 1px solid rgba(255,255,255,0.45);
  box-shadow: 0 6px 24px rgba(0,0,0,0.25); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
body.view #zoomCtl [data-z="shake"] { display: none; }
/* the note sits above the overlay button */
body.view #viewMsg { bottom: calc(76px + env(safe-area-inset-bottom)); }

/* "shake" prompt — fades in after the dome settles, fades out by itself */
#shakePrompt {
  position: absolute; left: 50%; top: 18%; transform: translate(-50%, 6px); z-index: 5;
  padding: 9px 16px; border-radius: 999px; white-space: nowrap; pointer-events: none;
  font-family: var(--sans); font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase;
  color: #fff; background: rgba(20,14,10,0.45); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  opacity: 0; transition: opacity 0.7s ease, transform 0.7s ease;
}
#shakePrompt.on { opacity: 1; transform: translate(-50%, 0); }
