@font-face {
  font-family: "Huninn";
  src: url("./assets/huninn.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  color: #17202a;
  background: #f5f1ea;
  font-family: Inter, ui-rounded, "Segoe UI", system-ui, sans-serif;
  font-synthesis: none;
  --ink: #17202a;
  --muted: #687078;
  --line: #d8d1c6;
  --paper: #fffdf9;
  --accent: #d94c70;
  --focus: #005fcc;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
button, input, textarea, select { font: inherit; }
button, summary, input, select, textarea { touch-action: manipulation; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 20px max(18px, env(safe-area-inset-right)) 16px max(18px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: rgb(255 253 249 / 92%);
}
.eyebrow, .step { margin: 0 0 3px; color: var(--accent); font-size: .72rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.lede { margin: 8px 0 0; color: var(--muted); font-size: .95rem; line-height: 1.4; font-weight: 550; max-width: 28rem; }
h1, h2 { margin: 0; line-height: 1.08; letter-spacing: -.025em; }
h1 { font-size: clamp(1.35rem, 5vw, 2rem); }
h2 { font-size: 1.2rem; }
.link-status { margin: 0; color: var(--muted); font-size: .82rem; text-align: right; }
.link-status.valid { color: #16714a; }
.link-status.invalid { color: #a12424; }

.flow-steps {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 18px 0;
}
.flow-steps ol {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: .92rem;
  font-weight: 650;
}
.flow-steps li { display: flex; align-items: center; gap: 8px; }
.flow-num {
  display: inline-grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 999px;
  background: #efe6dc;
  color: var(--ink);
  font-size: .78rem;
  font-weight: 800;
}

.link-gate {
  max-width: 560px;
  margin: 28px auto;
  padding: 22px 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: 0 12px 35px rgb(51 40 28 / 7%);
}
.link-gate h2 { margin-bottom: 10px; }
.link-gate p { margin: 0 0 10px; color: var(--ink); line-height: 1.5; }
.link-gate .hint { color: var(--muted); font-size: .9rem; }

.send-done {
  grid-column: 1 / -1;
  padding: 22px 20px;
  border: 1px solid #cfe8d8;
  border-radius: 18px;
  background: linear-gradient(180deg, #f3fbf6 0%, #fffdf9 100%);
  text-align: center;
}
.send-done-eyebrow {
  margin: 0 0 6px;
  color: #16714a;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.send-done h2 { margin-bottom: 8px; font-size: clamp(1.4rem, 4vw, 1.8rem); }
.send-done p { margin: 0; color: var(--muted); line-height: 1.5; }
main.is-sent .preview-panel,
main.is-sent .editor-panel {
  opacity: .42;
  filter: grayscale(.15);
}

.send-footer { margin-top: 8px; }
.send-step-label { margin-bottom: 6px; }
.privacy { margin: 12px 0 0; color: var(--muted); font-size: .85rem; line-height: 1.45; }

.occasion-field { background: #faf7f2; }
.occasion-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.occasion-grid .template-button {
  padding: 8px;
  font-size: .85rem;
  font-weight: 750;
}
.occasion-grid .template-swatch { aspect-ratio: 464 / 272; }
.photo-main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.photo-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px 12px;
  flex: 1 1 16rem;
  align-items: center;
}
#sign-name { margin-top: 8px; }
.sign-name-field { margin: 0 0 14px; }
.tap-text-hint { margin: 8px auto 0; max-width: 696px; }
.preview-draw-bar {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.preview-draw-bar .hint {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
}
.preview-draw-bar .history-actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  margin: 0 0 0 auto;
}
.preview-draw-bar .button,
.selection-bar .button {
  min-height: 34px;
  padding: 6px 10px;
}
.send-dock {
  grid-column: 1 / -1;
  padding: 14px 16px calc(12px + env(safe-area-inset-bottom));
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: 0 12px 35px rgb(51 40 28 / 7%);
}
.send-dock .privacy { margin-top: 8px; }
main.is-sent .send-dock { display: none !important; }
main.is-locked,
main[hidden] {
  display: none !important;
}

.selection-bar {
  display: none;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px auto 0;
  max-width: 696px;
}
.selection-bar.is-visible { display: flex; }
.selection-bar-label {
  flex: 0 1 auto;
  margin: 0;
  font-size: .82rem;
  font-weight: 700;
  color: var(--muted);
}
.selection-bar .quiet { font-weight: 800; }
.later-send, .type-details {
  margin: 0 0 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 12px;
}
.later-send > summary, .type-details > summary {
  cursor: pointer;
  font-weight: 750;
  padding: 10px 0;
}
.later-send .details-body, .type-details .details-body { padding-bottom: 10px; }

main { display: grid; gap: 18px; max-width: 1080px; margin: auto; padding: 18px; }
.preview-stick-sentinel {
  display: none;
  height: 1px;
  margin: 0 0 -1px;
  pointer-events: none;
}
.preview-stick-fill { display: none; height: 0; }
.preview-panel, .editor-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: 0 12px 35px rgb(51 40 28 / 7%);
}
.preview-panel { padding: 16px; align-self: start; }
.editor-panel { padding: 16px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.size-badge { padding: 5px 9px; border-radius: 999px; background: #eee8df; color: var(--muted); font: 700 .72rem ui-monospace, monospace; }

.preview-frame { position: relative; width: 100%; max-width: 696px; margin: auto; aspect-ratio: 464 / 272; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: #ddd; }
#preview { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#preview:active { cursor: grabbing; }
.preview-frame.drawing-active #preview,
.preview-frame.drawing-active #preview:active { cursor: crosshair; }
.draw-mode-indicator {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  border-radius: 999px;
  padding: 5px 10px;
  color: white;
  background: rgb(23 32 42 / 82%);
  font-size: .74rem;
  font-weight: 800;
}
/* safe1-overlay: Geometry from SAFE_MARGIN in app.js */
.safe-area {
  position: absolute;
  pointer-events: none;
  border: 1px dashed rgb(255 255 255 / 72%);
  border-radius: 4px;
  mix-blend-mode: difference;
}
.preview-options, .section-actions, .draft-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px;
  margin-top: 10px;
}
.inline-control { display: flex; grid-template-columns: none; align-items: center; gap: 7px; }
.inline-control input { width: auto; min-height: auto; }
.safe-area-status { color: #9b4b00; font-size: .78rem; font-weight: 700; }
.warning { color: #9b4b00 !important; font-weight: 700; }
.hint, .privacy, .details-hint { margin: 9px 0 0; color: var(--muted); font-size: .78rem; line-height: 1.45; }
.details-hint { padding: 0 13px 13px; }
.drawing-actions, .layer-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.layer-toolbar { padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: #faf7f2; }
.layer-list { display: grid; gap: 7px; margin-top: 10px; }
.layer-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  min-height: 40px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #faf7f2;
}
.layer-row[aria-current="true"] { border-color: var(--focus); background: #eef5ff; }
.layer-select { min-width: 0; overflow: hidden; border: 0; background: transparent; color: var(--ink); font-weight: 700; text-align: left; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.layer-action { width: 38px; min-height: 34px; border: 0; border-radius: 7px; background: #eae4db; cursor: pointer; }
.layer-action[aria-pressed="true"] { color: #fff; background: #59636d; }
.advanced-intro { margin-top: 0; }
#advanced-editor .section-actions { margin: 4px 0 12px; }

fieldset, details { margin: 0 0 14px; border: 1px solid var(--line); border-radius: 12px; }
fieldset { padding: 12px; }
legend { padding: 0 6px; font-weight: 750; }
summary { cursor: pointer; padding: 13px; font-weight: 750; }
.details-body { padding: 0 13px 13px; }
label { display: grid; gap: 6px; color: #34393f; font-size: .83rem; font-weight: 650; }
input, textarea, select {
  width: 100%;
  min-height: 42px;
  border: 1px solid #bbb3a8;
  border-radius: 9px;
  padding: 9px 10px;
  color: var(--ink);
  background: white;
}
textarea { resize: vertical; line-height: 1.45; }
input[type="color"] { padding: 4px; }
input[type="range"] { padding: 0; }
.wide { position: relative; display: grid; margin-bottom: 12px; }
.field-meta { position: absolute; right: 9px; bottom: 7px; color: var(--muted); font-size: .72rem; }
.control-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
output { color: var(--muted); font-size: .76rem; }

.template-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.template-button { display: grid; gap: 5px; min-width: 0; padding: 5px; border: 2px solid transparent; border-radius: 9px; color: var(--muted); background: transparent; font-size: .68rem; cursor: pointer; }
.template-button[aria-checked="true"] { border-color: var(--accent); color: var(--ink); }
.template-swatch { width: 100%; aspect-ratio: 2 / 1; border-radius: 5px; background: var(--sample); background-size: cover; background-position: center; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); margin-bottom: 12px; overflow: hidden; border: 1px solid #bbb3a8; border-radius: 9px; }
.segmented label { display: flex; justify-content: center; padding: 9px 3px; background: #f6f2ec; }
.segmented input { width: auto; min-height: auto; }

.sticker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 52px);
  justify-content: start;
  gap: 8px;
}
.sticker-button {
  width: 52px;
  height: 52px;
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 8px;
  background: #f5f1ea;
  cursor: pointer;
}
.sticker-button img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.sticker-button:active { border-color: var(--accent); transform: translateY(1px); }
.sticker-button.added { border-color: var(--accent); background: #fff0f4; }
.file-label { padding: 14px; border: 1px dashed #9e9588; border-radius: 10px; background: #faf7f2; text-align: center; }
.file-label input { border: 0; padding: 6px 0 0; }
.hidden { display: none !important; }

.button { min-height: 42px; border: 0; border-radius: 9px; padding: 9px 14px; font-weight: 750; cursor: pointer; }
.button:disabled { cursor: not-allowed; opacity: .48; }
.primary { color: white; background: #b8325a; }
.secondary { color: var(--ink); background: #eae4db; }
.quiet { color: #8a263b; background: transparent; border: 1px solid #d7b9c0; }
.send-button { width: 100%; margin-top: 10px; min-height: 50px; }
.send-status { min-height: 1.4em; margin: 9px 0 0; font-weight: 650; text-align: center; }
.send-status.error { color: #a12424; }
.send-status.success { color: #16714a; }
.turnstile-slot {
  margin-top: 0;
  min-height: 0;
}
body.turnstile-challenge .turnstile-slot {
  min-height: 65px;
  margin-top: 10px;
}

@media (min-width: 820px) {
  .topbar { padding-inline: 28px; }
  .flow-steps { padding-inline: 28px; }
  main { grid-template-columns: minmax(0, .95fr) minmax(420px, 1.05fr); padding: 28px; }
  .preview-panel { position: sticky; top: 20px; }
  .editor-panel, .preview-panel { padding: 20px; }
  .later-send > summary, .type-details > summary { display: none; }
  .later-send, .type-details {
    border: 0;
    padding: 0;
    margin: 0;
  }
}
@media (max-width: 819px) {
  /* Block layout so sticky preview can travel through the editor, not just its grid row. */
  main { display: block; }
  .preview-stick-sentinel { display: block; }
  .preview-panel {
    position: sticky;
    top: 0;
    z-index: 25;
    background: var(--paper);
  }
  body.keyboard-open:not(.preview-pinned) .preview-panel {
    position: static;
  }
  .editor-panel { margin-top: 18px; }
  .eyebrow, .flow-steps { display: none; }
  .preview-panel .step, .editor-panel .step, .send-step-label { display: none; }
  .preview-hint, #drawing-status { display: none; }
  .selection-bar-label { display: none; }
  .selection-bar { flex-wrap: nowrap; }
  .topbar { padding-top: 12px; padding-bottom: 10px; }
  .lede { margin-top: 4px; font-size: .86rem; }
  body {
    padding-bottom: calc(6.25rem + env(safe-area-inset-bottom));
  }
  body.turnstile-challenge {
    padding-bottom: calc(11.5rem + env(safe-area-inset-bottom));
  }
  body:has(main.is-sent),
  body.link-invalid {
    padding-bottom: 0;
  }
  body:has(main.is-sent) .preview-panel {
    position: static;
  }
  body.link-invalid .send-dock {
    display: none !important;
  }
  body.keyboard-open {
    padding-bottom: env(safe-area-inset-bottom);
  }
  body.keyboard-open .send-dock { display: none; }
  body.preview-pinned .preview-panel {
    position: fixed;
    top: var(--vv-top, 0px);
    left: 18px;
    right: 18px;
    z-index: 25;
    background: var(--paper);
    box-shadow: 0 8px 18px rgb(51 40 28 / 12%);
    padding-bottom: 8px;
    border-radius: 0 0 18px 18px;
  }
  body.preview-pinned .preview-stick-fill { display: block; }
  body.preview-pinned .preview-panel .section-heading,
  body.preview-pinned .preview-draw-bar,
  body.preview-pinned .selection-bar,
  body.preview-pinned .drawing-actions,
  body.preview-pinned .tap-text-hint {
    display: none;
  }
  body.preview-pinned .preview-frame {
    max-width: min(100%, 280px);
  }
  body.preview-pinned #advanced-editor,
  body.preview-pinned #text-editor {
    scroll-margin-top: 180px;
  }
  .send-dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    margin: 0;
    border: 0;
    border-radius: 0;
    border-top: 1px solid var(--line);
    background: rgb(255 253 249 / 96%);
    box-shadow: 0 -8px 24px rgb(51 40 28 / 12%);
  }
  .send-dock > .hint,
  .send-dock .privacy,
  #turnstile-hint { display: none; }
  .send-dock .send-button { margin-top: 8px; }
}
@media (max-width: 430px) {
  .template-grid { grid-template-columns: repeat(2, 1fr); }
  .control-grid { grid-template-columns: 1fr; }
  .sticker-grid { grid-template-columns: repeat(auto-fill, 48px); gap: 6px; }
  .sticker-button { width: 48px; height: 48px; padding: 7px; }
  .layer-toolbar .button { flex: 1 1 calc(50% - 8px); }
  .preview-panel { padding: 12px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
