:root {
  --ink: #4f403c;
  --ink-soft: #71615b;
  --paper: #fbf3e7;
  --paper-deep: #f3e3cf;
  --peach: #e9a084;
  --peach-dark: #c97770;
  --lilac: #a687a7;
  --sage: #aeb99a;
  --sage-deep: #7f9076;
  --cream: #fffaf1;
  --shadow: 0 8px 24px rgba(82, 59, 48, 0.12);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: #e9dfd2;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  background:
    radial-gradient(circle at 12% 8%, rgba(255,255,255,.7), transparent 24rem),
    linear-gradient(135deg, #eadfd3, #dcd2c7);
}

button, input, textarea, select { font: inherit; }
button { color: inherit; }

.app-shell {
  position: relative;
  width: min(100%, 520px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 86px) 16px calc(var(--safe-bottom) + 102px);
  overflow-x: hidden;
  background-color: var(--paper);
  background-image:
    repeating-linear-gradient(0deg, rgba(115, 84, 62, .018) 0, rgba(115, 84, 62, .018) 1px, transparent 1px, transparent 5px),
    radial-gradient(circle at 18% 20%, rgba(206, 169, 132, .12) 0 1px, transparent 1.6px),
    radial-gradient(circle at 78% 65%, rgba(129, 111, 92, .08) 0 1px, transparent 1.8px);
  background-size: auto, 13px 13px, 17px 17px;
  box-shadow: 0 0 60px rgba(52, 39, 31, .18);
}

.topbar {
  position: fixed;
  z-index: 20;
  top: 0;
  left: 50%;
  width: min(100%, 520px);
  min-height: calc(var(--safe-top) + 78px);
  transform: translateX(-50%);
  padding: calc(var(--safe-top) + 10px) 18px 9px;
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  border-bottom: 1px solid rgba(96, 73, 59, .12);
  background: rgba(251, 243, 231, .94);
  backdrop-filter: blur(16px);
}

.topbar::after {
  content: "";
  position: absolute;
  inset: auto 0 -5px;
  height: 8px;
  background: linear-gradient(135deg, transparent 4px, var(--paper) 0) 0 0/10px 8px repeat-x;
}

.brand-wrap { text-align: center; line-height: 1; }
.brand-wrap h1 {
  margin: 2px 0 0;
  color: #75556c;
  font-family: "Comic Sans MS", "Bradley Hand", cursive;
  font-size: clamp(2rem, 10vw, 2.65rem);
  letter-spacing: -.06em;
  transform: rotate(-1deg);
}

.eyebrow, .kicker {
  margin: 0;
  color: var(--peach-dark);
  font-family: ui-rounded, "Arial Rounded MT Bold", sans-serif;
  font-size: .65rem;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 2px dashed rgba(90, 67, 56, .45);
  border-radius: 50%;
  background: #f8ebd8;
  box-shadow: 0 3px 0 rgba(96, 69, 52, .12);
}

.menu-button { gap: 4px; padding: 12px; }
.menu-button span { width: 19px; height: 2px; background: var(--ink); border-radius: 4px; }

.stitched-heart {
  display: grid;
  place-items: center;
  width: 45px;
  height: 45px;
  color: #fff6e9;
  font-size: 1.5rem;
  background: var(--peach);
  border: 2px dashed #fff2df;
  border-radius: 48% 48% 52% 52%;
  outline: 2px solid rgba(201, 119, 112, .28);
  transform: rotate(5deg);
}

main { display: grid; gap: 16px; }
.view { display: grid; gap: 16px; animation: page-in .22s ease-out; }
@keyframes page-in { from { opacity: 0; transform: translateY(5px); } }

.paper-panel, .note-card, .dog-card, .stat-card, .setting-card {
  position: relative;
  border: 1px solid rgba(94, 70, 56, .15);
  border-radius: 16px 12px 18px 11px;
  background: rgba(255, 250, 241, .88);
  box-shadow: var(--shadow);
}

.hero {
  min-height: 304px;
  padding: 28px 22px;
  display: grid;
  place-items: center;
  text-align: center;
  background:
    linear-gradient(rgba(255,250,241,.88), rgba(255,250,241,.88)),
    repeating-linear-gradient(0deg, transparent 0 23px, rgba(142, 117, 101, .1) 23px 24px);
}

.hero .kicker { align-self: start; }
.torn-bottom::after {
  content: "";
  position: absolute;
  z-index: 1;
  left: -1px; right: -1px; bottom: -6px;
  height: 10px;
  background: linear-gradient(135deg, var(--cream) 5px, transparent 0) 0 0/12px 10px repeat-x;
}

.tape {
  position: absolute;
  width: 74px;
  height: 28px;
  opacity: .72;
  background-image: repeating-linear-gradient(90deg, transparent 0 11px, rgba(255,255,255,.32) 11px 13px);
}
.tape-lilac { top: 86px; left: -15px; background-color: #b29abb; transform: rotate(-9deg); }
.tape-sage { top: 94px; right: -14px; background-color: #aaba9c; transform: rotate(8deg); }

.scan-button {
  width: 174px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 5px;
  padding: 20px;
  border: 3px dashed #f8dfca;
  border-radius: 50%;
  outline: 3px solid var(--peach-dark);
  background: var(--peach);
  box-shadow: 0 9px 0 #c87f6d, 0 16px 24px rgba(118, 73, 60, .22);
  transition: transform .15s ease, box-shadow .15s ease;
}
.scan-button:active { transform: translateY(5px); box-shadow: 0 4px 0 #c87f6d, 0 10px 18px rgba(118,73,60,.2); }
.scan-button-icon { font-size: 2.6rem; filter: sepia(.4); }
.scan-button strong { font-family: "Comic Sans MS", "Bradley Hand", cursive; font-size: 1.28rem; }
.scan-button small { color: rgba(79,64,60,.72); font-size: .72rem; }
.doodle-paws { align-self: end; justify-self: end; color: #c7a976; transform: rotate(8deg); }

.note-card, .setting-card { padding: 20px; }
.empty-card { text-align: center; border-style: dashed; }
.empty-card p:last-child { margin: 8px auto 0; max-width: 30ch; color: var(--ink-soft); line-height: 1.45; }
.hand-label, .section-title {
  margin: 0;
  font-family: "Comic Sans MS", "Bradley Hand", cursive;
  font-size: 1.25rem;
}

.paperclip {
  position: absolute;
  top: -10px; left: 24px;
  width: 13px; height: 32px;
  border: 2px solid #998b82;
  border-radius: 9px;
  transform: rotate(9deg);
}

.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; padding: 4px 5px 0; }
.section-heading h2 { margin: 0; font-family: "Comic Sans MS", "Bradley Hand", cursive; font-size: 1.5rem; }
.section-heading p { margin: 0; color: var(--ink-soft); font-size: .8rem; }

.recent-card { overflow: hidden; }
.photo-frame { position: relative; margin: 10px; padding: 8px 8px 0; background: #fffaf0; box-shadow: 0 2px 7px rgba(62,45,36,.16); transform: rotate(-.35deg); }
.dog-photo { width: 100%; aspect-ratio: 4/3; display: block; object-fit: cover; border-radius: 8px 6px 5px 8px; background: #e2d7c8; }
.photo-caption { display: flex; justify-content: space-between; gap: 10px; padding: 10px 4px 12px; color: var(--ink-soft); font-family: "Comic Sans MS", cursive; font-size: .82rem; }
.ribbon-label { position: absolute; z-index: 2; top: 2px; left: -3px; padding: 8px 17px; background: var(--peach); font-family: "Comic Sans MS", cursive; font-weight: 700; transform: rotate(-2deg); box-shadow: 2px 3px 0 rgba(134,82,68,.14); }

.breed-summary { display: grid; grid-template-columns: 58px 1fr auto; gap: 12px; align-items: center; padding: 15px; }
.breed-stamp { width: 58px; height: 58px; display: grid; place-items: center; border: 2px dashed var(--lilac); border-radius: 50%; background: #f0e5ed; font-size: 1.7rem; }
.breed-summary h3 { margin: 0 0 4px; font-family: "Comic Sans MS", cursive; font-size: 1.25rem; }
.breed-summary p { margin: 0; color: var(--ink-soft); font-size: .78rem; }
.rarity-chip { align-self: start; padding: 5px 9px; border-radius: 999px; background: #e7d6e7; color: #765a79; font: 700 .68rem ui-rounded, sans-serif; }

.progress-card { padding: 16px; background: #e7eadb; }
.progress-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 9px; }
.progress-meta strong { font-family: "Comic Sans MS", cursive; }
.progress-track { height: 18px; padding: 3px; border: 1px solid rgba(75,70,58,.22); border-radius: 999px; background: #fff9ed; }
.progress-fill { height: 100%; min-width: 12px; border-radius: inherit; background: var(--lilac); }

.collection-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.dog-card { overflow: hidden; background: #fffaf1; transform: rotate(var(--tilt, 0deg)); }
.dog-card:nth-child(3n+1) { --tilt: -.5deg; }
.dog-card:nth-child(3n+2) { --tilt: .6deg; }
.dog-card button { width: 100%; padding: 0; border: 0; background: transparent; text-align: left; }
.dog-card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: #dfd4c5; }
.dog-card-copy { padding: 10px 11px 12px; }
.dog-card h3 { margin: 0 0 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: "Comic Sans MS", cursive; font-size: 1rem; }
.dog-card p { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-soft); font-size: .72rem; }

.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stat-card { min-height: 130px; padding: 17px; display: grid; align-content: space-between; background: #fff9ef; }
.stat-card:nth-child(2) { background: #f0e5ed; }
.stat-card:nth-child(3) { background: #e7eadb; }
.stat-card:nth-child(4) { background: #f7e2d8; }
.stat-value { font-family: "Comic Sans MS", cursive; font-size: 2rem; color: #75556c; }
.stat-label { color: var(--ink-soft); font-size: .78rem; }

.setting-card { display: grid; gap: 14px; }
.setting-row { display: flex; gap: 14px; align-items: center; justify-content: space-between; }
.setting-row + .setting-row { padding-top: 14px; border-top: 1px dashed rgba(83,64,53,.2); }
.setting-row div:first-child { min-width: 0; }
.setting-row strong { display: block; margin-bottom: 3px; }
.setting-row small { display: block; color: var(--ink-soft); line-height: 1.35; }

.button, .text-button, .danger-button {
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid rgba(82,61,51,.18);
  border-radius: 13px;
  background: #f6e7d6;
  font-family: ui-rounded, "Arial Rounded MT Bold", sans-serif;
  font-size: .82rem;
  font-weight: 800;
  box-shadow: 0 3px 0 rgba(92,63,48,.12);
}
.button.primary { color: #fffaf1; border-color: var(--peach-dark); background: var(--peach-dark); }
.button.secondary { background: #e9e1ec; }
.wide-button { width: 100%; justify-content: center; }
.button:active, .text-button:active, .danger-button:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(92,63,48,.12); }
.text-button { min-height: auto; padding: 5px 7px; border: 0; background: transparent; box-shadow: none; color: #7f607a; }
.danger-button { color: #8c4646; background: #f7e2df; }
.button:disabled { opacity: .5; }

.bottom-nav {
  position: fixed;
  z-index: 30;
  left: 50%; bottom: 0;
  width: min(100%, 520px);
  min-height: calc(79px + var(--safe-bottom));
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: start;
  padding: 8px 5px var(--safe-bottom);
  border-top: 1px solid rgba(94,70,56,.14);
  background: rgba(255,249,239,.96);
  backdrop-filter: blur(15px);
  box-shadow: 0 -8px 24px rgba(70,50,38,.1);
}

.nav-item { min-width: 0; min-height: 61px; display: grid; place-items: center; align-content: center; gap: 2px; border: 0; background: transparent; color: #74645e; font-family: ui-rounded, sans-serif; font-size: .62rem; }
.nav-icon, .camera-glyph { font-size: 1.55rem; line-height: 1; }
.nav-item.is-active { color: #775a79; font-weight: 800; }
.scan-nav { position: relative; margin-top: -28px; }
.scan-nav .camera-glyph { width: 54px; height: 54px; display: grid; place-items: center; color: #fff8ec; border: 3px dashed #f6d8c3; border-radius: 50%; outline: 2px solid var(--peach-dark); background: var(--peach); box-shadow: 0 5px 12px rgba(104,65,54,.25); }

.sheet {
  width: min(calc(100% - 20px), 500px);
  max-height: min(88dvh, 820px);
  margin: auto auto 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 24px 24px 0 0;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 -15px 50px rgba(48,34,28,.28);
}
.sheet::backdrop { background: rgba(55,43,37,.42); backdrop-filter: blur(2px); }
.sheet-body { max-height: 88dvh; padding: 11px 18px calc(22px + var(--safe-bottom)); overflow-y: auto; }
.sheet-handle { width: 46px; height: 5px; margin: 3px auto 15px; border-radius: 999px; background: rgba(85,65,55,.25); }
.sheet-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.sheet-header h2 { margin: 0; font-family: "Comic Sans MS", cursive; font-size: 1.55rem; }
.sheet-header p { margin: 4px 0 0; color: var(--ink-soft); font-size: .82rem; line-height: 1.4; }
.close-button { flex: 0 0 auto; width: 40px; height: 40px; border: 1px solid rgba(78,59,51,.15); border-radius: 50%; background: #f4e7d7; font-size: 1.15rem; }

.choice-grid { display: grid; gap: 11px; }
.choice-card { min-height: 74px; display: grid; grid-template-columns: 46px 1fr; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid rgba(83,62,52,.14); border-radius: 15px; background: #fff9ef; text-align: left; }
.choice-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; background: #f0dfd2; font-size: 1.3rem; }
.choice-card strong { display: block; margin-bottom: 3px; }
.choice-card small { color: var(--ink-soft); }

.preview-image { width: 100%; max-height: 40dvh; display: block; object-fit: contain; border: 9px solid #fff8ed; border-radius: 13px; background: #dfd4c4; box-shadow: var(--shadow); }
.form-grid { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field label, .field legend { color: var(--ink); font: 800 .76rem ui-rounded, sans-serif; }
.field input, .field textarea, .field select {
  width: 100%; min-height: 46px; padding: 11px 12px;
  border: 1px solid rgba(83,62,52,.2); border-radius: 12px;
  color: var(--ink); background: rgba(255,252,246,.94); outline: none;
}
.field textarea { min-height: 84px; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--lilac); box-shadow: 0 0 0 3px rgba(166,135,167,.18); }
.field-hint { color: var(--ink-soft); font-size: .7rem; line-height: 1.35; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); padding: 3px; border-radius: 13px; background: #ede1d5; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; }
.segmented span { min-height: 40px; display: grid; place-items: center; border-radius: 10px; font: 800 .72rem ui-rounded, sans-serif; }
.segmented input:checked + span { color: #fffaf1; background: #80647f; box-shadow: 0 2px 5px rgba(77,56,76,.18); }
.mix-field[hidden] { display: none; }
.form-actions { position: sticky; bottom: -1px; display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; margin: 6px -4px -4px; padding: 13px 4px 4px; background: linear-gradient(transparent, var(--paper) 26%); }

.detail-photo { width: 100%; max-height: 43dvh; object-fit: cover; border-radius: 14px; background: #e1d5c4; }
.detail-list { margin: 15px 0; padding: 0; list-style: none; }
.detail-list li { display: grid; grid-template-columns: 92px 1fr; gap: 10px; padding: 9px 0; border-bottom: 1px dashed rgba(84,62,51,.15); }
.detail-list span:first-child { color: var(--ink-soft); font-size: .78rem; }
.detail-list strong { font-size: .9rem; }
.local-badge { display: inline-flex; align-items: center; gap: 5px; padding: 5px 9px; border-radius: 999px; color: #62715b; background: #dfe6d5; font: 800 .68rem ui-rounded, sans-serif; }
.warning-note { padding: 12px; border-left: 4px solid var(--peach); border-radius: 8px; color: var(--ink-soft); background: #f7e8dc; font-size: .78rem; line-height: 1.45; }

.analysis-loader {
  min-height: 240px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  text-align: center;
}
.analysis-loader strong { font-family: "Comic Sans MS", "Bradley Hand", cursive; font-size: 1.15rem; }
.analysis-loader small { color: var(--ink-soft); }
.paw-spinner {
  width: 82px;
  height: 82px;
  display: grid;
  place-items: center;
  border: 3px dashed #f3d5c2;
  border-radius: 50%;
  outline: 2px solid var(--peach-dark);
  color: #765a79;
  background: var(--peach);
  font-size: 2.3rem;
  animation: paw-pulse 1.15s ease-in-out infinite;
}
@keyframes paw-pulse {
  0%, 100% { transform: rotate(-5deg) scale(.94); box-shadow: 0 4px 0 rgba(139,85,69,.18); }
  50% { transform: rotate(5deg) scale(1.04); box-shadow: 0 9px 18px rgba(139,85,69,.19); }
}

.suggestion-panel {
  padding: 13px;
  border: 1px solid rgba(94,70,56,.14);
  border-radius: 15px 11px 16px 12px;
  background: #ece5ef;
  box-shadow: 0 4px 12px rgba(77,56,76,.08);
}
.suggestion-panel.compact { margin-top: 14px; }
.suggestion-heading { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.suggestion-heading strong { font-family: "Comic Sans MS", "Bradley Hand", cursive; }
.suggestion-heading span { align-self: center; color: #80647f; font: 800 .62rem ui-rounded, sans-serif; text-transform: uppercase; letter-spacing: .08em; }
.suggestion-list { display: grid; gap: 7px; }
.suggestion-row {
  width: 100%;
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 11px;
  border: 1px solid rgba(87,66,83,.12);
  border-radius: 11px;
  background: rgba(255,250,244,.78);
  text-align: left;
}
.suggestion-row strong, .suggestion-row small { display: block; }
.suggestion-row small { margin-top: 2px; color: var(--ink-soft); font-size: .66rem; }
.match-score { flex: 0 0 auto; min-width: 48px; padding: 6px 8px; border-radius: 999px; color: #fffaf2; background: #80647f; text-align: center; font: 800 .7rem ui-rounded, sans-serif; }
.suggestion-panel > p { margin: 10px 2px 0; color: var(--ink-soft); font-size: .69rem; line-height: 1.4; }
.saved-match { display: flex; justify-content: space-between; gap: 12px; padding: 7px 2px; border-top: 1px dashed rgba(79,62,75,.16); font-size: .78rem; }

.toast { position: fixed; z-index: 60; left: 50%; bottom: calc(92px + var(--safe-bottom)); max-width: calc(100% - 34px); transform: translate(-50%, 18px); padding: 10px 15px; border-radius: 999px; color: #fffaf2; background: rgba(73,56,50,.94); box-shadow: 0 8px 24px rgba(42,30,25,.2); opacity: 0; pointer-events: none; transition: .2s ease; font: 700 .76rem ui-rounded, sans-serif; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.visually-hidden { position: fixed !important; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

@media (min-width: 521px) {
  .app-shell { min-height: 920px; margin-block: 20px; border-radius: 35px; }
  .topbar { top: 20px; border-radius: 35px 35px 0 0; }
  .bottom-nav { bottom: 20px; border-radius: 0 0 35px 35px; }
  .sheet { margin-bottom: 20px; border-radius: 24px; }
}

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