body { min-height: 100vh; }

.preview-bar {
  position: sticky; top: 0; z-index: 60;
  display: flex; justify-content: center; align-items: center; gap: 16px; flex-wrap: wrap;
  background: var(--ink); color: var(--paper);
  padding: 10px 16px; font-size: 14px; text-align: center;
}
.preview-bar[hidden] { display: none; }
.btn-xs { padding: 8px 16px; font-size: 14px; box-shadow: none; }

.cert-nav {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px var(--gutter);
  max-width: var(--max); margin: 0 auto;
}

/* ── Gift stage ── */
.gift-stage {
  min-height: calc(100vh - 90px);
  min-height: calc(100svh - 90px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 0 var(--gutter) 60px;
  transition: opacity .6s ease;
}
.gift-greet { font-family: var(--serif); font-style: italic; font-size: clamp(26px, 3.4vw, 36px); color: var(--red); margin-bottom: 6px; }
.gift-greet:empty { display: none; }
.gift-kicker { font-size: 15px; font-weight: 500; color: var(--ink-soft); letter-spacing: .02em; }
.from-line:empty, .from-line.hidden { display: none; }
.gift-name {
  font-family: var(--serif); font-weight: 400;
  font-size: clamp(56px, 11vw, 128px); line-height: .95; letter-spacing: -0.02em;
  margin: 8px 0 clamp(36px, 6vh, 64px);
  overflow-wrap: anywhere;
}
.gift-hint { margin-top: 36px; font-size: 14px; color: var(--ink-soft); letter-spacing: .08em; text-transform: uppercase; transition: opacity .3s; }

/* CSS gift box */
.giftbox {
  position: relative;
  width: min(240px, 60vw); aspect-ratio: 1 / 0.92;
  animation: wiggle 2.6s ease-in-out infinite;
  transform-origin: 50% 100%;
  -webkit-tap-highlight-color: transparent;
}
.giftbox:focus-visible { outline: 3px solid var(--ink); outline-offset: 12px; border-radius: 12px; }
.gb-body {
  position: absolute; left: 6%; right: 6%; bottom: 0; height: 68%;
  background:
    linear-gradient(90deg, transparent 43%, var(--paper) 43%, var(--paper) 57%, transparent 57%),
    linear-gradient(160deg, #E4453D, var(--red-deep));
  border-radius: 6px 6px 12px 12px;
  box-shadow: 0 30px 50px -20px rgba(168,35,30,.55), inset 0 -10px 20px rgba(0,0,0,.12);
}
.gb-lid {
  position: absolute; left: 0; right: 0; top: 18%; height: 18%;
  background:
    linear-gradient(90deg, transparent 43%, var(--paper) 43%, var(--paper) 57%, transparent 57%),
    linear-gradient(160deg, #EE5048, #C12A24);
  border-radius: 8px;
  box-shadow: 0 8px 14px -6px rgba(0,0,0,.25);
  z-index: 2;
  transition: transform .9s cubic-bezier(.3,1.4,.5,1), opacity .9s;
}
.gb-bow { position: absolute; left: 50%; bottom: 92%; width: 0; height: 0; }
.gb-bow i {
  position: absolute; bottom: 0;
  width: 58px; height: 40px;
  border: 12px solid var(--paper); border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
}
.gb-bow i:first-child { right: -4px; transform: rotate(-24deg); transform-origin: right bottom; }
.gb-bow i:last-child { left: -4px; transform: rotate(24deg); transform-origin: left bottom; }
.gb-empty {
  position: absolute; left: 12%; right: 12%; top: 32%; height: 10%;
  background: #7E1A16; border-radius: 4px; opacity: 0; z-index: 1;
  transition: opacity .3s .15s;
}
@keyframes wiggle {
  0%, 70%, 100% { transform: rotate(0); }
  74% { transform: rotate(-5deg); }
  78% { transform: rotate(5deg); }
  82% { transform: rotate(-4deg); }
  86% { transform: rotate(3deg); }
  90% { transform: rotate(0); }
}
.giftbox.opened { animation: none; cursor: default; }
.giftbox.opened .gb-lid { transform: translate(40%, -170%) rotate(38deg); }
.giftbox.opened .gb-empty { opacity: 1; }
.giftbox.opened ~ .gift-hint { opacity: 0; }

.reveal-text { max-height: 0; opacity: 0; overflow: hidden; transition: opacity .6s .5s, max-height .6s .3s; }
.reveal-text.show { max-height: 240px; opacity: 1; }
.reveal-text h2 { font-size: clamp(44px, 7vw, 76px); line-height: 1; margin-top: 8px; }
.reveal-text h2 em { color: var(--red); }
.reveal-text p { color: var(--ink-soft); font-size: 19px; margin-top: 8px; }

/* ── Certificate stage ── */
.cert-stage { display: none; padding: 20px var(--gutter) 100px; }
.cert-stage.show { display: block; animation: rise 1s cubic-bezier(.2,.8,.2,1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(40px); } to { opacity: 1; transform: none; } }

.certificate {
  position: relative;
  max-width: 760px; margin: 0 auto;
  background:
    radial-gradient(circle at 20% 10%, rgba(255,255,255,.7), transparent 40%),
    radial-gradient(circle at 90% 90%, rgba(184,145,74,.10), transparent 45%),
    var(--paper);
  border-radius: 6px;
  box-shadow: 0 1px 0 rgba(0,0,0,.04), 0 60px 120px -50px rgba(80,50,20,.55);
  padding: clamp(20px, 3vw, 30px);
}
.guilloche { position: absolute; inset: clamp(10px, 1.6vw, 16px); width: calc(100% - 2 * clamp(10px, 1.6vw, 16px)); height: calc(100% - 2 * clamp(10px, 1.6vw, 16px)); pointer-events: none; }
.guilloche rect { fill: none; stroke: var(--gold); stroke-width: .35; vector-effect: non-scaling-stroke; stroke-width: 1.5; }
.cert-inner {
  position: relative;
  border: 1px solid rgba(184,145,74,.55);
  padding: clamp(40px, 7vw, 72px) clamp(20px, 6vw, 64px) clamp(32px, 5vw, 48px);
  text-align: center;
  background-image:
    repeating-radial-gradient(circle at 50% 50%, transparent 0 18px, rgba(184,145,74,.05) 18px 19px);
}
.cert-logo { font-size: 26px; }
.cert-kicker { margin: 26px 0 30px; font-size: 13px; letter-spacing: .34em; text-transform: uppercase; color: var(--gold); font-weight: 600; }
.cert-this { font-family: var(--serif); font-style: italic; font-size: 22px; color: var(--ink-soft); }
.cert-name {
  font-family: var(--serif); font-weight: 400;
  font-size: clamp(52px, 9vw, 92px); line-height: 1.02; letter-spacing: -0.015em;
  margin: 10px 0 14px; overflow-wrap: anywhere;
}
.cert-owner { font-family: var(--serif); font-size: clamp(22px, 2.6vw, 27px); line-height: 1.3; max-width: 22em; margin: 0 auto; }
.cert-owner strong { font-weight: 400; font-style: italic; color: var(--red); }
.cert-msg {
  margin: 34px auto 0; max-width: 30em;
  padding: 22px 26px; border-radius: 14px;
  background: rgba(237,227,211,.6);
  font-size: 17px; text-align: left;
}
.cert-msg[hidden] { display: none; }
.cert-msg p { font-family: var(--serif); font-size: 22px; line-height: 1.3; }
.cert-msg footer { margin-top: 8px; font-size: 14px; color: var(--ink-soft); font-weight: 500; }

.cert-meta {
  display: grid; grid-template-columns: repeat(4, 1fr);
  margin: 40px 0 36px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.cert-meta div { padding: 16px 8px; display: grid; gap: 4px; }
.cert-meta div + div { border-left: 1px solid var(--line); }
.cert-meta span { font-size: 11px; text-transform: uppercase; letter-spacing: .14em; color: var(--ink-soft); font-weight: 600; }
.cert-meta strong { font-weight: 500; font-size: 16px; font-variant-numeric: tabular-nums; }

.cert-foot { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; text-align: left; }
.sig { display: grid; }
.sig-script { font-family: "Pinyon Script", cursive; font-size: clamp(32px, 4vw, 42px); line-height: 1; color: var(--navy); transform: rotate(-4deg); transform-origin: left; }
.sig-line { border-top: 1px solid var(--ink); margin-top: 6px; padding-top: 6px; font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-soft); min-width: 200px; }
.wax { flex: none; width: 120px; height: 120px; transform: rotate(-12deg); margin: -10px -6px -12px 0; }
.cert-stage.show .wax { animation: stamp .7s .5s cubic-bezier(.3,1.6,.5,1) both; }
@keyframes stamp { from { opacity: 0; transform: rotate(-30deg) scale(1.8); } to { opacity: 1; transform: rotate(-12deg) scale(1); } }
@media (max-width: 680px) {
  .cert-meta { grid-template-columns: 1fr 1fr; }
  .cert-meta div:nth-child(3) { border-left: 0; }
  .cert-meta div:nth-child(n+3) { border-top: 1px solid var(--line); }
}
@media (max-width: 560px) {
  .wax { width: 92px; height: 92px; }
  .sig-line { min-width: 0; }
}

/* Share */
.share { text-align: center; margin: 48px auto 0; }
.share-title { font-weight: 600; margin-bottom: 16px; }
.share-row { display: flex; justify-content: center; align-items: center; gap: 10px; flex-wrap: wrap; }
.share-btn {
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--red); color: var(--paper);
  display: grid; place-items: center;
  transition: transform .2s, background .2s;
}
.share-btn[hidden] { display: none; }
.share-btn:hover { transform: translateY(-3px); background: var(--red-deep); }
.share-btn svg { width: 24px; height: 24px; fill: currentColor; }
.share-copy {
  height: 54px; padding: 0 22px; border-radius: 999px;
  border: 1.5px solid var(--ink); font-weight: 600;
  transition: background .2s, color .2s;
}
.share-copy:hover { background: var(--ink); color: var(--paper); }

.what {
  max-width: 560px; margin: 64px auto 0; text-align: center;
  padding: 36px 28px; border-radius: var(--radius);
  background: var(--sand);
}
.what h3 { font-family: var(--serif); font-weight: 400; font-size: 34px; margin-bottom: 8px; }
.what p { color: var(--ink-soft); margin-bottom: 22px; }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 80; }
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px);
  background: var(--ink); color: var(--paper);
  padding: 12px 20px; border-radius: 999px; font-size: 15px; font-weight: 500;
  opacity: 0; transition: opacity .3s, transform .3s; z-index: 90; pointer-events: none;
  max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.cert-legal { text-align: center; margin-top: 32px; font-size: 13px; color: var(--ink-soft); }
.cert-legal a { color: inherit; }

/* Loading & not-found */
body.is-loading .gift-stage { visibility: hidden; }
.gift-stage[hidden] { display: none; }
.not-found {
  min-height: calc(100svh - 90px); display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 18px; padding: 0 var(--gutter) 80px;
}
.not-found[hidden] { display: none; }
.not-found h1 { font-size: clamp(48px, 8vw, 96px); line-height: 1; }
.not-found h1 em { color: var(--red); }
.not-found p { color: var(--ink-soft); font-size: 19px; max-width: 28em; }
.nf-box { width: 120px; height: 90px; border: 3px dashed var(--line); border-radius: 14px; margin-bottom: 12px; }
.nf-home { font-size: 15px; color: var(--ink-soft); }

body.self .only-gift, body:not(.self) .only-self { display: none !important; }
