/* Homepage, 我的片单 and /s/ search pages. Paper, ink and warm orange; lines, type and
   posters carry the hierarchy instead of cards, shadows or gradients. */
:root {
  --bg: #f3efe8; --panel: #fffdf8; --ink: #17151a; --muted: #6c6670; --soft-ink: #4d484e;
  --line: rgba(23, 21, 26, .17); --field: #a6a09a; --accent: #cb5a2b; --action: #a74119;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.65 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif; }
button, input { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-underline-offset: 4px; }
a, button, input, summary { touch-action: manipulation; }
[hidden] { display: none !important; }
h1, h2, h3, p, dl, dd { margin: 0; }
h1, h2, h3 { line-height: 1.35; }
p, h1, h2, h3, strong, dd { overflow-wrap: anywhere; }
img { display: block; max-width: 100%; }
:where(a, button, input, summary, [tabindex]):focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
:where(h1, main)[tabindex="-1"]:focus { outline: none; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip-link { position: fixed; top: -80px; left: 16px; z-index: 30; padding: 10px 14px; background: var(--panel); border: 1px solid var(--ink); }
.skip-link:focus { top: 8px; }
.page-shell { width: min(1184px, calc(100% - 64px)); margin: 0 auto; }

/* Masthead: brand, one search field, 我的片单 */
.masthead { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 48px; padding: 18px 0 16px; border-bottom: 1px solid var(--ink); }
.brand { font-size: 28px; font-weight: 800; letter-spacing: -1px; text-decoration: none; white-space: nowrap; }
.brand span { color: var(--action); font-size: 16px; font-weight: 500; letter-spacing: 0; }
.search-form { display: flex; min-width: 0; min-height: 48px; border: 1px solid var(--field); border-radius: 4px; background: var(--panel); }
.search-form:focus-within { border-color: var(--ink); }
.search-form input { flex: 1; min-width: 0; width: 100%; padding: 10px 15px; border: 0; background: none; border-radius: 3px 0 0 3px; }
.search-form input:focus-visible { outline: none; }
.search-form input::-webkit-search-cancel-button { cursor: pointer; filter: grayscale(1); }
.search-form button { flex-shrink: 0; min-height: 46px; padding: 0 22px; background: var(--action); color: var(--panel); font-weight: 600; border-radius: 0 3px 3px 0; }
.search-form button:hover { background: #8f3713; }
.library-link { min-height: 44px; display: inline-flex; align-items: center; gap: 6px; font-weight: 600; text-decoration: none; white-space: nowrap; }
.library-link[aria-current="page"] { box-shadow: inset 0 -2px var(--accent); }
.saved-count { color: var(--action); font-size: 13px; }
.storage-warning, .notice { margin: 14px 0; padding: 6px 12px; border-left: 2px solid var(--accent); color: var(--soft-ink); font-size: 13px; }
.notice:has(.retry-button, .retry-link) { padding-block: 0; }
.notice .retry-button, .notice .retry-link { display: inline-flex; align-items: center; min-height: 40px; margin-left: 6px; color: var(--action); font-weight: 600; vertical-align: middle; }

/* Home */
.recent-summary { display: flex; align-items: center; gap: 18px; min-height: 52px; border-bottom: 1px solid var(--line); font-size: 13px; }
.summary-label, .summary-source { color: var(--muted); white-space: nowrap; }
.summary-title { min-width: 0; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.recent-summary a { min-height: 44px; display: inline-flex; align-items: center; flex-shrink: 0; color: var(--action); text-decoration: none; }
.recent-summary a:hover { text-decoration: underline; }
.recent-summary .summary-all { margin-left: auto; color: var(--muted); }
.section-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin: 24px 0 20px; }
.section-head h1 { font-family: "Songti SC", "STSong", "Noto Serif SC", serif; font-size: 30px; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.edition { color: var(--muted); font-size: 12px; line-height: 1.7; text-align: right; }
.film-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 190px)); justify-content: space-between; gap: 34px 25px; }
.film { display: flex; flex-direction: column; min-width: 0; }
.poster-link { display: block; width: 100%; aspect-ratio: 2 / 3; overflow: hidden; background: #e5dfd6; border-radius: 2px; }
.poster-link img { width: 100%; height: 100%; object-fit: cover; }
.poster-link.image-missing { display: grid; place-items: center; color: var(--muted); font-size: 13px; text-decoration: none; }
.film-title { margin-top: 12px; font-size: 17px; font-weight: 700; }
.film-meta { margin-top: 2px; color: var(--muted); font-size: 12px; }
.film-note { margin-top: 8px; color: var(--soft-ink); font-size: 13px; line-height: 1.65; }
.film-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: auto; padding-top: 6px; border-bottom: 1px solid var(--line); }
.film-search { min-height: 44px; display: inline-flex; align-items: center; color: var(--action); font-size: 13px; font-weight: 600; text-decoration: none; }
.film-search:hover, .text-links a:hover { text-decoration: underline; }
.save-button { min-height: 44px; padding: 0 2px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.save-button:hover, .save-button[aria-pressed="true"] { color: var(--action); }
.browse-more { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 40px; margin-top: 40px; padding-top: 22px; border-top: 1px solid var(--ink); }
.browse-block h2 { font-size: 18px; }
.browse-block p { margin-top: 3px; color: var(--muted); font-size: 13px; }
.text-links { display: flex; flex-wrap: wrap; gap: 0 20px; margin-top: 6px; }
.text-links a { min-height: 40px; display: inline-flex; align-items: center; color: var(--action); text-decoration: none; }
.site-footer { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-top: 44px; padding: 16px 0 26px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.site-footer a { display: inline-flex; min-height: 44px; align-items: center; }

/* Search results: same markup from app.js and the Worker */
.back-link { min-height: 44px; display: inline-flex; align-items: center; margin-top: 8px; color: var(--muted); font-size: 13px; text-decoration: none; }
.back-link:hover { color: var(--ink); }
.results-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; padding-bottom: 14px; }
.results-heading { min-width: 0; }
.results-heading h1 { font-size: 26px; }
.results-summary { margin-top: 4px; color: var(--muted); font-size: 13px; }
.results-tools { display: flex; align-items: center; gap: 20px; flex-shrink: 0; }
.save-outline { padding: 0 14px; border: 1px solid var(--line); border-radius: 3px; background: var(--panel); color: var(--ink); font-size: 13px; }
.source-preferences { position: relative; font-size: 13px; }
.source-preferences summary { min-height: 44px; display: flex; align-items: center; color: var(--muted); cursor: pointer; }
.source-preferences[open] summary { color: var(--ink); }
.preferences-panel { position: absolute; z-index: 5; right: 0; top: calc(100% + 4px); width: min(340px, calc(100vw - 32px)); padding: 14px; border: 1px solid var(--ink); border-radius: 3px; background: var(--panel); }
.preferences-panel p { margin-bottom: 10px; color: var(--muted); font-size: 12px; }
[data-source-preferences] { display: flex; flex-wrap: wrap; gap: 8px; }
[data-source-preferences] button { min-height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 3px; font-size: 13px; }
[data-source-preferences] [aria-pressed="true"] { border-color: var(--accent); color: var(--action); font-weight: 600; }
.result-group { margin: 22px 0 30px; }
.group-head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding-bottom: 8px; border-bottom: 1px solid var(--ink); }
.group-title { font-size: 17px; }
.group-count { flex-shrink: 0; color: var(--muted); font-size: 12px; }
.group-description { margin: 8px 0 2px; color: var(--muted); font-size: 13px; }
.result-row { display: grid; grid-template-columns: minmax(0, 1fr) 170px 128px; gap: 24px; align-items: center; padding: 16px 0; border-bottom: 1px solid var(--line); text-decoration: none; }
.result-row > * { min-width: 0; }
.result-row:hover { background: var(--panel); box-shadow: -8px 0 var(--panel), 8px 0 var(--panel); }
.result-main { display: grid; gap: 3px; }
.result-title { font-size: 17px; font-weight: 600; }
.result-meta { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.result-source { display: flex; align-items: center; flex-wrap: wrap; gap: 2px 8px; font-size: 14px; }
.site-icon { width: 16px; height: 16px; object-fit: contain; flex-shrink: 0; }
.link-kind { flex-basis: 100%; padding-left: 24px; color: var(--muted); font-size: 12px; }
.result-action { justify-self: end; color: var(--action); font-size: 14px; font-weight: 600; white-space: nowrap; }
.result-row[data-kind="search"] .result-title { font-weight: 500; }
.result-row[data-kind="search"] .result-action { padding: 6px 12px; border: 1px solid var(--field); border-radius: 3px; background: var(--panel); color: var(--ink); font-weight: 500; font-size: 13px; }
.source-note { margin: 26px 0; padding-left: 14px; border-left: 2px solid var(--accent); color: var(--muted); font-size: 13px; }
.empty-state { margin: 22px 0 8px; }
.empty-state h2 { font-size: 21px; }
.empty-state p { margin-top: 6px; color: var(--muted); }
.retry-button { min-height: 44px; }
.empty-state .retry-button { margin-top: 14px; padding: 0 18px; border: 1px solid var(--field); border-radius: 3px; background: var(--panel); font-weight: 600; }
.loading-state { display: grid; gap: 14px; padding: 22px 0 60px; border-top: 1px solid var(--ink); }
.loading-state span { display: block; height: 44px; background: rgba(23, 21, 26, .05); border-radius: 2px; }
.related-links, .faq { margin-top: 34px; padding-top: 18px; border-top: 1px solid var(--line); }
.related-links h2, .faq h2 { font-size: 17px; }
.faq dl { display: grid; gap: 4px; margin-top: 10px; font-size: 14px; }
.faq dt { font-weight: 600; margin-top: 8px; }
.faq dd { color: var(--muted); }

/* 我的片单 */
.library-view { margin-top: 26px; }
.library-view h1 { font-family: "Songti SC", "STSong", "Noto Serif SC", serif; font-size: 30px; }
.library-intro { margin-top: 6px; color: var(--muted); font-size: 13px; }
.library-bar { display: flex; align-items: center; gap: 20px; margin-top: 18px; border-bottom: 1px solid var(--line); }
.library-tabs { display: flex; gap: 28px; }
.library-tabs a { min-height: 44px; display: inline-flex; align-items: center; text-decoration: none; }
.library-tabs a[aria-current="page"] { color: var(--action); box-shadow: inset 0 -2px var(--accent); font-weight: 600; }
.history-clear { margin-left: auto; min-height: 44px; color: var(--muted); font-size: 13px; }
.history-clear:hover { color: var(--ink); }
.library-hint { margin-top: 10px; color: var(--muted); font-size: 12px; }
.history-list { margin: 4px 0 0; padding: 0; list-style: none; }
.history-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 24px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.history-copy { display: grid; gap: 2px; min-width: 0; }
.history-title { font-size: 18px; }
.history-meta { color: var(--muted); font-size: 13px; }
.history-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 0 20px; }
.history-link { min-height: 44px; display: inline-flex; align-items: center; font-size: 13px; text-decoration: none; white-space: nowrap; }
.history-link:hover { text-decoration: underline; }
.history-primary, a.history-link { color: var(--action); }
.history-primary { font-weight: 600; }
.history-save, .history-remove { color: var(--muted); }
.history-save[aria-pressed="true"] { color: var(--action); }
.history-empty { padding: 32px 0; color: var(--muted); }
.history-toast { position: fixed; z-index: 20; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 16px; width: max-content; max-width: calc(100% - 24px); padding: 8px 10px 8px 16px; background: var(--ink); color: var(--panel); border-radius: 3px; font-size: 13px; }
.history-toast .history-button { min-height: 40px; padding: 0 12px; border: 1px solid #8e8790; border-radius: 3px; flex-shrink: 0; }
.history-dialog { max-width: min(460px, calc(100vw - 32px)); padding: 24px; border: 1px solid var(--ink); border-radius: 4px; background: var(--panel); color: var(--ink); }
.history-dialog::backdrop { background: rgba(23, 21, 26, .3); }
.history-dialog h2 { margin-bottom: 10px; font-size: 22px; }
.history-dialog p { color: var(--muted); font-size: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 20px; }
.dialog-actions .history-button { min-height: 44px; padding: 0 16px; border: 1px solid var(--line); border-radius: 3px; }
.dialog-actions .history-danger { background: var(--action); border-color: var(--action); color: var(--panel); font-weight: 600; }

@media (max-width: 1100px) {
  .masthead { gap: 24px; }
  .film-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 30px 22px; }
  .summary-source { display: none; }
}
@media (max-width: 700px) {
  body { font-size: 14px; }
  .page-shell { width: calc(100% - 32px); }
  .masthead { grid-template-columns: minmax(0, 1fr) auto; gap: 10px 12px; padding: 12px 0 14px; }
  .brand { font-size: 25px; }
  .brand span { font-size: 14px; }
  .library-link { font-size: 14px; }
  .search-form { grid-row: 2; grid-column: 1 / -1; min-height: 46px; }
  .search-form input { padding: 9px 12px; font-size: 16px; }
  .search-form button { min-height: 44px; padding: 0 16px; font-size: 15px; }
  .recent-summary { flex-wrap: wrap; gap: 0 12px; min-height: 0; padding: 4px 0; font-size: 12px; }
  .summary-title { max-width: 45vw; }
  .section-head { margin: 20px 0 16px; gap: 12px; }
  .section-head h1 { font-size: 25px; }
  .edition { font-size: 11px; }
  .film-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 26px 16px; }
  .film-title { margin-top: 9px; font-size: 16px; }
  .film-meta { font-size: 11px; }
  .film-note { font-size: 12px; }
  .film-search, .save-button { font-size: 12px; }
  .browse-more { grid-template-columns: minmax(0, 1fr); gap: 22px; margin-top: 30px; padding-top: 18px; }
  .browse-block h2 { font-size: 17px; }
  .site-footer { display: block; margin-top: 30px; font-size: 11px; }
  .site-footer p + p { margin-top: 2px; }
  .results-head { flex-direction: column; align-items: stretch; gap: 6px; padding-bottom: 6px; }
  .results-heading h1 { font-size: 23px; }
  .results-tools { justify-content: space-between; }
  .preferences-panel { right: auto; left: 0; }
  .source-preferences:last-child .preferences-panel { left: auto; right: 0; }
  .result-row { grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; padding: 14px 0; }
  .result-main { grid-column: 1 / -1; }
  .result-title { font-size: 16px; }
  .result-meta { font-size: 12px; }
  .result-source { font-size: 13px; }
  .link-kind { flex-basis: auto; padding-left: 0; font-size: 11px; }
  .result-action { font-size: 13px; }
  .group-description, .source-note { font-size: 12px; }
  .library-view { margin-top: 20px; }
  .library-view h1 { font-size: 26px; }
  .library-tabs { gap: 22px; }
  .history-row { grid-template-columns: minmax(0, 1fr); gap: 4px; padding: 14px 0 6px; }
  .history-title { font-size: 17px; }
  .history-meta { font-size: 12px; }
  .history-actions { gap: 0 18px; }
}
@media (max-width: 360px) {
  .section-head h1 { font-size: 22px; }
  .edition { white-space: nowrap; }
  .search-form input { padding: 9px 10px; }
  .search-form button { padding: 0 13px; }
}
@media (prefers-reduced-motion: no-preference) {
  .poster-link img { transition: filter .15s; }
  .poster-link:hover img { filter: brightness(1.05); }
}
