:root {
  color-scheme: light;
  --paper: #f6f1e9;
  --paper-light: #fcf9f3;
  --paper-deep: #eee1cf;
  --ink: #50382b;
  --muted: #8b7666;
  --copper: #ad7955;
  --copper-dark: #936442;
  --sage: #66745b;
  --line: #e0d4c5;
  --sans: "DM Sans", "Avenir Next", sans-serif;
  --serif: "DM Serif Display", Georgia, serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body.admin-locked > *:not(#auth-gate) { visibility: hidden; }
.auth-gate { display: none; }
.auth-gate:not([hidden]) { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 22px; background: var(--paper); }
.auth-panel { width: min(390px, 100%); padding: 25px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper-light); box-shadow: 0 12px 32px #50382b0c; }
.auth-panel h1 { margin: 0; font: 28px/1.1 var(--serif); }
.auth-panel > p:not(.eyebrow) { margin: 10px 0 20px; color: var(--muted); font-size: 12px; line-height: 1.55; }
.auth-panel form { display: grid; gap: 12px; }
.auth-panel input[type="password"] { width: 100%; height: 40px; padding: 0 10px; border: 1px solid #dfd4c7; border-radius: 5px; outline: none; color: var(--ink); background: #fffdfa; font-size: 13px; }
.auth-panel input[type="password"]:focus { border-color: var(--copper); box-shadow: 0 0 0 3px #ad79551c; }
.auth-status { min-height: 16px; margin: 0; color: var(--copper-dark); font-size: 11px; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  font-family: var(--sans);
  background-color: var(--paper);
  background-image: radial-gradient(#8b766610 0.75px, transparent 0.75px);
  background-size: 15px 15px;
}

button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.topbar {
  min-height: 72px;
  padding: 0 clamp(20px, 5vw, 72px);
  display: flex;
  align-items: center;
  gap: 20px;
  background: rgba(252, 249, 243, 0.92);
  border-bottom: 1px solid var(--line);
}

.wordmark {
  color: var(--ink);
  font: 28px/1 var(--serif);
  text-decoration: none;
}

.wordmark span { color: var(--copper); }
.topbar-label, .eyebrow, .preview-label, .preview-device {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.4px;
}

.topbar-label { color: var(--muted); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.save-state { color: var(--sage); font-size: 11px; }

.button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}

.button-quiet { padding: 0 13px; color: var(--ink); background: var(--paper-light); }
.button-quiet span { margin-right: 5px; color: var(--copper-dark); font-size: 16px; }
.button:hover, .icon-button:hover { border-color: var(--copper); }

.workspace { width: min(1440px, 100%); margin: 0 auto; padding: 38px clamp(20px, 5vw, 72px) 64px; }
.intro { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 26px; }
.eyebrow { margin: 0 0 8px; color: var(--copper-dark); }
.intro h1 { margin: 0; font: 34px/1.1 var(--serif); }
.intro-note { margin: 0 0 3px; color: var(--muted); font-size: 12px; }

.builder-layout { display: grid; grid-template-columns: minmax(270px, 340px) minmax(0, 1fr); align-items: start; gap: 26px; }
.editor { padding: 23px 22px 18px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper-light); }
.editor-heading { display: flex; align-items: center; justify-content: space-between; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.editor-heading .eyebrow { margin-bottom: 4px; }
.editor h2 { margin: 0; font: 21px/1.2 var(--serif); }
.icon-button { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 50%; color: var(--copper-dark); background: transparent; font-size: 19px; cursor: pointer; }

fieldset { display: grid; gap: 13px; margin: 0; padding: 17px 0 15px; border: 0; border-bottom: 1px solid var(--line); }
legend { padding: 0; margin-bottom: 2px; color: var(--ink); font-size: 12px; font-weight: 700; }
label { display: grid; gap: 6px; color: #705b4b; font-size: 11px; font-weight: 600; }
input[type="text"], input[type="url"] { width: 100%; height: 38px; padding: 0 10px; border: 1px solid #dfd4c7; border-radius: 5px; outline: none; color: var(--ink); background: #fffdfa; font-size: 12px; font-weight: 400; }
input:focus { border-color: var(--copper); box-shadow: 0 0 0 3px #ad79551c; }
input::placeholder { color: #aa9b8e; }
.field-hint { color: var(--muted); font-size: 10px; line-height: 1.5; font-weight: 400; }
.file-picker { position: relative; }
.file-picker input { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
.file-picker-button { width: fit-content; padding: 8px 11px; border: 1px solid var(--line); border-radius: 5px; color: var(--ink); background: #fffdfa; font-size: 11px; font-weight: 500; cursor: pointer; }
.file-picker:focus-within .file-picker-button { outline: 2px solid var(--copper); outline-offset: 2px; }
.file-name { overflow: hidden; color: var(--muted); font-size: 10px; font-weight: 400; text-overflow: ellipsis; white-space: nowrap; }
.editor-footnote { display: flex; gap: 9px; align-items: flex-start; padding-top: 15px; }
.editor-footnote p { margin: 0; color: var(--muted); font-size: 10px; line-height: 1.55; }
.info-mark { width: 15px; height: 15px; flex: 0 0 15px; border: 1px solid #bba995; border-radius: 50%; color: var(--copper-dark); font: 10px/14px var(--serif); text-align: center; }
.publish-controls { gap: 10px; border-bottom: 0; }
.publish-controls legend { margin-bottom: 1px; }
.publish-button { width: 100%; min-height: 43px; display: flex; justify-content: center; align-items: center; gap: 9px; border: 1px solid var(--copper-dark); border-radius: 6px; color: white; background: var(--copper-dark); font-size: 12px; font-weight: 600; cursor: pointer; }
.publish-button:hover { background: #7e5338; }
.publish-button:disabled { opacity: 0.6; cursor: wait; }
.publish-status { min-height: 15px; margin: 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
.publish-result { display: grid; gap: 12px; padding: 14px; border: 1px solid #cbd3c0; border-radius: 6px; background: #f2f5ee; }
.publish-result h3 { margin: 0; color: var(--sage); font-size: 12px; }
.publish-result label { gap: 6px; }
.publish-result input { background: white; }
.result-actions { display: flex; gap: 8px; }
.result-actions .button { min-height: 34px; display: inline-flex; align-items: center; justify-content: center; padding: 0 10px; color: var(--ink); text-decoration: none; font-size: 10px; }
.production-qr { display: flex; align-items: center; gap: 13px; }
.production-qr p { max-width: 190px; margin: 0; color: var(--muted); font-size: 10px; line-height: 1.5; }

.preview-area { min-width: 0; }
.preview-toolbar { min-height: 41px; display: flex; align-items: center; justify-content: space-between; padding: 0 15px; border: 1px solid var(--line); border-bottom: 0; border-radius: 8px 8px 0 0; background: #f1e9de; }
.preview-label { display: flex; align-items: center; gap: 8px; color: var(--ink); }
.preview-device { color: var(--muted); font-size: 9px; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--sage); box-shadow: 0 0 0 3px #66745b1a; }

.message-page { max-width: 760px; min-height: 700px; margin: 0 auto; overflow: hidden; border: 1px solid var(--line); border-radius: 0 0 8px 8px; background: var(--paper-light); box-shadow: 0 12px 32px #50382b0c; }
.message-hero { min-height: 294px; padding: 31px 24px 24px; display: flex; flex-direction: column; align-items: center; background: linear-gradient(155deg, #f1e6d5, #e8d4bc); text-align: center; }
.hero-heart { height: 29px; color: var(--copper); font: 32px/1 var(--serif); }
.brand-name { margin-top: 8px; color: #553a2b; font: clamp(54px, 7vw, 76px)/0.98 var(--serif); }
.brand-tagline { margin: 16px 0 0; color: var(--ink); font-size: 11px; font-weight: 600; letter-spacing: 4px; }
.memory-plaque { width: min(390px, 100%); margin-top: 31px; padding: 18px 16px 20px; border: 1px solid #d5c3ae; border-radius: 50% 50% 15px 15px / 24% 24% 15px 15px; background: #f8f2e8a8; }
.plaque-flowers { margin-bottom: 8px; color: #65422f; font-size: 15px; letter-spacing: 6px; }
.memory-plaque h2 { margin: 0; font: 18px/1.25 var(--serif); }
.memory-plaque p { margin: 6px 0 0; font: 16px/1.3 var(--serif); }

.message-content { padding: 37px clamp(20px, 4vw, 52px) 24px; text-align: center; }
.message-content > h1 { margin: 0; font: clamp(31px, 4vw, 46px)/1.13 var(--serif); }
.recipient { min-height: 21px; margin: 23px 0 37px; color: #78604e; font-size: 16px; }
audio { display: block; width: 100%; height: 44px; margin: 0 auto 29px; }
.audio-empty { display: none; margin: -20px 0 27px; color: var(--muted); font-size: 11px; }
.message-actions { display: grid; gap: 11px; }
.listen-button, .download-button { min-height: 56px; display: flex; justify-content: center; align-items: center; gap: 12px; border: 1.5px solid var(--copper); border-radius: 15px; text-decoration: none; font-size: 14px; font-weight: 600; transition: background-color 140ms ease, transform 140ms ease; }
.listen-button { color: white; background: var(--copper); cursor: pointer; }
.listen-button:hover { background: var(--copper-dark); }
.listen-button span { font-size: 13px; }
.download-button { color: var(--copper-dark); background: transparent; }
.download-button:not(.is-disabled):hover { background: #f5eadc; }
.download-button span { font-size: 20px; font-weight: 400; }
.download-button.is-disabled { opacity: 0.55; pointer-events: none; }

.qr-frame { width: 128px; height: 128px; margin: 0 auto; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 6px; background: white; }
#qr-code { display: grid; place-items: center; }
#qr-code img, #qr-code canvas { width: 110px; height: 110px; }
.qr-placeholder { color: #c7b6a5; font: 32px var(--serif); }
.qr-frame.has-qr .qr-placeholder { display: none; }
.message-footer { padding-top: 18px; }
.message-footer p { margin: 0 0 17px; color: #795b45; font-size: 12px; font-weight: 600; letter-spacing: 2px; }
.message-footer span { color: #988473; font-size: 11px; }
.message-footer b { font-weight: 600; }
.public-body { min-height: 100vh; }
.public-shell { width: min(820px, 100%); margin: 0 auto; padding: 22px 14px 48px; }
.public-shell .message-page { max-width: 760px; border-radius: 8px; }
.public-loading, .public-error { margin: 30px auto; color: var(--muted); text-align: center; font-size: 13px; }
.public-error { max-width: 460px; padding: 18px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper-light); line-height: 1.5; }
#public-qr img, #public-qr canvas { width: 110px; height: 110px; }

@media (min-width: 1200px) {
  .editor { position: sticky; top: 18px; }
}

@media (max-width: 850px) {
  .workspace { padding-top: 28px; }
  .builder-layout { grid-template-columns: 1fr; }
  .editor { order: 2; }
  .preview-area { order: 1; }
  .message-page { max-width: 650px; }
}

@media (max-width: 560px) {
  .topbar { min-height: 62px; padding: 0 16px; gap: 12px; }
  .wordmark { font-size: 25px; }
  .topbar-label { font-size: 8px; letter-spacing: 1px; }
  .topbar-actions { gap: 8px; }
  .save-state { display: none; }
  .button-quiet { min-height: 34px; padding: 0 9px; font-size: 11px; }
  .workspace { padding: 25px 12px 40px; }
  .intro { display: block; margin: 0 5px 19px; }
  .intro h1 { font-size: 29px; }
  .intro-note { margin-top: 8px; font-size: 11px; }
  .preview-toolbar { min-height: 37px; padding: 0 10px; }
  .preview-label { font-size: 8px; letter-spacing: 1px; }
  .preview-device { font-size: 8px; letter-spacing: 0.7px; }
  .message-hero { min-height: 270px; padding: 26px 15px 20px; }
  .brand-name { font-size: 60px; }
  .brand-tagline { margin-top: 13px; font-size: 9px; letter-spacing: 3px; }
  .memory-plaque { margin-top: 28px; padding: 16px 10px 17px; }
  .memory-plaque h2 { font-size: 16px; }
  .memory-plaque p { font-size: 14px; }
  .message-content { padding: 30px 18px 22px; }
  .message-content > h1 { font-size: 33px; }
  .recipient { margin: 18px 0 29px; }
  .listen-button, .download-button { min-height: 52px; border-radius: 13px; font-size: 13px; }
  .editor { padding: 19px 16px 16px; }
  .public-shell { padding: 12px 10px 28px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}