/* Shared by the app and standalone story reader. Keep foreground accents separate
   from filled button colours: a light link colour is not a readable button fill. */
:root {
  color-scheme: light;
  --page: #f5f1e8;
  --surface: #ffffff;
  --raised: #e8e4dc;
  --ink: #4a5568;
  --muted: #596775;
  --line: #b6bdbb;
  --link: #256668;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #181d21;
  --surface: #222a30;
  --raised: #303b43;
  --ink: #e5e9ed;
  --muted: #b3bec8;
  --line: #667783;
  --link: #9bd9d6;
  --color-warm-cream: var(--page);
  --color-stone-gray: var(--raised);
  --color-soft-slate: var(--ink);
  --color-deep-teal: #236466;
  --color-terracotta: #904422;
  --color-sage-green: #355f46;
  --color-muted-rose: #873f4a;
  --color-dusty-blue: #385d7d;
  --color-golden-amber: #f0bd65;
}
body { background-color: var(--page); color: var(--ink); }
.theme-picker { display: inline-flex; align-items: center; gap: .5rem; font: 500 .875rem/1.5 system-ui, sans-serif; color: var(--ink); }
.theme-picker select { background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: .5rem; padding: .3rem .5rem; }
.theme-picker select:focus-visible { outline: 2px solid var(--link); outline-offset: 3px; }
html[data-theme="dark"] :focus-visible { outline-color: var(--link); }
html[data-theme="dark"] ::selection { background: #9bd9d6; color: #181d21; }
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder { color: var(--muted); opacity: 1; }
html[data-theme="dark"] :is(input, textarea, select) { accent-color: #9bd9d6; }

/* Hand-authored workspaces and reader pages do not use Tailwind. */
html[data-theme="dark"] :is(.idea-workspace, .publishing, .reader-page) { color: var(--ink); }
html[data-theme="dark"] .reader-page { background: var(--page); }
html[data-theme="dark"] :is(.idea-workspace h1, .idea-workspace a, .idea-workspace summary, .reader-page a, .publishing a, .publishing-secondary) { color: var(--link); }
html[data-theme="dark"] :is(.idea-workspace section, .idea-workspace article, .publishing-panel) { background: var(--surface); border-color: var(--line); }
html[data-theme="dark"] :is(.idea-workspace input:not([type=submit]), .idea-workspace textarea, .idea-workspace select, .publication-form input:not([type=submit]), .publication-form textarea) { background: var(--surface); color: var(--ink); border-color: var(--line); }
html[data-theme="dark"] :is(.idea-workspace .muted, .publishing-eyebrow, .reading-byline) { color: var(--muted); }
html[data-theme="dark"] :is(.idea-workspace .primary, .idea-workspace button, .idea-workspace input[type=submit], .publishing-button, .publishing a.publishing-button) { background: #236466; color: #fff; }
html[data-theme="dark"] .publishing-button:disabled { background: var(--raised); color: var(--muted); }
html[data-theme="dark"] .idea-workspace .errors { background: #442a29; }
html[data-theme="dark"] .idea-workspace .badge { background: #293e34; }
html[data-theme="dark"] :is(.reader-header, .publication-chapter, .chapter-list li, .scene-break, .reader-pagination, .publishing-secondary) { border-color: var(--line); }

/* Explicit utility overrides cover templates, helpers and dynamically inserted UI. */
html[data-theme="dark"] :is(.bg-blue-100, .bg-blue-200, .bg-blue-50) { background-color: #29394b; }
html[data-theme="dark"] :is(.bg-gray-200, .bg-gray-50) { background-color: var(--raised); }
html[data-theme="dark"] :is(.bg-green-100, .bg-green-200, .bg-green-50) { background-color: #293e34; }
html[data-theme="dark"] :is(.bg-pink-100, .bg-pink-200, .bg-pink-50) { background-color: #442d38; }
html[data-theme="dark"] :is(.bg-purple-100, .bg-purple-200, .bg-purple-50) { background-color: #39304a; }
html[data-theme="dark"] :is(.bg-warm-white, .bg-white, .bg-white\/80, .bg-white\/85, .hover\:bg-white:hover) { background-color: var(--surface); }
html[data-theme="dark"] :is(.bg-yellow-100, .bg-yellow-200, .bg-yellow-50) { background-color: #433923; }
html[data-theme="dark"] :is(.border-soft-slate\/10, .border-soft-slate\/30, .border-stone-gray, .border-stone-gray\/10, .border-stone-gray\/20, .border-stone-gray\/30, .border-stone-gray\/70, .divide-stone-gray > :not(:last-child), .divide-stone-gray\/70 > :not(:last-child), .divide-stone-gray\/80 > :not(:last-child)) { border-color: var(--line); }
html[data-theme="dark"] :is(.hover\:text-deep-teal:hover, .hover\:text-deep-teal\/80:hover, .text-deep-teal, .text-deep-teal\/60, .text-deep-teal\/70) { color: #9bd9d6; }
html[data-theme="dark"] :is(.hover\:text-golden-amber:hover, .hover\:text-golden-amber\/85:hover, .text-amber-600, .text-golden-amber, .text-yellow-800) { color: #f0cd8b; }
html[data-theme="dark"] :is(.hover\:text-sage-green:hover, .text-sage-green) { color: #b4dbbc; }
html[data-theme="dark"] :is(.hover\:text-soft-slate:hover, .text-deep-slate, .text-soft-slate) { color: var(--ink); }
html[data-theme="dark"] :is(.hover\:text-soft-slate\/80:hover, .text-gray-400, .text-soft-slate\/40, .text-soft-slate\/50, .text-soft-slate\/60, .text-soft-slate\/70, .text-soft-slate\/75, .text-soft-slate\/80) { color: var(--muted); }
html[data-theme="dark"] :is(.hover\:text-terracotta:hover, .hover\:text-terracotta\/80:hover, .text-terracotta) { color: #f6b48f; }
html[data-theme="dark"] :is(.text-blue-700, .text-dusty-blue) { color: #b5d5f2; }
html[data-theme="dark"] :is(.text-deep-forest) { color: #a9d9b5; }
html[data-theme="dark"] :is(.text-muted-rose) { color: #f5b2be; }

/* Amber actions retain dark ink, including nested labels and hover states. */
html[data-theme="dark"] :is(.bg-golden-amber, .bg-golden-amber\/90) { color: #233039; }
html[data-theme="dark"] :is(.bg-golden-amber, .bg-golden-amber\/90) :is(.text-deep-teal, .text-white) { color: #233039; }
html[data-theme="dark"] .bg-golden-amber.text-deep-teal { color: #233039; }
html[data-theme="dark"] .sortable-ghost { background-color: #303b43; border-color: #9bd9d6; }
/* Keyboard focus must remain distinct from the dark button/surface palette. */
html[data-theme="dark"] :is(input, textarea, select, button, a):focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 3px;
}
html[data-theme="dark"] .focus\:border-deep-teal:focus { border-color: var(--link); }
html[data-theme="dark"] .focus\:ring-deep-teal:focus { --tw-ring-color: var(--link); }
/* Locked achievements and expired/redeemed codes still contain readable content. */
html[data-theme="dark"] :is(.bg-white.opacity-60, tr.opacity-60, code.opacity-50) { opacity: 1; }
html[data-theme="dark"] .text-purple-400 { color: #d8b4fe; }
html[data-theme="dark"] .text-yellow-400 { color: #f0cd8b; }

/* Compact header control; pages without navigation retain a footer preference. */
.theme-menu { position: relative; float: right; order: 1; flex: 0 0 auto; margin-left: .5rem; }
.theme-menu > summary { display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; list-style: none; cursor: pointer; border: 1px solid currentColor; border-radius: .5rem; }
.theme-menu > summary::-webkit-details-marker { display: none; }
.theme-menu > summary:focus-visible { outline: 2px solid var(--link); outline-offset: 3px; }
.theme-menu-panel { position: absolute; right: 0; top: calc(100% + .5rem); z-index: 60; padding: .75rem; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: .5rem; box-shadow: 0 6px 24px #0003; }
.theme-menu-panel .theme-picker { white-space: nowrap; }
header[data-controller="mobile-menu"] .theme-menu { margin-left: auto; }
header[data-controller="mobile-menu"] > div > button { order: 2; margin-left: .75rem; }
