:root {
  --cream: #F7F1E8;
  --paper: #FFFDF9;
  --ink: #2A2522;
  --muted: #6E645D;
  --line: rgba(42, 37, 34, .2);
  --red: #B5302A;
  --red-deep: #932420;
  --green: #2F6B4F;
  --gold: #E2B13C;
  --accent: var(--red);
  --radius: 16px;
  --chart: "Alfa Slab One", Rockwell, Georgia, serif;
  --ui: Fredoka, "Avenir Next", "Trebuchet MS", system-ui, sans-serif;
  color-scheme: light;
}

body { --accent: #5B1631; }

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100dvh;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 18px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- falling snow / confetti ---------- */
.fall { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.p {
  position: absolute;
  top: -40px;
  width: var(--size);
  height: var(--size);
  animation-name: fall;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  will-change: transform;
}
.p-snow { border-radius: 50%; background: #C9DCE8; opacity: .8; }
.p-confetti { height: calc(var(--size) * .45); border-radius: 2px; opacity: .85; }
.p-letters {
  width: auto; height: auto;
  font-family: var(--chart);
  font-size: var(--size);
  color: rgba(42, 37, 34, .12);
}
@keyframes fall {
  to { transform: translate3d(var(--drift), calc(100dvh + 80px), 0) rotate(var(--spin)); }
}
@media (prefers-reduced-motion: reduce) {
  .fall { display: none; }
}

/* ---------- top bar ---------- */
.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px max(16px, env(safe-area-inset-right)) 6px max(16px, env(safe-area-inset-left));
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 4px 4px;
  border: 0;
  background: none;
  border-radius: 14px;
  cursor: pointer;
  text-align: left;
  min-width: 0;
}
.brand-mark { width: 40px; height: 40px; flex: none; color: var(--accent); transition: color .3s; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-family: var(--chart); font-size: 18px; letter-spacing: .04em; line-height: 1.1; }
.brand-office { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { border-color: var(--ink); }

/* ---------- screens ---------- */
main { position: relative; z-index: 1; }
.screen { display: none; padding: 8px 16px 32px; }
.screen.is-active { display: block; animation: rise .35s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.screen-title {
  font-family: var(--chart);
  font-weight: 400;
  font-size: clamp(28px, 5vw, 40px);
  letter-spacing: .03em;
  text-align: center;
  margin: 8px 0 20px;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 22px;
  border: 2px solid var(--ink);
  border-radius: 14px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 500;
  font-size: 18px;
  cursor: pointer;
  transition: transform .12s ease, background-color .2s, box-shadow .2s;
  box-shadow: 0 3px 0 var(--ink);
  touch-action: manipulation;
}
.btn:hover { background: #fff; }
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--ink); color: #FFF8EE; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-lg { min-height: 60px; padding: 12px 30px; font-size: 21px; border-radius: 16px; }
.btn-xl { min-height: 72px; padding: 14px 64px; font-size: 26px; border-radius: 20px; }
.btn-quiet { border-color: transparent; box-shadow: none; background: transparent; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.btn-quiet:hover { background: transparent; color: var(--ink); }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

/* ---------- home ---------- */
.home {
  min-height: calc(100dvh - 120px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 24px;
  max-width: 1080px;
  margin: 0 auto;
}
.booth-art { width: 100%; max-height: calc(100dvh - 140px); justify-self: end; }
.art-sign, .art-chart { font-family: var(--chart); }
.home-copy { display: flex; flex-direction: column; align-items: flex-start; gap: 14px; }
.home-copy h1 {
  font-family: var(--chart);
  font-weight: 400;
  font-size: clamp(40px, 6.5vw, 72px);
  line-height: 1.02;
  letter-spacing: .01em;
  margin: 0;
}
.home-sub { margin: 0 0 18px; font-size: 21px; color: var(--muted); }
.home-open, .home-closed { display: flex; flex-direction: column; align-items: inherit; gap: 14px; }
.home-closed { display: none; }
body.is-closed .home-open { display: none; }
body.is-closed .home-closed { display: flex; }
.home-closed h1 { font-size: clamp(34px, 5vw, 56px); }

.art-strip { animation: print 6s ease-in-out infinite; }
@keyframes print {
  0%, 12% { transform: translateY(-104px); opacity: 1; }
  45%, 85% { transform: translateY(0); opacity: 1; }
  95% { transform: translateY(0); opacity: 0; }
  100% { transform: translateY(-104px); opacity: 0; }
}
.art-flash { animation: flashbar 6s steps(1) infinite; }
@keyframes flashbar {
  0%, 100% { fill: #F2C14E; }
  4%, 7% { fill: #FFFFFF; }
}
.art-bulbs ellipse { animation: twinkle 1.6s ease-in-out infinite; }
.art-bulbs ellipse:nth-child(2n) { animation-delay: .8s; }
.art-bulbs ellipse:nth-child(3n) { animation-delay: .4s; }
@keyframes twinkle { 50% { opacity: .35; } }
.art-star { transform-origin: 200px 25px; animation: wobble 3s ease-in-out infinite; }

/* Start-screen decorations per event: Christmas or Chinese New Year */
body[data-scene="lunar"] .scene-christmas,
body:not([data-scene="lunar"]) .scene-lunar { display: none; }
body[data-scene="lunar"] .art-curtain { fill: #E8A93A; }
body[data-scene="lunar"] .art-folds { stroke: #C98B24; }
.art-lanterns > g { animation: twinkle 2.4s ease-in-out infinite; }
.art-lanterns > g:nth-child(2n) { animation-delay: 1.2s; }
.p-petals { border-radius: 60% 0 60% 0; opacity: .85; }
@keyframes wobble { 50% { transform: rotate(12deg) scale(1.08); } }
@media (prefers-reduced-motion: reduce) {
  .art-strip, .art-flash, .art-bulbs ellipse, .art-star { animation: none; }
}

/* ---------- menu ---------- */
.menu { max-width: 1000px; margin: 0 auto; display: flex; flex-direction: column; align-items: center; }
.theme-picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  width: 100%;
  max-width: 520px;
}
.theme-picker.is-single { grid-template-columns: minmax(0, 250px); justify-content: center; }
@media (min-width: 900px) {
  .theme-picker:has(> :nth-child(3)) { grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 760px; }
  .theme-picker:has(> :nth-child(4)) { grid-template-columns: repeat(4, minmax(0, 1fr)); max-width: 980px; }
}
.theme-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 10px 12px;
  border: 2px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  cursor: pointer;
  text-align: center;
  transition: border-color .2s, transform .15s;
}
.theme-card:hover { border-color: var(--ink); }
.theme-card[aria-pressed="true"] { border-color: var(--ink); box-shadow: 0 0 0 3px var(--gold); transform: translateY(-2px); }
.theme-thumb {
  height: min(340px, 42dvh);
  width: auto;
  max-width: 100%;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 6px 16px rgba(42, 37, 34, .18);
  margin-bottom: 8px;
}
.theme-name { font-weight: 600; font-size: 18px; }
.theme-blurb { font-size: 14px; color: var(--muted); line-height: 1.25; }

.menu-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; margin-top: 22px; }
.menu-actions .btn { min-width: 220px; }

/* ---------- booth ---------- */
.booth { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.stage {
  position: relative;
  display: inline-block;
  line-height: 0;
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(42, 37, 34, .22), 0 2px 6px rgba(42, 37, 34, .12);
}
.stage canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: min(100%, 720px);
  max-height: calc(100dvh - 230px);
  border-radius: 10px;
}
#screen-booth .stage { max-width: 100%; }
.countdown {
  position: absolute;
  display: grid;
  place-items: center;
  pointer-events: none;
  font-family: var(--chart);
  line-height: 1;
  color: #fff;
  text-shadow: 0 4px 20px rgba(0, 0, 0, .45);
}
.countdown span { animation: pop 1s ease-out both; }
@keyframes pop {
  0% { transform: scale(1.6); opacity: 0; }
  20% { transform: scale(1); opacity: 1; }
  85% { opacity: 1; }
  100% { transform: scale(.85); opacity: 0; }
}
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; border-radius: 10px; }
.flash.go { animation: flash .55s ease-out; }
@keyframes flash { 0% { opacity: .95; } 100% { opacity: 0; } }
.camera-msg {
  position: absolute;
  inset: 12% 8%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  border-radius: 16px;
  background: rgba(255, 253, 249, .96);
  line-height: 1.4;
  text-align: center;
}
.camera-msg p { margin: 0 0 6px; }
.hint { margin: 0; color: var(--muted); text-align: center; font-size: 17px; max-width: 46ch; }
.controls { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 12px; }

/* ---------- decorate ---------- */
.decorate {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 380px);
  gap: 28px;
  align-items: start;
  max-width: 1180px;
  margin: 0 auto;
}
.stage-decor { justify-self: center; }
.stage-decor canvas { max-height: calc(100dvh - 110px); touch-action: none; cursor: grab; }
.stage-decor canvas.dragging { cursor: grabbing; }
.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
  border: 2px solid var(--line);
  border-radius: 20px;
  background: var(--paper);
}
.panel .hint { text-align: left; font-size: 15px; }
.panel .album-note { font-size: 14px; color: #2F6B4F; }
.qr-box {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px;
  border: 2px solid var(--ink);
  border-radius: 16px;
  background: #fff;
}
.qr-code { width: 150px; height: 150px; flex: none; }
.qr-code svg { display: block; width: 100%; height: 100%; }
.qr-text { display: flex; flex-direction: column; gap: 4px; text-align: left; }
.qr-text strong { font-family: var(--chart); font-weight: 400; font-size: 22px; letter-spacing: .02em; }
.qr-text span { font-size: 15px; color: var(--muted); line-height: 1.35; }
@media (max-width: 420px) {
  .qr-box { flex-direction: column; text-align: center; }
  .qr-text { text-align: center; }
}
.panel-title { font-family: var(--chart); font-weight: 400; font-size: 28px; margin: 0; letter-spacing: .02em; }
.sticker-tray {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  gap: 8px;
}
.sticker {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 8px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
  transition: transform .12s, border-color .2s;
  touch-action: manipulation;
  overflow: hidden;
  min-width: 0;
}
.sticker:hover { border-color: var(--ink); transform: translateY(-2px); }
.sticker:active { transform: scale(.94); }
.sticker { position: relative; }
.sticker img {
  position: absolute;
  inset: 9px;
  width: calc(100% - 18px);
  height: calc(100% - 18px);
  object-fit: contain;
  pointer-events: none;
}
.sticker-tools { display: flex; gap: 8px; }
.tool {
  flex: 1;
  height: 46px;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
}
.tool svg { width: 22px; height: 22px; fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tool:disabled { opacity: .35; cursor: default; }
.tool-danger svg { stroke: var(--red); }
#clearStickersBtn { align-self: flex-start; min-height: 36px; padding: 4px 2px; font-size: 15px; }
.finish { display: flex; flex-wrap: wrap; gap: 10px; padding-top: 12px; border-top: 1.5px dashed var(--line); }
.finish .btn { flex: 1 1 auto; }
.finish-secondary { display: flex; gap: 10px; }
.finish-secondary .btn { flex: 1; min-height: 44px; font-size: 16px; }

/* ---------- settings dialog ---------- */
dialog {
  width: min(460px, calc(100vw - 32px));
  padding: 24px;
  border: 2px solid var(--ink);
  border-radius: 20px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(42, 37, 34, .45); }
dialog h2 { font-family: var(--chart); font-weight: 400; margin: 0 0 4px; font-size: 26px; }
dialog .hint { text-align: left; margin-bottom: 14px; font-size: 15px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; font-weight: 500; font-size: 16px; }
.field input, .field select {
  min-height: 46px;
  padding: 8px 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-weight: 400;
}
.check { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; font-size: 16px; }
.check input { width: 22px; height: 22px; accent-color: var(--red); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.dialog-actions .btn-quiet { margin-right: auto; }

/* ---------- smaller screens ---------- */
@media (max-width: 900px) {
  .decorate { grid-template-columns: minmax(0, 1fr); }
  .stage-decor canvas { max-height: 68dvh; }
}
@media (max-width: 720px) {
  .home { grid-template-columns: minmax(0, 1fr); text-align: center; min-height: 0; gap: 8px; }
  .booth-art { justify-self: center; max-width: 340px; max-height: 50dvh; }
  .home-copy { align-items: center; }
  .btn-xl { padding: 12px 48px; }
  .theme-thumb { height: 300px; }
  .stage canvas { max-height: calc(100dvh - 260px); }
}
@media (max-width: 420px) {
  .brand-office { display: none; }
  .theme-picker { gap: 10px; }
  .theme-thumb { height: 240px; }
  .theme-blurb { display: none; }
  .menu-actions .btn { min-width: 0; flex: 1 1 100%; }
  .btn-lg { padding: 10px 20px; }
}

/* ---------- printing (4x6 photo paper) ---------- */
#printSheet { display: none; }
/* The sheet shrinks to fit the paper, so it stays on one page even when the
   printer's "4x6" is a little smaller (Canon SELPHY postcards are 100x148mm). */
@media print {
  @page { size: 4in 6in; margin: 0; }
  html, body {
    width: 100%;
    height: 100%;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    background: #fff !important;
  }
  body > *:not(#printSheet) { display: none !important; }
  #printSheet {
    display: flex !important;
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    break-inside: avoid;
    break-after: avoid;
  }
  #printSheet img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
  }
}
