:root {
  color-scheme: light;
  --accent: #791f2b;
  --cream: #fff5df;
  --ink: #352923;
  --sage: #dce3d2;
  --secondary-border: #747c62;
  --gold: #855408;
}
:root[data-theme="blue"] {
  --accent: #294e72;
  --ink: #25364a;
  --sage: #dce7ef;
  --secondary-border: #677c8d;
  --tin-filter: url(tin-themes.svg#blue);
}
:root[data-theme="green"] {
  --accent: #345a38;
  --ink: #2d3a2a;
  --sage: #dce8d5;
  --secondary-border: #697e61;
  --tin-filter: url(tin-themes.svg#green);
}
* { box-sizing: border-box; }
body {
  --page-gutter: clamp(0px, 3vw, 32px);
  margin: 0;
  padding: var(--page-gutter);
  background: radial-gradient(ellipse at top, #f7ecdc, #d3b696);
  color: var(--ink);
  font-family: Georgia, serif;
  line-height: 1.5;
  min-height: 100vh;
}
.tin {
  width: min(100%, 600px);
  margin: auto;
}
.auth-tin { position: relative; }
.closed .auth-tin h1 {
  position: absolute;
  inset: 30% auto auto 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  padding: .12em .45em;
  border: 3px double #a8804d;
  border-radius: 8px;
  background: #f6e3be;
  font-size: clamp(1.35rem, 5.4vw, 2.5rem);
  white-space: nowrap;
}
.tin:not(.open-tin) .paper { width: min(calc(100% - 24px), 420px); margin: 8px auto 0; }
.tin-cover {
  width: min(94%, 500px);
  margin-inline: auto;
}
.tin-cover-lid {
  display: block;
  width: 100%;
  height: auto;
  filter: var(--tin-filter, none);
}
.settings-link {
  position: absolute; inset: 8% 5% auto auto;
  display: grid; place-items: center;
  min-width: 44px; min-height: 44px;
  border: 1px solid #74512d; border-radius: 50%;
  background: var(--cream); color: var(--accent);
  font: 1.5rem system-ui, sans-serif;
  text-decoration: none;
}
.invite-dot {
  position: absolute;
  inset: 0 0 auto auto;
  width: 13px;
  height: 13px;
  border: 2px solid var(--cream);
  border-radius: 50%;
  background: #b92039;
}
.paper {
  padding: clamp(14px, 4vw, 27px);
  border: 1px solid #a8804d;
  border-radius: 17px 17px 13px 13px;
  background: linear-gradient(135deg, #fff6e3, #f5dfbc 65%, #fff2d8);
  box-shadow: inset 0 0 18px #ab794328, 0 -4px #ead6b6, 0 -6px #826139;
}
h1, h2 { color: var(--accent); line-height: 1.16; overflow-wrap: anywhere; }
h1 { font-size: clamp(2rem, 7vw, 3rem); margin: .45em 0 .55em; }
h2 { font-size: 1.3rem; margin: 0 0 .5em; }
p { margin: .45em 0 .8em; }
a { color: var(--accent); }
button, .button, input, select, textarea { font: inherit; }
button, .button {
  min-height: 44px; display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 14px; background: var(--accent); color: white;
  border: 1px solid var(--accent); border-radius: 9px; cursor: pointer; text-decoration: none;
}
.secondary { background: var(--sage); color: var(--ink); border-color: var(--secondary-border); }
.full { display: flex; width: 100%; font-size: 1.15rem; }
.stack { display: grid; gap: 12px; }
label { display: grid; gap: 4px; }
input:not([type=checkbox]), textarea, select {
  width: 100%; min-width: 0; min-height: 44px; padding: 8px 10px;
  border: 1px solid #92734e; border-radius: 7px; color: var(--ink);
  background: #fffaf0; font-size: 1rem;
}
textarea { resize: vertical; }
input[type=checkbox] { accent-color: var(--accent); width: 1.2rem; height: 1.2rem; margin: 0 4px 0 0; }
.check { display: flex; align-items: center; min-height: 44px; }
fieldset, .panel { border: 1px solid #b59569; border-radius: 9px; padding: 13px; margin: 0 0 13px; min-width: 0; }
.settings-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  overflow-wrap: anywhere;
}
.settings-row > button, .settings-row > form { flex-shrink: 0; }
.settings-heading h2 { margin: 0; }
.family-tin-heading h2 { margin: 0; min-width: 0; }
.family-tin-heading { margin-block: 12px; }
[data-share-invite][hidden] { display: none; }
.settings-row + .settings-row { border-top: 1px solid #b59569; padding-top: 8px; }
.settings-row:last-child { margin-bottom: 0; }
.panel h3 { margin: 12px 0 6px; font-size: 1rem; color: var(--accent); }
.profile-email { margin-top: 6px; overflow-wrap: anywhere; }
.auth-actions, .auth-links { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.auth-actions { margin-top: 12px; }
.auth-links { justify-content: space-between; margin-top: 16px; }
[data-phone-auth] { margin-top: 12px; }
[data-phone-auth] [hidden] { display: none; }
.google-button { gap: 6px; padding: 6px 10px; background: #fff; color: var(--ink); border-color: #92734e; }
.google-button svg { width: 20px; height: 20px; flex: none; }
.google-button:disabled { opacity: .55; cursor: default; }
#google-sign-in-status { margin-top: 8px; }
.icon-button { width: 44px; padding: 0; font-size: 1.4rem; }
.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.tin-access, .install-guide details + details { margin-top: 8px; }
.install-guide [data-install-app]:not([hidden]) { margin-bottom: 8px; }
.install-guide [data-install-app][hidden] { display: none; }
.panel summary { cursor: pointer; color: var(--accent); }
.panel details[open] summary, .panel[open] summary { margin-bottom: 8px; }
.invite-link { margin-bottom: 8px; }
.settings-dialog {
  width: min(400px, calc(100% - 24px));
  padding: 16px;
  border: 1px solid #8b6033;
  border-radius: 14px;
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 12px 32px #45260950;
}
.settings-dialog::backdrop { background: #35292380; }
legend { padding: 0 5px; }
small { display: block; }
.recipe-filters { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 7px; align-items: center; }
.tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 3px; margin: 13px 0 9px; }
.tabs a {
  min-height: 44px; display: grid; place-items: center; text-align: center;
  padding: 5px 2px; background: var(--sage); color: var(--ink);
  border-radius: 12px 12px 2px 2px; text-decoration: none; font-size: clamp(.75rem, 3vw, 1.05rem);
}
.tabs [aria-current] { background: var(--accent); color: white; }
.recipe-list { display: grid; gap: 10px; margin-top: 12px; }
.collection-create { background: #fff3d8; }
.collection-create > summary { font-weight: bold; }
.collection-create .settings-field > label { min-width: 0; }
.recipe-card {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 6px;
  padding: 12px; border: 1px solid #b59569; border-radius: 10px;
  background: #fff3d8; box-shadow: 0 2px 4px #53351925;
}
.recipe-card h2, .recipe-card p { margin: 0; }
.recipe-card h2 a { text-decoration: none; }
.recipe-card h2 a:hover { text-decoration: underline; }
.star { min-width: 44px; padding: 1px; border: 0; background: transparent; color: var(--gold); font-size: 1.5rem; }
.empty { text-align: center; }
.photo-picker { background: var(--sage); border: 1px solid var(--secondary-border); padding: 10px; border-radius: 8px; }
[data-recipe-entry] [hidden] { display: none; }
.recipe-entry-options, .recipe-step-actions, .ingredient-row-actions, .ingredient-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.recipe-entry-options [aria-pressed="true"] { background: var(--accent); color: white; border-color: var(--accent); }
.recipe-step-actions { justify-content: flex-end; }
.guided-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.guided-ingredient-list { margin: 0; padding-inline-start: 1.5em; }
.guided-ingredient-list li { padding-block: 6px; overflow-wrap: anywhere; }
.guided-ingredient-list li > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.guided-ingredient-list li > div > span { min-width: 0; }
.guided-ingredient-list li + li { border-top: 1px solid #b59569; }
.ingredient-row-actions { flex: none; flex-wrap: nowrap; gap: 2px; }
.ingredient-row-actions button { min-height: 32px; width: 32px; padding: 0; font-size: 1.2rem; line-height: 1; }
.ingredient-suggestions button { padding: 5px 9px; font-size: .92rem; }
[data-existing-ingredients] { white-space: pre-wrap; overflow-wrap: anywhere; }
.original-photo { display: block; width: 100%; max-height: 65vh; object-fit: contain; margin-top: 10px; }
.recipe-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.credit { font-style: italic; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.person { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; margin: 10px 0; overflow-wrap: anywhere; }
.transfer { border-top: 1px solid #b59569; padding-top: 12px; margin-top: 12px; }
.notice { padding: 8px 12px; background: var(--sage); border-radius: 6px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@media screen and (prefers-reduced-motion: no-preference) {
  .recipe-tab-entering [data-recipe-tab-content] { animation: fade-in 180ms ease-out both; }
}

/* Keep the entire photographic tin visible while the card content scrolls. */
.open-tin {
  position: relative;
  aspect-ratio: 2 / 3;
}
.open-tin::before {
  content: "";
  position: absolute;
  inset: 0;
  background: url(open-tin.webp) center / contain no-repeat;
  filter: var(--tin-filter, none);
}
.open-tin .lid {
  position: absolute;
  inset: 0 0 auto;
  height: 28%;
}
.open-tin .clasp { display: none; }
.tin-well {
  position: absolute;
  inset: 33.4% 7.1% 12.5%;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #ae8058 transparent;
  overscroll-behavior-y: contain;
}
.open-tin .paper {
  padding: clamp(8px, 2vw, 16px);
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
}
.opening-cover {
  position: absolute;
  inset: 0 0 auto;
  pointer-events: none;
  z-index: 1;
  animation: lift-cover .65s ease-in-out both;
}
.opening-cover .tin-cover-lid {
  transform-origin: center top;
  animation: hinge-lift .65s ease-in-out both;
}
.opening::before, .opening .lid, .opening .tin-well, .opening .clasp {
  animation: fade-in .42s .22s ease-out both;
}
@keyframes hinge-lift {
  to { transform: perspective(600px) rotateX(-82deg); }
}
@keyframes lift-cover {
  0%, 25% { opacity: 1; }
  100% { opacity: 0; visibility: hidden; }
}
@media (prefers-reduced-motion: reduce) {
  .opening-cover { display: none; }
  .opening::before, .opening .lid, .opening .tin-well, .opening .clasp { animation: none; }
}
@media screen and (max-width: 650px) {
  .open-tin {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    min-height: calc(100vh - 2 * var(--page-gutter));
    min-height: calc(100dvh - 2 * var(--page-gutter));
  }

  /* Slice the photo at y=513 and y=1344. Only the interior stretches. */
  .open-tin .lid, .open-tin::before, .open-tin .clasp { grid-column: 1; }
  .open-tin .lid::before, .open-tin::before, .open-tin .clasp {
    background-image: url(open-tin.webp);
    background-repeat: no-repeat;
    filter: var(--tin-filter, none);
  }
  .open-tin .lid {
    grid-row: 1;
    position: relative;
    inset: auto;
    height: auto;
    aspect-ratio: 1024 / 513;
  }
  .open-tin .lid::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-size: 100% calc(100% * 1536 / 513);
    background-position: center top;
  }
  .open-tin::before {
    position: static;
    grid-row: 2;
    background-size: 100% calc(100% * 1536 / 831);
    background-position: center calc(100% * 513 / 705);
  }
  .open-tin .tin-well {
    grid-area: 2 / 1;
    position: relative;
    inset: auto;
    min-height: 0;
    margin-inline: 7.1%;
  }
  .open-tin .clasp {
    grid-row: 3;
    display: block;
    aspect-ratio: 1024 / 192;
    background-size: 100% 800%;
    background-position: center bottom;
  }
}
@media print {
  body, .tin, .paper { padding: 0; width: 100%; background: white; color: black; border: 0; box-shadow: none; }
  .open-tin { aspect-ratio: auto; }
  .actions, .back, .clasp, .notice, .open-tin .lid, .open-tin::before, .tin-cover { display: none; }
  .tin-well { position: static; overflow: visible; }
  .open-tin .paper, .tin:not(.open-tin) .paper { padding: 0; width: 100%; margin: 0; }
  .original-photo { break-inside: avoid; }
}
