/* Safari's browser chrome also samples the system-scheme canvas before JS. */
@media(prefers-color-scheme:dark){
  :root:root,html:root body{background-color:#161c19!important;color-scheme:dark!important}
}
@media(prefers-color-scheme:light){
  :root:root,html:root body{background-color:#f5f1e9!important;color-scheme:light!important}
}
/* Paint the root canvas too: Safari exposes it around its dynamic toolbars. */
html[data-theme]{min-height:100%;height:auto;background-color:#f5f1e9!important}
html[data-theme] body{box-sizing:border-box;min-height:100vh;min-height:100dvh}
@media(max-width:700px){
  html[data-theme] body{padding-bottom:env(safe-area-inset-bottom,0px)}
  html[data-theme] body .linen-texture{inset:0;bottom:auto;min-height:100vh;min-height:100lvh}
}
html[data-theme="dark"] {color-scheme:dark!important;background:#161c19!important}
/* The homepage's ID selector otherwise keeps its body canvas light beneath the texture. */
html[data-theme="dark"] body#linen-home{background:#161c19!important;color-scheme:dark!important}
html[data-theme="light"] body#linen-home{background:#f5f1e9!important;color-scheme:light!important}
html[data-theme="dark"] body {
  --bg:#161c19;--bg-2:#202923;--surface:#202923;--surface-soft:#29342c;--fill:#29342c;
  --text:#e0e8df;--ink:#e0e8df;--text-muted:#adbbae;--text-dim:#a3b1a6;--muted:#adbbae;
  --border:#3b4940;--border-strong:#516357;--line:#3b4940;--paper:#161c19;--card:#202923;
  --accent:#9ac9ae;--accent-hover:#b9dec7;--green:#9ac9ae;
  background:#161c19!important;color:#e0e8df!important;
}
html[data-theme="dark"] :is(body,#linen-home) :is(h1,h2,h3,h4,p,span,strong,label,legend,li,td,th,summary,a,button,input,select,textarea,pre,code,em,b){color:#edf3ee!important}
html[data-theme="dark"] body *{border-color:#3b4940!important;text-shadow:none!important}
html[data-theme="dark"] body .linen-texture{background:linear-gradient(to bottom,#161c19 0px,transparent 180px),radial-gradient(ellipse at top right,#29433555,transparent 65%),#161c19!important}
html[data-theme="light"] body .linen-texture{background:linear-gradient(to bottom,#f5f1e9 0px,transparent 180px),linear-gradient(to top,#f5f1e9 0px,transparent 180px),radial-gradient(ellipse at 92% 0%,#dce8de99,transparent 58%),radial-gradient(ellipse at 5% 95%,#eee0c680,transparent 60%),linear-gradient(135deg,#f6f2e9 0%,#f2f4ec 55%,#eaf0e7 100%)!important}
@media(max-width:700px){html[data-theme="light"] body .linen-texture{height:100vh;height:100dvh;min-height:0}}
html[data-theme="dark"] body :is(.paper-today,.paper-cottage,.link-card,.home-shortcut,.edit-card,.account-card,.admin-card,.messages-card,.message-item,.mail-compose,.meal-panel,.dish-tile,.series-card,.lesson-card,.lesson-sidebar,.recipe-section,.order-cart-bar,.modal,.user-menu-panel,.ai-page-main,.ai-page-chat,.ai-material-page,.ai-composer,.ai-starter-prompts button,.summary-card,.panel,.main-stat,dialog,[data-ai-jobs],.media-result){background:#202923!important;color:#e0e8df!important;box-shadow:none!important}
html[data-theme="dark"] body :is(.paper-ai-sidebar,.home-nav,.paper-tabs,.mail-filters,.ai-message-user .ai-message-content,.ai-chat-header,.ai-chat-tools,.ai-chat-form,input,textarea,select,button,.btn,.user-menu-trigger){background:#29342c!important;color:#e0e8df!important}
html[data-theme="dark"] body :is(.is-active,.is-selected,[aria-pressed="true"],.btn-primary,.primary-button){background:#3a5948!important;color:#f0f8f2!important}
html[data-theme="dark"] body :is(.topbar-title,.paper-greeting h1,.reminder-count,.reminder-count b,.reminder-count em,#family-reminder-prefix){color:#e0e8df!important}
html[data-theme="dark"] body :is(.paper-date,.link-desc,.form-hint,.ai-jobs-status,.ai-composer-note,small){color:#adbbae!important}
html[data-theme="dark"] body :is(input,textarea)::placeholder{color:#a3b1a6!important;opacity:1}
html[data-theme="dark"] dialog::backdrop{background:#0009}
html[data-theme="dark"] body :focus-visible{outline:2px solid #b5ddbf;outline-offset:3px}
html[data-theme="dark"] body :is(.paper-directory,.search-box,.paper-action,.home-shortcuts,.home-message-preview,.bakery-hero,.menu-hero,.messages-hero){background:#202923!important;color:#e0e8df!important}
html[data-theme="dark"] body :is(.home-shortcut,.home-shortcut strong,.link-name,.paper-directory h2,.paper-action){color:#e0e8df!important}
/* The wrapper owns the search field surface; Safari must not paint a second inset field. */
html[data-theme="dark"] body#linen-home .search-box{background:#29342c!important}
html[data-theme="dark"] body#linen-home .search-box input#search{
  -webkit-appearance:none;appearance:none;background:transparent!important;
  border:0!important;border-radius:0;box-shadow:none!important;color:#e0e8df!important;
}
/* Keep helper copy readable without inheriting the original light-theme greens. */
html[data-theme="dark"] :is(body,#linen-home) :is(small,.paper-date,.directory-caption,.link-desc,.form-hint,.ai-jobs-status,.ai-composer-note,.ai-starter-prompts small,.message-time,.paper-weather){color:#c0cec3!important;opacity:1!important}
html[data-theme="dark"] :is(body,#linen-home) :is(input,textarea)::placeholder{color:#b9c9be!important;opacity:1!important}
html[data-theme="dark"] body.ai-workspace :is(.ai-reasoning,.ai-message-content blockquote,.ai-message-content pre,.ai-model-select-label select){background:#29342c!important;color:#edf3ee!important}
html[data-theme="dark"] body.ai-workspace .ai-composer-note{font-size:11px}
html[data-theme="dark"] body.ai-workspace .ai-starter-prompts small{font-size:11px}
html[data-theme="dark"] body#linen-home .paper-tabs,
html[data-theme="dark"] body#linen-home .paper-tabs button{background:transparent!important;box-shadow:none!important}
html[data-theme="dark"] body#linen-home .link-favicon-fallback{color:#476352!important}
html[data-theme="dark"] body.menu-body .menu-hero{background:transparent!important}
/* Baking search uses a single surface, including Safari's native search input. */
body.bakery-body .bakery-search{display:flex;align-items:center;gap:10px;width:100%;min-height:48px;padding:0 14px;box-sizing:border-box;border-radius:12px;overflow:hidden}
body.bakery-body .bakery-search svg{width:20px;height:20px;flex:0 0 20px}
body.bakery-body .bakery-search input#bakery-search{-webkit-appearance:none;appearance:none;flex:1;width:100%;min-width:0;min-height:46px;margin:0;padding:10px 0;border:0!important;border-radius:0;background:transparent!important;box-shadow:none!important;font-size:16px;line-height:1.5}
html[data-theme="dark"] body.bakery-body .bakery-search{background:#29342c!important;color:#edf3ee!important}
html[data-theme="dark"] body.bakery-body .bakery-hero{background:linear-gradient(120deg,#2b382e,#24302a)!important;border:1px solid #3b4940!important;border-radius:16px}
body.bakery-body .bakery-hero{box-sizing:border-box}
@media(max-width:700px){body.bakery-body .bakery-hero{padding:24px 20px}body.bakery-body .bakery-brand{font-size:25px;line-height:1.5}body.bakery-body .bakery-toolbar{margin:20px 0}}
html[data-theme="dark"] body.menu-body .meal-tabs{background:transparent!important;box-shadow:none!important}
html[data-theme="dark"] body.menu-body .meal-tabs [aria-selected="true"]{background:#3a5948!important}
body.menu-body .meal-panel-top{gap:20px}
body.menu-body .meal-actions-compact{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px;width:100%}
body.menu-body .meal-field{min-width:0;width:100%}
body.menu-body .meal-field select{width:100%;min-width:0;min-height:44px;border-radius:10px;box-sizing:border-box}
@media(max-width:700px){
  body.menu-body .meal-panel-top{display:flex;flex-direction:column;align-items:stretch}
  body.menu-body .edit-toolbar{display:flex;flex-wrap:wrap;gap:10px;align-items:center}
  body.menu-body .edit-toolbar h2{flex:1 0 auto;white-space:nowrap;margin:0}
  body.menu-body .edit-toolbar .edit-hint{flex-basis:100%}
}
/* Message surfaces and interaction states need their own dark palette. */
html[data-theme="dark"] body.messages-body .messages-hero,
html[data-theme="dark"] body.messages-body .mail-filters{background:transparent!important}
html[data-theme="dark"] body.messages-body .mail-filters button{background:transparent!important;color:#c0cec3!important}
html[data-theme="dark"] body.messages-body .mail-filters button[aria-pressed="true"]{background:#3a5948!important;color:#f0f6f1!important}
html[data-theme="dark"] body.messages-body :is(.mail-selection,.mail-undo){background:#29382e!important;border-color:#4a6050!important;color:#edf3ee!important}
html[data-theme="dark"] body.messages-body .message-item.is-selected{background:#314b3b!important;border-color:#6f947c!important}
html[data-theme="dark"] body.messages-body #message-delete{background:#49312c!important;color:#ffc2b4!important;border-color:#785047!important}
html[data-theme="dark"] body.messages-body #message-send{background:#3a5948!important;color:#f0f6f1!important}
html[data-theme="dark"] body.messages-body :is(.message-time,.message-sender,.messages-hero-desc,.form-hint){color:#b9c8bd!important}
body.messages-body .messages-unread:empty{display:none}
body.messages-body .mail-filters{gap:6px;margin-top:12px}
body.messages-body .mail-filters button{min-height:36px}
body.messages-body :is(input,textarea,select):focus-visible{outline:2px solid #8fb9a0;outline-offset:2px}
/* Bakery uses its own palette, including nested recipe blocks. */
html[data-theme="dark"] body.bakery-body{
--bk-bg:#161c19;--bk-bg-elevated:#202923;--bk-grouped:#263229;
--bk-ink:#edf3ee;--bk-label:#edf3ee;--bk-muted:#bdcdc1;--bk-muted-2:#bdcdc1;--bk-dim:#a9bcae;
--bk-tint:#a3d2b7;--bk-tint-deep:#709e83;--bk-tint-fill:#314b3b;
--bk-separator:#3b4940;--bk-separator-opaque:#4a5c50;--bk-fill:#29382f;--bk-fill-secondary:#263229;--bk-fill-tertiary:#243027;
--bk-shadow:none;--bk-shadow-sm:none;--bk-shadow-lift:none;
}
html[data-theme="dark"] body.bakery-body .topbar{background:transparent!important;box-shadow:none!important}
html[data-theme="dark"] body.bakery-body :is(.recipe-block,.recipe-tabs){background:#263229!important;color:#edf3ee!important}
html[data-theme="dark"] body.bakery-body :is(.recipe-tab.is-active,.btn-primary){background:#3a5948!important;border-color:#6c947b!important}
html[data-theme="dark"] body.bakery-body :is(.lesson-card-number,.lesson-card-badge){background:#263d30!important;color:#edf3ee!important}
html[data-theme="dark"] body.bakery-body :is(.series-card-cover,.lesson-card-cover){background-color:#29382f}
html[data-theme="dark"] body.bakery-body :is(.series-card-desc,.series-card-meta,.lesson-intro,.recipe-hint,.recipe-section-desc){color:#bdcdc1!important}
html[data-theme="dark"] body.bakery-body .player-play{background:transparent!important}
html[data-theme] body.bakery-body :is(.bakery-crumb,.bakery-crumb .bakery-link){background:transparent!important;border:0!important;box-shadow:none!important}
html[data-theme] body.bakery-body :is(.recipe-gallery,.recipe-item,.recipe-item img){background:transparent!important;border:0!important;box-shadow:none!important}
