:root {
  --paper: #f7f4eb;
  --ink: #203e32;
  --muted: #706e60;
  --red: #983e32;
  --line: #d5cfbb;
  --cream: #fffcf3;
  --gold: #b9924b;
  --soft: #efe9d8;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font: 15px/1.6 'PingFang SC', 'Microsoft YaHei', sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button, select { cursor: pointer; }
button { border: none; background: none; }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, [tabindex="-1"]:focus-visible {
  outline: 3px solid #c18b46;
  outline-offset: 3px;
}
button:disabled { opacity: .42; cursor: not-allowed; }
.wrap { max-width: 1150px; margin: auto; padding: 0 40px; }

/* Header */
header { border-bottom: 1px solid var(--line); background: #fbf8ef; }
header .wrap { height: 74px; display: flex; justify-content: space-between; align-items: center; }
.brand {
  display: flex; gap: 12px; align-items: center;
  font: bold 23px 'Songti SC', 'STSong', serif; letter-spacing: 2px;
}
.mark {
  position: relative; width: 42px; height: 42px;
  border: 3px dotted var(--cream); border-radius: 5px;
  background: var(--ink); color: #fff6d6;
  text-align: center; font: 26px/36px Georgia, serif;
}
.head-end { font: italic 17px Georgia, serif; color: #70684f; }
.head-end b { font-style: normal; color: var(--red); padding: 0 9px; }

/* Intro */
.intro {
  margin: 30px 0 22px;
  display: flex; justify-content: space-between; align-items: flex-end; gap: 12px 20px;
}
.intro-main { min-width: 0; flex: 1; }
h1, h2, h3, p { margin: 0; }
h1 {
  font: 600 clamp(30px, 4.2vw, 52px)/1.22 'Songti SC', 'STSong', serif;
  letter-spacing: .025em;
}
.kicker, .micro {
  font: 600 11px/1.4 'Courier New', monospace;
  letter-spacing: .16em; color: var(--red);
}
.kicker { margin-bottom: 8px; }
.sub { color: var(--muted); margin-top: 8px; }
.link { color: var(--red); padding: 6px 2px; font-weight: 600; }
.link:hover { text-decoration: underline; text-underline-offset: 3px; }
.title-wish { overflow-wrap: anywhere; }

/* Main layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.48fr) minmax(280px, 1fr);
  gap: 22px; align-items: start;
}
.scene, .card { border: 1px solid var(--line); border-radius: 15px; overflow: hidden; }
.scene { position: relative; background: #eee8d7; isolation: isolate; }
.scene:before {
  content: ''; position: absolute; inset: 0; z-index: -1; opacity: .30;
  background-image:
    repeating-linear-gradient(0deg, transparent 0 15px, #cfc7ae 15px 16px),
    repeating-linear-gradient(90deg, transparent 0 15px, #cfc7ae 15px 16px);
}
.art {
  position: relative; width: min(100%, 460px);
  aspect-ratio: 480 / 432; margin: 16px auto 0;
}
.art canvas { display: block; width: 100%; height: 100%; }
.stamp {
  position: absolute; top: 18px; left: 18px;
  font: 700 10px/1.45 'Courier New', monospace; letter-spacing: .09em;
  color: #766a50; z-index: 1;
  border-top: 1px solid #998e75; border-bottom: 1px solid #998e75; padding: 3px 0;
}
.scene .corner {
  position: absolute; right: 18px; top: 15px;
  font: italic 19px Georgia, serif; color: #988460;
}
.tree-empty-hint {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  background: rgba(255, 252, 243, .88); border: 1px dashed #c2b699;
  border-radius: 999px; padding: 4px 14px; font-size: 12px; color: var(--muted);
  white-space: nowrap; pointer-events: none;
}
.tree-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border-top: 1px dashed #c9c1a9; padding: 11px 18px;
  background: #f6f1e3; font-size: 13px; flex-wrap: wrap;
}
.tree-stats { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.tree-foot b { color: var(--red); }
.unread-pill {
  display: inline-flex; align-items: center; gap: 5px;
  background: #f6e7dc; color: var(--red); border: 1px solid #e0c2b4;
  border-radius: 999px; padding: 1px 9px; font-size: 12px; font-weight: 600;
}
.unread-pill.all-read { background: #e8efe7; color: #36614a; border-color: #c5d7c8; }
.pager { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.pager button {
  min-width: 30px; min-height: 30px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--cream); color: var(--ink);
  font-size: 16px; line-height: 1; display: inline-grid; place-items: center;
}
.pager button:hover:not(:disabled) { background: #efe9d7; }

/* Ornaments on tree */
.orn {
  position: absolute; transform: translate(-50%, -50%);
  width: 10.5%; height: 11.5%; padding: 0;
  display: grid; place-items: center; border-radius: 50%;
  transition: transform .16s ease, filter .16s ease;
}
/* Ensure >= 44px touch target on mobile without expanding visual size */
.orn::after {
  content: ''; position: absolute;
  min-width: 44px; min-height: 44px; inset: -4px; margin: auto;
}
.orn:hover { transform: translate(-50%, -50%) scale(1.12); z-index: 3; }
.orn img {
  width: 86%; height: 92%; object-fit: contain;
  filter: drop-shadow(1px 3px 2px #16382288); pointer-events: none;
}
.orn.is-unread img {
  filter: drop-shadow(0 0 6px rgba(242, 206, 114, .95)) drop-shadow(1px 3px 2px #16382288);
}
.orn.is-unread::before {
  content: ''; position: absolute; top: 4%; right: 6%;
  width: 10px; height: 10px; border-radius: 50%;
  background: #c83e32; border: 2px solid var(--cream);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .28); z-index: 2;
  animation: pulseDot 2.1s ease-in-out infinite;
}
.orn.is-read img { opacity: .88; filter: drop-shadow(1px 2px 1.5px #16382266); }
.orn.is-new {
  z-index: 4;
  animation: popIn .48s cubic-bezier(.22, 1.35, .45, 1) both;
}
.orn.is-new img {
  filter: drop-shadow(0 0 10px rgba(240, 198, 98, 1)) drop-shadow(1px 3px 3px #163822aa);
}
.orn-tag {
  position: absolute; left: 50%; bottom: calc(100% + 2px); transform: translateX(-50%);
  background: var(--ink); color: #fffaf0; font-size: 11px; line-height: 1.3;
  padding: 2px 7px; border-radius: 999px; white-space: nowrap;
  box-shadow: 0 3px 10px rgba(20, 42, 31, .28); pointer-events: none;
}
.orn-sender {
  position: absolute; left: 50%; top: calc(100% + 1px); transform: translateX(-50%);
  background: rgba(32, 62, 50, .92); color: #fffaf0; font-size: 11px; line-height: 1.3;
  padding: 2px 7px; border-radius: 5px; white-space: nowrap; max-width: 110px;
  overflow: hidden; text-overflow: ellipsis; opacity: 0; pointer-events: none;
  transition: opacity .15s ease; z-index: 5;
}
.orn:hover .orn-sender, .orn:focus-visible .orn-sender { opacity: 1; }

@keyframes pulseDot {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.18); }
}
@keyframes popIn {
  0% { transform: translate(-50%, -50%) scale(.45); opacity: 0; }
  70% { transform: translate(-50%, -50%) scale(1.16); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
@keyframes unfold {
  0% { opacity: 0; transform: translateY(8px) scale(.98); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* Cards & Sidebar */
.card { background: var(--cream); padding: 24px 26px; }
.side { display: grid; gap: 16px; }
.paper {
  border-top: 5px solid transparent;
  border-image: repeating-linear-gradient(118deg, #954b3e 0 10px, #f8f0da 10px 18px, #537463 18px 28px, #f8f0da 28px 36px) 5 0 0 0;
}
.card h2, dialog h2 { font: 600 24px/1.35 'Songti SC', 'STSong', serif; margin: 8px 0; }
.card p, dialog p { color: var(--muted); font-size: 14px; margin: 8px 0 14px; }
.date-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.date { font: italic 18px Georgia, serif; color: var(--red); }
.countdown {
  font-size: 12px; font-weight: 600; color: var(--ink);
  background: var(--soft); border: 1px solid var(--line);
  border-radius: 999px; padding: 2px 10px;
}
.tz-note { font-size: 12px; color: var(--muted); margin: -6px 0 14px; }
.backup-tip {
  margin-top: 14px; padding: 10px 12px; border-radius: 9px;
  background: #f5efe0; border: 1px dashed #cbbd9c;
  font-size: 12.5px; color: #544e3f;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.backup-tip button { font-size: 12.5px; padding: 2px 4px; flex-shrink: 0; }

/* Buttons */
.mainbtn, .outline {
  border-radius: 8px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 9px 18px; gap: 8px;
  transition: background .15s ease, border-color .15s ease;
}
.mainbtn { background: var(--ink); color: #fffaf0; }
.mainbtn:hover:not(:disabled) { background: #2e5543; }
.outline { background: transparent; border: 1px solid #b6b5a3; }
.outline:hover:not(:disabled) { background: #f2ecdb; }
.danger { background: var(--red); color: #fffaf0; }
.danger:hover:not(:disabled) { background: #7f3127; }
.wide { width: 100%; }
.actions { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }
.actions .link { margin-left: 2px; }
.stack-actions { display: grid; gap: 8px; }

/* Inbox rows */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.rows { margin-top: 12px; display: grid; }
.row {
  display: flex; width: 100%; align-items: center; gap: 10px;
  text-align: left; padding: 10px 4px; border-top: 1px solid #e6e0d0;
  border-radius: 6px;
}
.row:hover { background: #f5f0e2; }
.row img { width: 29px; height: 30px; object-fit: contain; flex-shrink: 0; }
.row strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row small { margin-left: auto; color: var(--muted); white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--red); display: inline-block; }
.inbox-filters { display: flex; gap: 8px; margin: 8px 0 4px; }
.filter-chip {
  border: 1px solid var(--line); background: #f5f0e2; border-radius: 999px;
  padding: 4px 12px; font-size: 12.5px; color: var(--muted);
}
.filter-chip[aria-pressed="true"] {
  background: var(--ink); border-color: var(--ink); color: #fffaf0;
}
.inbox-list { max-height: 52dvh; overflow: auto; margin-top: 6px; }

/* Dialogs & Forms */
dialog {
  width: min(440px, calc(100% - 24px));
  border: 1px solid var(--line); border-radius: 16px;
  background: var(--cream); color: var(--ink);
  padding: 24px; box-shadow: 0 22px 90px #15291f44;
  max-height: 90dvh; overflow: auto;
}
dialog::backdrop { background: #19362966; backdrop-filter: blur(3px); }
.dlgTop { display: flex; justify-content: space-between; align-items: center; }
.close {
  font-size: 21px; color: var(--muted); width: 36px; height: 36px;
  border: 1px solid var(--line); border-radius: 50%;
  display: inline-grid; place-items: center;
}
.close:hover { background: #f2ecdb; }
.field-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 15px 0 6px; gap: 8px;
}
label.field, .field-label { font-weight: 600; display: block; margin: 0; }
.field-meta { font-weight: 400; font-size: 12px; color: var(--muted); }
.field-meta.near-limit { color: var(--red); font-weight: 600; }
input, textarea {
  border-radius: 8px; background: #fffdf7;
  border: 1px solid var(--line); width: 100%; padding: 10px 12px;
}
textarea { min-height: 96px; resize: vertical; }
.picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.pick {
  border: 1px solid var(--line); border-radius: 8px; padding: 6px;
  min-height: 44px; display: flex; align-items: center; justify-content: center;
  gap: 5px; font-size: 13px; background: #fffdf8;
}
.pick img { width: 28px; height: 30px; object-fit: contain; }
.pick[aria-pressed="true"] {
  background: #eeeada; border-color: #456650;
  box-shadow: inset 0 0 0 1px #456650; font-weight: 600;
}
.letter {
  margin: 15px 0; background: #f4efdf; border: 1px dashed #baa98b;
  border-radius: 9px; padding: 18px; color: #354939;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.letter.unfold { animation: unfold .32s ease both; }
.letter-head {
  display: flex; align-items: center; gap: 8px;
  color: var(--red); font-size: 13px; margin-bottom: 10px;
}
.letter-head img { width: 24px; height: 24px; object-fit: contain; }
.letter-nav {
  display: flex; align-items: center; justify-content: space-between;
  margin: -4px 0 14px; font-size: 13px; color: var(--muted);
}
.letter-nav button {
  padding: 5px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: #fffdf7; color: var(--ink); font-size: 13px;
}
.letter-nav button:hover:not(:disabled) { background: #f1ead8; }
.error { color: #a62f2a !important; font-size: 13px; }
.error:empty { display: none; }
.error:not(:empty) { margin: 9px 0; }
.code {
  font: 700 22px/1.5 'Courier New', monospace;
  letter-spacing: 1.5px; text-align: center; user-select: all;
}
.check-row {
  display: flex; align-items: center; gap: 8px;
  margin: 12px 0 16px; font-size: 14px; color: var(--ink); cursor: pointer;
}
.check-row input { width: 17px; height: 17px; margin: 0; accent-color: var(--ink); }
.invite-text { height: 86px; resize: vertical; }
.share-actions { margin-top: 14px; }
.inspiration { border: 0; padding: 0; margin: 10px 0 0; min-width: 0; }
.inspiration legend { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.prompt-list { display: flex; flex-wrap: wrap; gap: 6px; }
.prompt-chip {
  background: #f1ebda; border: 1px solid #d5cbb2; border-radius: 20px;
  padding: 5px 10px; color: var(--ink); font-size: 12px;
}
.prompt-chip:hover { background: #e8dec5; }
.prompt-feedback { display: block; color: var(--muted); font-size: 12px; }
.prompt-feedback:not(:empty) { margin-top: 6px; }
.compose-submit { margin-top: 14px; }
.hint { margin: 10px 0; font-size: 13px; color: var(--muted); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  background: #203e32; color: white; border-radius: 8px;
  padding: 9px 16px; z-index: 20; font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(17, 36, 27, .28);
  max-width: calc(100% - 32px); text-align: center;
}
.toast:empty { display: none; }

/* Mobile sticky CTA */
.mobile-cta { display: none; }

@media (max-width: 760px) {
  .wrap { padding: 0 16px; }
  header .wrap { height: 54px; }
  .mark { width: 32px; height: 32px; font-size: 20px; line-height: 26px; }
  .brand { font-size: 18px; }
  .head-end { font-size: 13px; }
  .intro { margin: 16px 0 12px; flex-wrap: wrap; align-items: center; }
  h1 { font-size: clamp(26px, 7.2vw, 34px); }
  .intro > .link { white-space: nowrap; font-size: 13px; margin-left: auto; }
  .sub { font-size: 13px; margin-top: 4px; }
  .layout { grid-template-columns: 1fr; gap: 14px; }
  .card { padding: 18px 18px; }
  .art { width: min(100%, 340px); margin-top: 6px; }
  .side { gap: 12px; }
  .scene .corner { right: 12px; top: 10px; font-size: 15px; }
  .stamp { top: 10px; left: 12px; font-size: 9px; }
  .tree-foot { padding: 10px 14px; font-size: 12.5px; }
  .stack-actions:has([data-a="write"]), .card > [data-a="write"] { display:none; }
  .orn-sender { display: none; }
  body.has-mobile-cta { padding-bottom: calc(74px + env(safe-area-inset-bottom, 0px)); }
  body.has-mobile-cta .toast { bottom: calc(82px + env(safe-area-inset-bottom, 0px)); }
  .mobile-cta {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 12;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
    background: rgba(251, 248, 239, .95); backdrop-filter: blur(8px);
    border-top: 1px solid var(--line); gap: 10px;
  }
  dialog { padding: 20px 18px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* The public invitation is a full-bleed scene; the owner's desk keeps its paper layout. */
.invitation {
  --ink: #214433;
  --red: #70452f;
  --muted: #505e58;
  --line: #c8d3ce;
  --cream: #fcfdfb;
  background: #213c5e;
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'PingFang SC', sans-serif;
}
.invitation::before {
  content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: url('/winter-clearing.webp') 80% center / cover no-repeat,
    linear-gradient(#142942, #3e6183 52%, #c4d5e5 74%, #e1e9f0);
}
.invitation > header { display: none; }
.invitation main.wrap { max-width: none; padding: 0; }
.invite-layout {
  width: min(100%, 490px); margin-inline: auto;
  min-height: 100vh; min-height: 100svh;
  display: grid; grid-template-rows: auto minmax(230px, 1fr) auto;
  padding: max(16px, env(safe-area-inset-top)) 20px max(16px, env(safe-area-inset-bottom));
}
.invite-head { display: grid; grid-template-columns: 1fr auto; align-items: start; gap: 10px; z-index: 1; }
.invite-clock, .invite-info, .invite-title, .invite-pages .pager, .invite-receipt {
  color: #20394a; background: rgba(252, 254, 255, .88); border: 1px solid #ffffffb0;
  box-shadow: 0 4px 18px #0c264329; backdrop-filter: blur(12px);
}
.invite-clock {
  justify-self: start; display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 16px; border-radius: 32px; min-height: 42px; font-size: 14px;
}
.invite-clock b { font-variant-numeric: tabular-nums; }
.invite-clock i {
  position: relative; width: 16px; height: 16px; border: 1.6px solid currentColor; border-radius: 50%;
}
.invite-clock i::after {
  content: ''; position: absolute; left: 5px; top: 2px; width: 4px; height: 5px;
  border-left: 1.5px solid; border-bottom: 1.5px solid; transform: skewY(18deg);
}
.invite-info { width: 44px; height: 44px; border-radius: 15px; font: bold italic 23px Georgia, serif; }
.invite-title { grid-column: 1 / -1; justify-self: start; max-width: 100%; padding: 10px 19px; border-radius: 19px; }
.invite-title h1, .invite-receipt h2 { font-family: inherit; font-size: 21px; font-weight: 750; line-height: 1.35; letter-spacing: 0; overflow-wrap: anywhere; }
.invite-title p, .invite-receipt p { margin: 3px 0 0; font-size: 13px; color: #52656d; }
.invite-stage.scene {
  min-width: 0; margin-inline: -20px; padding-top: min(5svh, 40px); overflow: hidden; background: transparent; border: 0; border-radius: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.invite-stage.scene::before { content: none; }
.invite-stage .art {
  flex: none; width: min(118vw, 580px, max(250px, calc((100svh - 270px) * 1.1)));
  margin: 0; max-width: none;
}
.invitation { overflow-x: clip; }
.invite-pages { position: relative; z-index: 1; }
.invite-pages .pager { border-radius: 99px; padding: 2px 8px; gap: 8px; font-size: 12px; }
.invite-pages button { border: 0; background: transparent; min-width: 44px; min-height: 40px; }
.invite-actions { display: grid; gap: 8px; align-self: end; position: relative; }
.invitation .mainbtn {
  background: linear-gradient(#42895c, #2e714d); color: white; border: 1px solid #ffffff4d;
  border-radius: 17px; box-shadow: 0 4px 14px #194d3e29;
}
.invitation .mainbtn:hover:not(:disabled) { background: #306f4b; }
.invite-actions .mainbtn { min-height: 54px; font-size: 19px; }
.invitation .outline { background: rgba(253, 255, 255, .88); border: 1px solid #ffffffcc; border-radius: 16px; }
.invite-actions .outline { min-height: 46px; color: #304854; box-shadow: 0 2px 10px #3452661f; }
.invite-receipt { text-align: center; border-radius: 16px; padding: 7px 14px; }
.invite-receipt h2 { font-size: 17px; }
.invitation dialog { border-radius: 22px; border-color: #fafdf9; background: #f9fcf9; }
.invitation dialog h2 { font-family: inherit; font-weight: 740; color: #253e36; }
.invitation dialog .dlgTop { justify-content: flex-end; }
.invitation dialog .dlgTop .micro { display: none; }
.invitation .pick[aria-pressed="true"] { background: #e2f1e6; }
.invitation dialog::backdrop { background: #132c47a8; }
.invitation .toast { bottom: max(126px, calc(env(safe-area-inset-bottom) + 112px)); }
.invitation #screen > :is(.intro,.card,.hint) {
  width: min(90%, 440px); margin: 16px auto; border-radius: 16px;
  background: #f7fbfe; padding: 18px; color: #233d49;
}
@media (max-height: 640px) {
  .invite-layout { padding-block: 10px; }
  .invite-title { padding-block: 6px; }
  .invite-head, .invite-actions { gap: 5px; }
  .invite-actions .mainbtn { min-height: 46px; }
}

@media (min-aspect-ratio: 1/1) and (min-width: 761px) {
  .invitation::before { background: linear-gradient(#172e60, #445f9d 44%, #7894c5 63%, #c6d3eb 74%, #d7dced); }
  .invitation::after {
    content: ''; position: fixed; z-index: -1; inset: 0; pointer-events: none; margin: auto;
    width: max(600px, 78vh);
    background: url('/winter-clearing.webp') center / cover no-repeat;
    mask-image: linear-gradient(90deg, transparent, black 18%, black 82%, transparent);
  }
}
