/* Night mode, plus the header layout around its switch. Behavior is in js/theme.js.
 * Night mode only swaps colors; it adds no downloads.
 */

/* ---------- The switch: a cracked egg with a rising sun (day), a whole egg (night) ---------- */
.header-start { display: contents; } /* computer screens: no wrapper box */
.theme-btn {
  display: block; position: relative; flex: none; height: 44px; margin: 0;
  padding: 0; border: 0; border-radius: 999px; background: transparent; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.theme-btn::after { content: ""; position: absolute; inset: 0 -10px; } /* larger hit area */
.theme-btn .egg {
  position: absolute; left: 50%; top: 50%;
  max-width: none; height: auto; overflow: visible; /* may be a little wider than the button */
  transform: translate(-50%, -50%);
  transition: transform .15s var(--ease-out), filter .3s ease;
}
.theme-btn:active .egg { transform: translate(-50%, -50%) scale(0.9); }

/* Day: the halves tip open 45° either side of the sun. These transitions play when opening. */
.egg-half {
  fill: #dcc29f;
  transform-box: view-box; transform-origin: 20px 12.5px; /* center of the closed egg */
  transition: transform .62s cubic-bezier(0.34, 1.3, 0.64, 1) .04s, fill .3s ease;
}
.egg-half--l { transform: translate(-11.22px, -3.48px) rotate(45deg); }
.egg-half--r { transform: translate(11.22px, -3.48px) rotate(-45deg); }
.egg-sun {
  transform-box: view-box; transform-origin: 20px 15.5px;
  transition: transform .5s cubic-bezier(0.34, 1.5, 0.64, 1) .16s;
}
.egg-yolk { fill: #ef9330; }
.egg-rays {
  fill: none; stroke: #fffdf8; stroke-width: 2.1; stroke-linecap: round;
  transform-box: view-box; transform-origin: 20px 15.5px;
  transition: transform .55s var(--ease-out) .3s, opacity .3s ease .3s;
}
/* Shown only once the halves have closed, so their seam never shows. */
.egg-whole { fill: #f4eee4; opacity: 0; transition: opacity .1s ease; }

/* Night: the rays draw in and the halves shut over the sun. These transitions play when closing. */
[data-theme="dark"] .egg-half {
  fill: #f4eee4; transform: none;
  transition: transform .45s cubic-bezier(0.65, 0, 0.35, 1) .08s, fill .3s ease .22s;
}
[data-theme="dark"] .egg-sun { transform: scale(0); transition: transform .38s cubic-bezier(0.5, 0, 0.75, 0) .1s; }
[data-theme="dark"] .egg-rays { transform: rotate(-45deg) scale(0.5); opacity: 0; transition: transform .3s cubic-bezier(0.5, 0, 0.75, 0), opacity .22s ease; }
[data-theme="dark"] .egg-whole { opacity: 1; transition: opacity .15s ease .52s; }
[data-theme="dark"] .theme-btn .egg {
  filter: drop-shadow(0 0 3px rgba(255, 246, 225, 0.35));
  transition: transform .15s var(--ease-out), filter .4s ease .45s;
}
@media (prefers-reduced-motion: reduce) {
  .egg-half, .egg-sun, .egg-rays, .egg-whole, .theme-btn .egg { transition: none !important; }
}

/* Storybook is day-only, so the switch is disabled while it shows. */
.theme-btn[aria-disabled="true"] { cursor: default; }
.theme-btn[aria-disabled="true"] .egg { opacity: 0.55; }
.theme-btn[aria-disabled="true"]:active .egg { transform: translate(-50%, -50%); }

/* ---------- Header below 960px (menu button showing) ---------- */
@media (max-width: 959px) {
  /* Icons on each side are spaced evenly between the screen edge and the name. Each box is trimmed to
     its drawing so the gaps are even between what you see; ::after keeps the tap area generous. */
  .header-start, .header-row > .cart-btn {
    display: flex; align-items: center; justify-content: space-evenly; justify-self: stretch;
    position: relative;
    top: calc(3.9px - 0.37 * clamp(17px, 5.4vw, 21px)); /* level with the middle of the wordmark's capitals */
    min-width: 0; height: 44px; padding: 0; gap: 0;
  }
  .header-start { margin: 0 -8px 0 calc(-1 * var(--gutter)); }
  .header-row > .cart-btn { justify-content: center; margin: 0 calc(-1 * var(--gutter)) 0 -8px; border-radius: 0; background: transparent; }
  .header-start .menu-btn {
    position: relative; flex: none; width: 17.7px; height: 44px; margin: 0; padding: 0; border-radius: 0; background: transparent;
  }
  .header-start .menu-btn .icon { width: 24px; height: 24px; max-width: none; margin: 0 -3.15px; }
  .header-start .menu-btn::after { content: ""; position: absolute; inset: 0 -10px; }
  .header-row > .cart-btn .icon { width: 24px; height: 24px; margin: 0 -4.65px; stroke-width: 1.7; } /* matches the menu lines */
  /* Centered between the bag (its right edge is 7.35px past center) and the screen edge;
     the flower's drawing sits 12.58px into its 26px box. */
  .header-row > .cart-btn .cart-count {
    position: absolute; left: calc(75% + 3.68px - 12.58px); top: calc(50% - 13px); width: 26px; height: 26px;
  }
  /* Lining digits, nudged onto the flower's visual center. */
  .header-row > .cart-btn .cart-count-num { left: -0.54px; right: 0.54px; top: 6.81px; font-variant-numeric: lining-nums tabular-nums; }
  .theme-btn { width: 29.1px; }
  .theme-btn .egg { width: 30px; }
}

.navp:focus { outline: none; } /* the side menu opens focused on its panel */

/* ---------- Phones: the switch moves into the side menu ---------- */
.theme-btn--nav { display: none; }
@media (max-width: 639px) {
  .header-row .theme-btn { display: none; }
  .theme-btn--nav {
    display: block; width: 29.1px; margin: 0 auto;
    left: 7.8px; /* centers the egg between the name and the ✕ itself, not its wider tap area */
    top: calc(3.9px - 0.37 * clamp(17px, 5.4vw, 21px));
  }
  .theme-btn--nav .egg { width: 30px; }
  .navp-head [data-close] { position: relative; top: calc(3.9px - 0.37 * clamp(17px, 5.4vw, 21px)); }
}

/* ---------- Header from 960px: links, then book, switch, order ---------- */
@media (min-width: 960px) {
  .header-row { grid-template-columns: auto minmax(0, 1fr) auto auto auto; }
  [data-storybook="off"] .header-row { grid-template-columns: auto minmax(0, 1fr) auto auto; } /* no book button */
  .header-row > .nav-desktop { order: 1; }
  .header-row .book-btn { order: 2; }
  .header-row .theme-btn { order: 3; width: 44px; }
  .header-row > .cart-btn { order: 4; }
  .theme-btn .egg { width: 36px; }
}

/* ---------- Night colors ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #1a1512;
  --paper-2: #221b17;
  --paper-3: #2c241e;
  --kraft: #3e3226;        /* behind pictures while they load */
  --card: #28201a;
  --ink: #f3e9dc;
  --ink-2: #d3c5b4;
  --ink-3: #a99886;
  --rose: #e27886;         /* lighter, so red text reads on the dark page */
  --rose-deep: #ee96a2;
  --rose-tint: #42262b;
  --sage: #a9bf98;
  --sage-tint: #283322;
  --line: rgba(243, 233, 220, 0.12);
  --line-strong: rgba(243, 233, 220, 0.24);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 12px -6px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 18px 40px -22px rgba(0, 0, 0, 0.7);
  --shadow-lg: 0 30px 80px -30px rgba(0, 0, 0, 0.85);
  --parch: #241c16;
  --mb-ink-line: rgba(243, 233, 220, 0.18);
}
@media (min-width: 960px) { [data-theme="dark"] .site-header { background: rgba(26, 21, 18, 0.9); } } /* phones: solid --paper */
[data-theme="dark"] .icon-btn:hover { background: rgba(243, 233, 220, 0.08); }
@media (max-width: 959px) { [data-theme="dark"] .cart-btn:hover { background: rgba(243, 233, 220, 0.08); } }

/* White on red keeps the deeper day red for contrast. */
[data-theme="dark"] .btn-primary { background: #b74554; box-shadow: 0 10px 22px -12px rgba(0, 0, 0, 0.8); }
[data-theme="dark"] .btn-primary:hover:not(:disabled) { background: #c45263; }
[data-theme="dark"] .btn-primary:disabled { background: #4a3d35; color: #a99886; }
[data-theme="dark"] .btn-ghost:hover,
[data-theme="dark"] .social a:hover { border-color: #b74554; background: #b74554; }
[data-theme="dark"] .line-remove { background: #b74554; }
[data-theme="dark"] .line.is-armed .line-remove { background: #943442; }
[data-theme="dark"] .signup { background: #8f3341; }
[data-theme="dark"] .signup-form input { color: #2a201b; }

/* Dark-on-light elements flip to light-on-dark. */
[data-theme="dark"] .btn-dark { background: var(--ink); color: var(--paper); }
[data-theme="dark"] .cart-bar-btn { background: #f3e9dc; color: #1a1512; box-shadow: 0 16px 34px -14px rgba(0, 0, 0, 0.85); }
[data-theme="dark"] .proto-bar { background: #0e0b09; }
[data-theme="dark"] .proto-seg button[aria-pressed="true"] { color: #1a1512; }

[data-theme="dark"] .hero-badge { background: rgba(40, 32, 25, 0.94); }
[data-theme="dark"] .pd-close { background: rgba(40, 32, 25, 0.94); }
[data-theme="dark"] .pd-close:hover { background: #31271f; }
[data-theme="dark"] .field input:focus, [data-theme="dark"] .field textarea:focus { background: var(--card); }
[data-theme="dark"] .week-band--bake { background: #9a7b55; }
[data-theme="dark"] .week-band--bake .week-band-label { color: #cfae82; }
/* The thin dark-red rose drawing, lifted to a lighter rose (the newsletter's is already white). */
[data-theme="dark"] .rose-mark:not(.signup-rose) img,
[data-theme="dark"] .thanks-card > img { filter: brightness(1.8) saturate(0.75) hue-rotate(-14deg); }
[data-theme="dark"] dialog::backdrop { background: rgba(0, 0, 0, 0.6); }

/* Classic menu at night: plain dark parchment. The day grain and wash look blotchy on dark. */
[data-theme="dark"].menu-paper .menu {
  background-color: var(--parch);
  background-image: radial-gradient(150% 120% at 50% 42%, rgba(0, 0, 0, 0) 60%, rgba(0, 0, 0, 0.22) 100%);
  background-size: 100% 100%;
  background-position: 0 0;
  background-repeat: no-repeat;
}
[data-theme="dark"].menu-paper .menu::before, [data-theme="dark"].menu-paper .menu::after { background-color: var(--parch); background-image: none; }
