/* MARGIN. / Unified reader experience + two carefully matched color themes */

/* Theme switch is installed into the existing navigation across all five pages. */
.margin-theme-toggle {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  order: 2;
  border-radius: 50%;
  border: 1px solid rgba(121, 112, 94, .24);
  background: rgba(255, 253, 248, .4);
  color: #554a3e;
  cursor: pointer;
  transition: background .25s ease, transform .25s ease, border-color .25s ease;
}
.margin-theme-toggle:hover { transform: translateY(-2px); border-color: #c65b43; background: rgba(198, 91, 67, .08); }
.margin-theme-toggle:focus-visible,
.margin-dialog button:focus-visible,
.margin-dialog textarea:focus-visible {
  outline: 2px solid #c65b43;
  outline-offset: 3px;
}
.margin-theme-toggle svg {
  width: 19px; height: 19px; fill: none; stroke: currentColor;
  stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round;
}
/* Keep the usual Explore/My Shelf link on the outside edge. */
.site-header > .header-link,
.daily-header > .daily-header-link,
.quiz-header > .quiz-header-link { order: 3; }
@media (max-width: 760px) {
  .margin-theme-toggle { margin-left: auto; order: 1; }
  .site-header > .header-link,
  .daily-header > .daily-header-link,
  .quiz-header > .quiz-header-link { order: 2; }
}

/* Elevated modal with a true click-away backdrop. */
.margin-reader-modal {
  position: fixed; inset: 0; z-index: 10000;
  display: grid; place-items: center;
  padding: clamp(12px, 3vw, 34px);
}
.margin-reader-modal[hidden] { display: none !important; }
.margin-modal-open { overflow: hidden !important; }
.margin-modal-shade {
  position: absolute; inset: 0;
  background: rgba(18, 20, 18, .62);
  -webkit-backdrop-filter: blur(9px);
  backdrop-filter: blur(9px);
  animation: margin-fade-in .23s ease-out;
}
.margin-dialog {
  position: relative;
  display: flex; flex-direction: column;
  background: #faf7f1;
  color: #292923;
  width: min(100%, 940px);
  max-height: min(90dvh, 870px);
  border: 1px solid rgba(255,255,255,.55);
  border-radius: 20px;
  box-shadow: 0 32px 95px rgba(5, 6, 5, .28);
  overflow: hidden;
  animation: margin-pop-in .3s cubic-bezier(.2,.8,.2,1);
}
.margin-dialog-top {
  display: flex; align-items: center; justify-content: space-between;
  flex: 0 0 auto;
  padding: 15px 28px;
  border-bottom: 1px solid #e3dace;
}
.margin-kicker {
  color: #9a694e; font: 700 10px/1.5 Arial, sans-serif;
  letter-spacing: 2px; text-transform: uppercase;
}
.margin-close {
  display: inline-flex; justify-content: center; align-items: center;
  width: 36px; height: 36px;
  padding: 0; border: 1px solid #d5cbbf; border-radius: 50%;
  background: transparent; color: #554b41; font: 26px/1 Arial, sans-serif;
  cursor: pointer; transition: background .2s ease;
}
.margin-close:hover { background: #efe5db; }
.margin-dialog-scroll { overflow-y: auto; overscroll-behavior: contain; }
.margin-dialog-grid { display: grid; grid-template-columns: 34% 66%; }
.margin-dialog-cover {
  background: radial-gradient(circle at 35% 30%, #eeebe2, #dce0d5);
  min-height: 405px; padding: 37px;
  display: grid; place-items: center;
}
.margin-dialog-cover img {
  width: auto; max-width: 100%; max-height: 325px;
  object-fit: contain; box-shadow: 0 19px 36px rgba(26, 28, 22, .18);
}
.margin-dialog-cover img[hidden],
.margin-cover-fallback[hidden] { display: none !important; }
.margin-cover-fallback {
  border: 1px solid #a7ae9e; color: #3f453b;
  font: 26px/1.3 Georgia, serif; text-align: center; padding: 32px 16px;
}
.margin-dialog-main { padding: clamp(24px, 4vw, 44px); display: flex; flex-direction: column; align-items: flex-start; }
.margin-dialog-main h2 { font: 400 clamp(32px, 4vw, 48px)/1.12 Georgia,serif; margin: 12px 0 9px; letter-spacing: -.8px; }
.margin-dialog-author { font: 16px Georgia,serif; color: #758370; margin-bottom: 12px; }
.margin-dialog-rule { height: 2px; width: 52px; background: #c65b43; margin: 14px 0 18px; }
.margin-dialog-main h3 { font: 400 23px Georgia,serif; margin: 0 0 10px; }
.margin-dialog-description { font: 15px/1.72 Georgia,serif; color: #67645c; margin-bottom: 26px; max-width: 470px; }
.margin-action-btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 13px 19px; border: 1px solid #c65b43; border-radius: 6px;
  background: #c65b43; color: #fff;
  font: 700 11px/1.3 Arial,sans-serif; letter-spacing: .7px;
  cursor: pointer; transition: background .22s ease, transform .22s ease;
}
.margin-action-btn:hover { background: #a84935; transform: translateY(-1px); }
.margin-save-btn.is-saved { background: #788771; border-color: #788771; }
.margin-save-btn.is-saved:hover { background: #566a51; }
.margin-journal-block { padding: 30px clamp(24px,4vw,44px) 38px; border-top: 1px solid #e3dace; }
.margin-journal-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; margin-bottom: 25px; }
.margin-journal-heading h3 { font: 400 30px/1.2 Georgia,serif; margin: 8px 0 0; }
.margin-personal-label { text-align: right; font: 600 9px Arial,sans-serif; letter-spacing: 1.2px; color: #7b8976; }
.margin-rating-section h4,
.margin-note-section label { font: 400 20px Georgia,serif; margin-bottom: 10px; display: block; }
.margin-stars { display: flex; align-items: center; gap: 8px; }
.margin-star {
  border: 0; border-radius: 7px; color: #b5aa98;
  background: transparent; padding: 3px; font: 36px/1 Georgia,serif;
  cursor: pointer; transition: color .2s, transform .2s;
}
.margin-star:hover { transform: scale(1.14); color: #c65b43; }
.margin-star.is-filled { color: #c65b43; }
.margin-feedback { font: 12px/1.5 Arial,sans-serif; color: #7b786f; }
.margin-rating-section { margin-bottom: 27px; }
.margin-note-section textarea {
  box-sizing: border-box;
  width: 100%; min-height: 130px; resize: vertical;
  padding: 17px 18px; border-radius: 10px;
  border: 1px solid #d8cfc2; background: #fffcf8; color: #2d2b27;
  font: 14px/1.65 Georgia,serif; box-shadow: none;
}
.margin-note-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 14px; margin-top: 12px; }
.margin-note-actions #margin-note-status { flex: 1 1 160px; }
.margin-text-btn { border: none; background: none; cursor: pointer; color: #856f61; font: 12px Arial,sans-serif; text-decoration: underline; text-underline-offset: 3px; padding: 6px; }
.margin-text-btn:hover { color: #c65b43; }
.margin-detail-open,
.margin-shelf-detail {
  margin-top: 15px; padding: 12px 16px;
  border: 1px solid #bdb5a8; background: transparent; color: #9b4a34;
  border-radius: 4px; font: 700 10px/1.3 Arial,sans-serif;
  letter-spacing: 1px; cursor: pointer;
  transition: background .2s ease, border-color .2s ease;
}
.margin-detail-open:hover, .margin-shelf-detail:hover { background: rgba(198,91,67,.08); border-color: #c65b43; }
.margin-shelf-rating { margin-top: 12px; font: 12px/1.4 Arial,sans-serif; color: #a6503f; }
@keyframes margin-pop-in { from { opacity: 0; transform: translateY(14px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes margin-fade-in { from { opacity: 0; } to { opacity: 1; } }
@media (max-width: 720px) {
  .margin-reader-modal { padding: 8px; }
  .margin-dialog { border-radius: 14px; max-height: 96dvh; }
  .margin-dialog-top { padding: 10px 17px; }
  .margin-dialog-grid { grid-template-columns: 1fr; }
  .margin-dialog-cover { min-height: 190px; padding: 20px; }
  .margin-dialog-cover img { max-height: 182px; }
  .margin-dialog-main { padding: 24px; }
  .margin-journal-heading { align-items: flex-start; flex-direction: column; }
  .margin-journal-heading h3 { font-size: 25px; }
  .margin-journal-block { padding: 25px 23px; }
}
@media (prefers-reduced-motion: reduce) {
  .margin-dialog, .margin-modal-shade { animation: none !important; }
  .margin-theme-toggle, .margin-action-btn, .margin-star { transition: none !important; }
}

/* Dark theme: shared semantic tokens + overrides for existing inline page CSS. */
html[data-theme="dark"] {
  color-scheme: dark;
  --paper: #202520;
  --ink: #efe9de;
  --terracotta: #e3a084;
  --sage: #afc0a7;
  --sand: #39423a;
  --ochre: #e2be84;
  --white: #282e28;
}
html[data-theme="dark"] body,
html[data-theme="dark"] body.quiz-body,
html[data-theme="dark"] body.daily-body,
html[data-theme="dark"] body.shelf-body { background: #202520 !important; color: #efe9de !important; }
html[data-theme="dark"] .site-header,
html[data-theme="dark"] .daily-header,
html[data-theme="dark"] .quiz-header,
html[data-theme="dark"] .shelf-header {
  background: rgba(31, 37, 32, .83) !important;
  border-bottom-color: rgba(238, 230, 214, .14) !important;
  box-shadow: 0 5px 24px rgba(0,0,0,.13) !important;
}
html[data-theme="dark"] .site-header .logo,
html[data-theme="dark"] .daily-header .daily-logo,
html[data-theme="dark"] .quiz-header .quiz-logo,
html[data-theme="dark"] .shelf-header .shelf-logo { color: #f2e9dc !important; }
html[data-theme="dark"] .site-header .main-nav a,
html[data-theme="dark"] .daily-header .daily-nav a,
html[data-theme="dark"] .quiz-header .quiz-nav a,
html[data-theme="dark"] .shelf-header .shelf-nav a { color: #d1cbbb !important; }
html[data-theme="dark"] .site-header .main-nav a:hover,
html[data-theme="dark"] .site-header .main-nav a.active,
html[data-theme="dark"] .daily-header .daily-nav a:hover,
html[data-theme="dark"] .daily-header .daily-nav a.active,
html[data-theme="dark"] .quiz-header .quiz-nav a:hover,
html[data-theme="dark"] .quiz-header .quiz-nav a.active,
html[data-theme="dark"] .shelf-header .shelf-nav a:hover,
html[data-theme="dark"] .shelf-header .shelf-nav a.active { color: #e3a084 !important; }
html[data-theme="dark"] .site-header .header-link,
html[data-theme="dark"] .daily-header .daily-header-link,
html[data-theme="dark"] .quiz-header .quiz-header-link { color: #e8dcca !important; }
html[data-theme="dark"] .margin-theme-toggle { background: #354035; color: #f1debf; border-color: #566251; }

html[data-theme="dark"] .mood-section,
html[data-theme="dark"] .book-collection,
html[data-theme="dark"] .daily-section,
html[data-theme="dark"] .editorial-section,
html[data-theme="dark"] .discover-hero,
html[data-theme="dark"] .discover-controls,
html[data-theme="dark"] .discover-categories { background: #252b25 !important; color: #efe9de !important; }
html[data-theme="dark"] .mood-card,
html[data-theme="dark"] .quiz-panel,
html[data-theme="dark"] .quiz-option,
html[data-theme="dark"] .quiz-result-card,
html[data-theme="dark"] .daily-feature,
html[data-theme="dark"] .shelf-card,
html[data-theme="dark"] .shelf-stat-card,
html[data-theme="dark"] .shelf-empty,
html[data-theme="dark"] .daily-bottom,
html[data-theme="dark"] .sort-box select,
html[data-theme="dark"] .shelf-search { background: #30382f !important; color: #efe9de !important; border-color: #4b5849 !important; }
html[data-theme="dark"] .mood-card:hover,
html[data-theme="dark"] .quiz-option.selected { background: #3d4b3e !important; border-color: #c88f75 !important; }
html[data-theme="dark"] .daily-book-cover,
html[data-theme="dark"] .book-cover,
html[data-theme="dark"] .quiz-result-cover,
html[data-theme="dark"] .shelf-cover { background: radial-gradient(circle at 40% 20%,#465345,#303b32) !important; }
html[data-theme="dark"] .daily-banner { background: #131a16 !important; }
html[data-theme="dark"] .button-secondary,
html[data-theme="dark"] .category-btn,
html[data-theme="dark"] .daily-btn:not(.primary),
html[data-theme="dark"] .quiz-button:not(.primary),
html[data-theme="dark"] .shelf-remove,
html[data-theme="dark"] .shelf-status,
html[data-theme="dark"] .margin-shelf-detail,
html[data-theme="dark"] .margin-detail-open { color: #f0e8dc !important; background: #30392f !important; border-color: #62705d !important; }
html[data-theme="dark"] .category-btn.active,
html[data-theme="dark"] .category-btn:hover { background: #cd846b !important; border-color: #cd846b !important; color: #171c17 !important; }
html[data-theme="dark"] .book-info h3,
html[data-theme="dark"] .quiz-option strong,
html[data-theme="dark"] .quiz-question,
html[data-theme="dark"] .quiz-hero h1,
html[data-theme="dark"] .shelf-heading,
html[data-theme="dark"] .shelf-section-title h2,
html[data-theme="dark"] .shelf-card-info h3,
html[data-theme="dark"] .shelf-empty h2,
html[data-theme="dark"] .shelf-stat-card strong,
html[data-theme="dark"] .daily-book-title,
html[data-theme="dark"] .daily-heading,
html[data-theme="dark"] .daily-bottom h2 { color: #f1e9dd !important; }
html[data-theme="dark"] .shelf-count span,
html[data-theme="dark"] .shelf-count span[style],
html[data-theme="dark"] .shelf-placeholder,
html[data-theme="dark"] .quiz-cover-placeholder { color: #eadfcd !important; }
html[data-theme="dark"] .hero-description,
html[data-theme="dark"] .mood-card p,
html[data-theme="dark"] .editorial-copy > p,
html[data-theme="dark"] .discover-hero > p:not(.eyebrow),
html[data-theme="dark"] .book-description,
html[data-theme="dark"] .book-author,
html[data-theme="dark"] .quiz-hero p,
html[data-theme="dark"] .quiz-side-note,
html[data-theme="dark"] .quiz-question-desc,
html[data-theme="dark"] .quiz-option small,
html[data-theme="dark"] .quiz-results-intro,
html[data-theme="dark"] .quiz-result-info p,
html[data-theme="dark"] .daily-intro,
html[data-theme="dark"] .daily-description,
html[data-theme="dark"] .daily-note,
html[data-theme="dark"] .daily-bottom p,
html[data-theme="dark"] .shelf-intro,
html[data-theme="dark"] .shelf-description,
html[data-theme="dark"] .shelf-empty p { color: #c5c6b6 !important; }
html[data-theme="dark"] .search-box input,
html[data-theme="dark"] .shelf-search { color: #f1e9dd !important; }
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder { color: #9ca89c !important; }
html[data-theme="dark"] .site-footer,
html[data-theme="dark"] .daily-footer,
html[data-theme="dark"] .shelf-footer,
html[data-theme="dark"] .quiz-footer { background: #202520 !important; border-top-color: #4b5849 !important; color: #c5c6b6 !important; }
html[data-theme="dark"] .site-footer .logo,
html[data-theme="dark"] .shelf-footer .shelf-logo,
html[data-theme="dark"] .daily-footer .daily-logo,
html[data-theme="dark"] .quiz-footer .quiz-logo { color: #efe9de !important; }
html[data-theme="dark"] .footer-links a { color: #d2cebf !important; }

/* Always legible, contained in a single modal theme. */
html[data-theme="dark"] .margin-dialog { background: #2b332c; color: #f1e9dd; border-color: #53604e; }
html[data-theme="dark"] .margin-dialog-top,
html[data-theme="dark"] .margin-journal-block { border-color: #465144; }
html[data-theme="dark"] .margin-dialog-cover { background: radial-gradient(circle,#465343,#303b31); }
html[data-theme="dark"] .margin-cover-fallback { color: #f2e6d6; border-color: #849384; }
html[data-theme="dark"] .margin-dialog-author { color: #bacbab; }
html[data-theme="dark"] .margin-dialog-description,
html[data-theme="dark"] .margin-feedback { color: #c9c9bb; }
html[data-theme="dark"] .margin-close { background: #384138; color: #efe9dc; border-color: #5c6958; }
html[data-theme="dark"] .margin-note-section textarea { background: #222a23; color: #efe9de; border-color: #5b6858; }
html[data-theme="dark"] .margin-star { color: #a09a88; }
html[data-theme="dark"] .margin-star.is-filled,
html[data-theme="dark"] .margin-star:hover { color: #e3a084; }
html[data-theme="dark"] .margin-text-btn { color: #e8b19d; }

/* Make the book covers recognizable entry points, without altering card layout. */
.margin-quiz-open, .margin-shelf-cover-open { cursor: pointer; }
.margin-quiz-open:focus-visible, .margin-shelf-cover-open:focus-visible { outline: 2px solid #c65b43; outline-offset: 3px; }
html[data-theme="dark"] .margin-shelf-rating { color: #e3a084 !important; }
html[data-theme="dark"] .shelf-author,
html[data-theme="dark"] .quiz-result-author,
html[data-theme="dark"] .daily-author { color: #b1c0ad !important; }
