.gift {
  --paper: #f3eee3;
  --sheet: #fcf8ee;
  --ink: #25372f;
  --muted: #5c675e;
  --line: #d9d0bf;
  --lake: #364c44;
  --brass: #876340;
  --edge: #d5c6ae;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
}

.gift .wrap,
.gift .nav-inner,
.gift .foot-inner {
  width: min(1180px, calc(100% - 72px));
}

.gift .nav-inner { min-height: 66px; }
.gift .account-link { min-height: 44px; }
.gift .primary { background: #314a3e; }
.gift .primary:hover { background: #405e50; }
.gift .secondary { border-color: var(--edge); }
.gift .secondary:hover { background: var(--sheet); }
.gift .small-btn,
.gift .link-button,
.gift .backlink {
  min-height: 44px;
}
.gift .backlink:hover { color: var(--ink); }
.gift .action-row { align-items: center; }
.gift .form-error:empty { display: none; }

.gift-mast {
  padding: 122px 0 39px;
  background:
    linear-gradient(90deg, #101e2b 0%, #101e2b 39%, #101e2b30 70%, #101e2b00),
    linear-gradient(0deg, #111f2a72, transparent 60%, #101e2b80),
    url('/assets/moon-lake.webp') right 17% / auto clamp(386px, 41vw, 675px) no-repeat,
    #101e2b;
}
.gift-mast .mast-line { width: 37px; margin-bottom: 9px; }
.gift-mast h1 {
  margin: 0;
  font-size: clamp(40px, 4.1vw, 59px);
  letter-spacing: .075em;
  line-height: 1.25;
}

.shelf-switcher {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--line);
}
.shelf-switcher .tabs {
  align-items: stretch;
  gap: clamp(13px, 3vw, 32px);
  margin: 0 0 -1px;
  border: 0;
}
.shelf-switcher .tabs a {
  display: grid;
  align-items: center;
  min-height: 58px;
  padding: 0;
  white-space: nowrap;
}
.shelf-switcher .tabs a[aria-current] { border-color: var(--brass); }
.shelf-switcher:has(#web-search-tab:not([hidden])) { flex-wrap: wrap; row-gap: 0; }
.web-search-view {
  width: min(100%, 760px);
  margin: 0 auto;
  padding-block: 16px 36px;
}
.gift.search-mode .gift-mast { display: none; }
.gift.search-mode #site-head { position: relative; background: #101e2b; }
.web-search-lead p { margin: 6px 0 20px; color: var(--muted); }
.web-search-form {
  padding: clamp(14px, 3vw, 24px);
  border: 1px solid var(--line);
  background: var(--sheet);
}
.web-search-form label { display: grid; gap: 5px; min-width: 0; }
.web-search-form label span { font-size: 14px; color: var(--lake); }
.web-search-form input,
.web-search-form select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--edge);
  border-radius: 4px;
  background: transparent;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
}
.web-search-term input { min-height: 48px; }
.web-search-options {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto;
  align-items: end;
  gap: 12px;
  margin-top: 12px;
}
.web-search-options button { min-height: 44px; justify-content: center; }
.web-search-refine { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; margin-top: 8px; }
.web-search-form .exact-choice { display: flex; align-items: center; gap: 8px; min-height: 44px; font-size: 14px; color: var(--lake); width: fit-content; }
.web-search-form .exact-choice input { width: 18px; height: 18px; min-height: 0; margin: 0; accent-color: var(--lake); }
#web-search-clues { min-height: 44px; padding-inline: 12px; font-size: 14px; }
.web-search-status { margin-block: 16px 12px; color: var(--muted); font-size: 14px; }
.web-search-status:empty { display: none; }
.web-book-list { margin: 0; padding: 0; list-style: none; }
.web-book-result { padding: 15px 0; border-top: 1px solid var(--line); }
.web-book-result h3 { margin: 3px 0; font-size: clamp(18px, 2.6vw, 22px); overflow-wrap: anywhere; }
.web-book-result h3 a { color: var(--lake); }
.web-book-result h3 a:hover,
.web-book-links a:hover { text-decoration: underline; text-underline-offset: 3px; }
.web-book-source { margin: 0; display: flex; flex-wrap: wrap; gap: 5px 10px; color: var(--muted); font-size: 13px; }
.web-book-source span { overflow-wrap: anywhere; }
.web-book-match { margin: 4px 0 0; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.web-book-match span { margin-inline-start: 6px; color: var(--lake); }
.web-book-detail {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  margin: 4px 0 0;
  line-height: 1.55;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.web-book-links { margin: 10px 0 16px; padding-top: 12px; border-top: 1px solid var(--line); }
.web-book-links summary { min-height: 44px; align-content: center; color: var(--lake); cursor: pointer; }
.web-book-links ul { display: flex; flex-wrap: wrap; gap: 0 16px; list-style: none; margin: 0; padding: 0; }
.web-book-links a { display: inline-flex; align-items: center; min-height: 44px; color: var(--lake); }
.web-book-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0 16px; }
.web-book-txt { display: inline-flex; align-items: center; min-height: 44px; color: var(--lake); font-size: 14px; text-decoration: underline; text-underline-offset: 3px; }
.web-book-block { min-height: 44px; padding-inline: 0 8px; font-size: 13px; color: var(--muted); }
.web-book-block:hover { text-decoration: underline; text-underline-offset: 3px; }
#search-blocks { display: block; margin-top: 8px; }
.link-address { min-width: 0; overflow-wrap: anywhere; color: var(--muted); font-size: 14px; }
.blocked-links { margin-top: 16px; }
.blocked-links ul { list-style: none; padding: 0; margin: 0; }
.blocked-links li { display: flex; gap: 10px; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); }
.blocked-links button { flex: none; }
.desk-account-actions { margin-top: 16px; }
.desk-account-actions #logout { margin-top: 0; }

@media (max-width: 540px) {
  .web-search-view { padding-top: 9px; }
  .web-search-options { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
  .web-search-options button { grid-column: 1 / -1; }
}

.private-shelf {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 14px 0 42px;
}
.shelf-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}
.private-shelf .button { min-height: 44px; }
.shelf-signed-out > p, .shelf-empty { color: var(--muted); }
.shelf-signed-out .action-row { margin-top: 16px; }
.shelf-search.searchbox {
  width: min(100%, 345px);
  min-height: 44px;
  margin: 0 0 14px;
  gap: 9px;
  padding: 6px 12px;
  border-color: var(--edge);
}
.shelf-search.searchbox[hidden] { display: none; }
.shelf-search input { width: 100%; min-width: 0; font-size: 16px; }
.shelf-list { margin: 0; padding: 0; list-style: none; }
.shelf-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(9px, 2vw, 16px);
  padding: 13px 0;
  border-top: 1px solid var(--line);
}
.shelf-row:last-child { border-bottom: 1px solid var(--line); }
.shelf-book-mark {
  display: grid;
  place-items: center;
  width: clamp(30px, 8vw, 40px);
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 4px 6px 6px 4px;
  background: var(--sheet);
  color: var(--brass);
}
.shelf-book-title h3 { margin: 0; font-size: clamp(18px, 3vw, 23px); line-height: 1.37; }
.shelf-book-title h3 a { display: block; overflow-wrap: anywhere; }
.shelf-book-title h3 a:hover { text-decoration: underline; text-underline-offset: 4px; }
.shelf-book-title p { margin: 3px 0 0; font-size: 13px; color: var(--muted); }
.shelf-download { padding-inline: clamp(9px, 2vw, 15px); gap: 5px; font-size: 14px; white-space: nowrap; }
.shelf-empty { padding: 17px 0 0; border-top: 1px solid var(--line); }
@media (max-width: 560px) {
  /* Phones: the title gets the full row; format, size and the download button share the line below. */
  .shelf-row {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "mark title title" "mark meta download";
    row-gap: 0;
    padding: 12px 0;
  }
  .shelf-book-title { display: contents; }
  .shelf-book-mark { grid-area: mark; align-self: start; margin-top: 1px; }
  .shelf-book-title h3 { grid-area: title; font-size: 18px; line-height: 1.45; }
  .shelf-book-title p { grid-area: meta; margin: 0; }
  .private-shelf .shelf-download { grid-area: download; min-height: 40px; margin-top: 4px; }
}
.resume-reading {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 6px 12px;
  margin-bottom: 14px;
  background: #ebe4d6;
  border: 1px solid var(--line);
  border-left-color: var(--brass);
}
.resume-reading:hover { background: #e8dfce; }
.resume-label { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.resume-reading strong { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.shelf-import input[type=file] {
  width: 100%;
  min-height: 44px;
  color: var(--muted);
}
.shelf-import input[type=file]::file-selector-button {
  min-height: 34px;
  margin-right: 8px;
  padding-inline: 10px;
  border: 0;
  background: #eae4d7;
  color: var(--ink);
  font: inherit;
}
#shelf-import-button { white-space: nowrap; }
#shelf-import #import-progress:empty { display: none; }

.desk-view,
.studio-view {
  max-width: 760px;
  margin-inline: auto;
}
.desk-view .app-title { letter-spacing: .025em; }
.desk-view .view-top { margin-bottom: 15px; }
.writing-paths {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 12px 0 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--sheet);
}
.writing-path {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 72px;
  padding: 12px;
  color: var(--ink);
  text-align: left;
}
.writing-path + .writing-path { border-inline-start: 1px solid var(--line); }
.writing-path:hover { background: var(--paper); }
.writing-path:focus-visible { outline-offset: -4px; }
.writing-path .icon { color: var(--lake); }
.writing-path strong { display: block; font: 650 19px/1.35 var(--serif); }
.writing-path small { display: block; margin-top: 3px; font: 14px/1.45 var(--sans); color: var(--muted); }
.continuation-note { margin: 2px 0 16px; color: var(--muted); }
.credit-card {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 9px 18px;
  margin-bottom: 14px;
  padding: 14px clamp(13px, 3vw, 22px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--sheet);
}
.credit-card h3 { margin: 0; font-size: 15px; color: var(--lake); }
.credit-card p { margin: 2px 0 0; }
.credit-card strong { font-variant-numeric: tabular-nums; font-size: 25px; line-height: 1.2; }
.credit-actions { display: flex; gap: 7px; flex-wrap: wrap; }
.credit-actions .button { min-height: 44px; }
.credit-entries { list-style: none; padding: 0; margin: 12px 0 0; }
.credit-entries li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.credit-entries li span:last-child { flex-shrink: 0; font-variant-numeric: tabular-nums; }
.desk-view .desk-item { padding: 14px 4px; }
.desk-view .desk-item h3 { overflow-wrap: anywhere; }
.desk-view .desk-account-actions { margin-top: 16px; }
.desk-account-actions .link-button { min-height: 44px; }
.desk-view.empty { padding-top: 4px; }

.gift.reader-mode .shelf-switcher { display: none; }
.gift.reader-mode #site-head { background: #101e2b; }
.gift.reader-mode .app-wrap { padding-top: 11px; }
.gift .editor-toolbar label {
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
}
.gift .select-chapter { border-color: var(--edge); }

.studio-view .work-note {
  margin: 14px 0 0;
  border-block: 1px solid var(--line);
}
.studio-view .work-note summary {
  display: list-item;
  align-content: center;
  min-height: 44px;
  color: var(--lake);
  cursor: pointer;
}
.studio-view .work-note p {
  padding-bottom: 10px;
  font-size: 15px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.work-note .button { margin-block: 2px 13px; }
.txt-import { display: grid; gap: .45rem; padding-bottom: .8rem; border-bottom: 1px solid var(--line); }
.txt-import .hint { margin: 0; }
.txt-file-row { display: flex; flex-wrap: wrap; align-items: center; gap: .15rem .7rem; }
.txt-file-row span { max-width: 100%; overflow-wrap: anywhere; font-size: .875rem; }
/* The bar sticks to the dialog's padding edge, so it also covers the padding strip below it. */
.txt-book-form .form-actions {
  position: sticky;
  bottom: calc(-1 * var(--dialog-pad, 0px));
  display: flex;
  margin-bottom: calc(-1 * var(--dialog-pad, 0px));
  padding: .65rem 0 var(--dialog-pad, 0px);
  background: var(--sheet);
  border-top: 1px solid var(--line);
}
.txt-book-form .form-error:empty { display: none; }
.form fieldset#paste-opening { border: 0; padding: 0; margin: 0; min-inline-size: 0; }
#paste-opening:not([hidden]) { display: grid; gap: 1rem; }
.evidence-form { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; }
.evidence-form input { flex: 1 1 12rem; min-width: 0; min-height: 44px; font: inherit; padding: .5rem .65rem; color: inherit; background: var(--sheet); border: 1px solid var(--line); border-radius: 5px; }
.story-evidence .evidence-form .button { margin: 0; }
.evidence-results article { padding-top: .65rem; border-top: 1px solid var(--line); }
.evidence-results h3 { font-size: 1rem; margin: 0 0 .4rem; }
.evidence-results p { white-space: pre-wrap; overflow-wrap: anywhere; }
.evidence-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.9; }
.story-facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 12px; margin: 0 0 12px; font-size: 14px; }
.story-facts dt { color: var(--muted); }
.story-facts dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.studio-view .editor-toolbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  justify-content: start;
}
.studio-view .select-chapter {
  width: 100%;
  min-width: 0;
  text-overflow: ellipsis;
}
.studio-view .edit-panel {
  gap: 12px;
  padding: clamp(13px, 3vw, 25px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--sheet);
}
.studio-view .edit-input {
  border-color: var(--line);
  background: #fffdf6;
}
.studio-view .edit-panel textarea { min-height: max(260px, 43svh); }
.studio-view .save-row { flex-wrap: wrap; }
.studio-view .save-row .button { flex: none; }
#chapter-review { scroll-margin-top: 18px; }
#chapter-review ol, #chapter-review ul { padding-inline-start: 1.5em; }
#chapter-review li + li { margin-top: 1em; }
#chapter-review p { overflow-wrap: anywhere; }
#chapter-review textarea { margin-top: 12px; line-height: 1.8; }
.studio-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-top: 2px;
}
.studio-ai { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 6px 12px; align-items: center; margin-top: 15px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 6px; background: var(--sheet); }
.studio-ai { scroll-margin-top: 12px; }
.studio-ai h2 { font-size: 18px; }
.studio-ai .studio-state { grid-column: 1 / -1; margin-top: 2px; }
.studio-ai .button:disabled, .work-note .button:disabled { opacity: .55; }

.gift .ui-dialog {
  --dialog-pad: clamp(17px, 5vw, 28px);
  border: 1px solid var(--line);
  padding: var(--dialog-pad);
}
.gift .ui-dialog .icon-button { width: 44px; height: 44px; }

@media (max-width: 720px) {
  .gift .wrap,
  .gift .nav-inner,
  .gift .foot-inner {
    width: calc(100% - 36px);
  }
  .gift .nav-inner { gap: 14px; min-height: 57px; }
  .gift .nav-inner nav { gap: 12px; }
  .gift-mast {
    padding: 95px 0 30px;
    background-image:
      linear-gradient(90deg, #101e2b 0%, #101e2bcc 26%, #101e2b20 66%, #101e2b00),
      linear-gradient(0deg, #111f2a72, transparent 60%, #101e2b80),
      url('/assets/moon-lake.webp');
    background-position: center, center, 82% 10%;
    background-size: auto, auto, auto 340px;
  }
  .gift-mast h1 { font-size: clamp(30px, 8.2vw, 44px); }
  .gift-mast .mast-line { margin-bottom: 7px; }
  .shelf-switcher { margin-bottom: 14px; }
  .shelf-switcher .tabs a { min-height: 52px; font-size: 15px; }
  .private-shelf { padding-top: 9px; }
  .gift.reader-mode .app-wrap { padding-top: 7px; }
  .writing-paths { grid-template-columns: 1fr; }
  .writing-path { min-height: 63px; gap: 12px; padding: 8px 13px; }
  .writing-path + .writing-path { border-inline-start: 0; border-block-start: 1px solid var(--line); }
  .studio-view .edit-panel textarea { min-height: clamp(228px, 35svh, 330px); }
}

@media (max-width: 560px) {
  .gift .nav-inner nav a[aria-current="page"] { display: none; }
  .gift .account-link { min-width: 44px; padding-inline: 9px; font-size: 13px; }
  .gift .account-link span { display: block; max-width: 4em; }
  .gift .brand { gap: 6px; font-size: 19px; }
  .gift-mast { background-position: center, center, 66% 10%; }
}

@media (max-width: 355px) {
  .gift .nav-inner { gap: 9px; }
  .gift .account-link span { display: none; }
  #begin { padding-inline: 5px; }
  #begin .icon { display: none; }
  .studio-view .save-row { gap: 7px; }
}

/* Touch screens keep :hover after a tap, so buttons and rows hold their resting look there. */
@media (hover: none) {
  .gift .primary:hover { background: #314a3e; }
  .gift .secondary:hover,
  .gift .icon-button:hover,
  .writing-path:hover { background: transparent; }
  .resume-reading:hover { background: #ebe4d6; }
  .shelf-book-title h3 a:hover { text-decoration: none; }
}

/* Chapter save row: word count on the left, both actions together on the right. */
.studio-view .save-row #review-chapter { margin-left: auto; }

/* Story notes use the same thin chevron as the rest of the site instead of the browser triangle. */
.studio-view .work-note summary {
  display: flex;
  align-items: center;
  gap: 10px;
  list-style: none;
}
.studio-view .work-note summary::-webkit-details-marker { display: none; }
.studio-view .work-note summary::before {
  content: "";
  flex: none;
  width: 6px;
  height: 6px;
  margin-inline: 2px 1px;
  border: solid currentColor;
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(-45deg);
  transition: transform .2s;
}
.studio-view .work-note[open] summary::before { transform: translateY(-2px) rotate(45deg); }

@media (max-width: 560px) {
  /* Dialog actions on phones: one full-width primary button within thumb reach. */
  .gift .ui-dialog .form > .button[type="submit"],
  .gift .ui-dialog .form-actions .button { width: 100%; justify-self: stretch; }
}

@media (prefers-reduced-motion: reduce) {
  .gift a,
  .gift button { transition: none; }
}
