.detail-photo{display:block;max-width:100%;max-height:440px;object-fit:contain;margin:20px 0}.detail-body audio{width:100%;margin:12px 0}
.quote-dialog.no-image{max-width:min(620px,calc(100vw - 30px))}
.dialog-shell.no-image{display:block;min-height:0}
.detail-image.custom-image{background-image:none}
.detail-background{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;z-index:-2}
.note-bottom>span{flex:1;min-width:0}
.note-bottom .small-button{flex-shrink:0}
.note-bottom .small-button:disabled{opacity:.6;cursor:wait}
.ai-chat{margin-top:28px;padding-top:24px;border-top:1px solid var(--line)}
.chat-heading{display:flex;justify-content:space-between;align-items:center;gap:16px}
.chat-heading h3{font:22px var(--serif)}
.chat-heading button{font-size:12px;white-space:nowrap}
.chat-help{font-size:12px;line-height:1.8;color:var(--muted);margin-top:12px}
.chat-history{max-height:216px;overflow-y:auto;overscroll-behavior:contain;margin:20px 0;scrollbar-gutter:stable}
.chat-message{padding:16px 0;border-top:1px solid var(--line)}
.chat-message strong{font-size:12px;font-weight:500;color:var(--rust)}
.chat-message p{margin-top:7px;font-size:13px;line-height:1.9;white-space:pre-wrap;overflow-wrap:anywhere}
.chat-message.user p{color:var(--muted)}
.chat-form label{display:block;font-size:12px;margin-top:20px}
.chat-form textarea{margin-top:8px;min-height:78px;max-height:180px}
.chat-form>.small-button{display:block;margin:12px 0 0 auto}
.chat-form>.small-button:disabled{opacity:.6;cursor:wait}
.chat-status{font-size:12px;line-height:1.8;margin-top:10px;color:var(--rust)}
@media(max-width:480px){.chat-heading{align-items:flex-start}.chat-heading h3{font-size:21px}.chat-history{max-height:300px}}

/* Floating chat stays in the dialog's top layer and is anchored to the viewport. */
.chat-widget[hidden]{display:none}
.chat-widget{position:fixed;right:24px;bottom:24px;z-index:30}
.chat-toggle{display:grid;place-items:center;width:58px;height:58px;border-radius:50%;background:var(--olive);color:var(--theme-button-label);box-shadow:0 8px 24px #252b2250;cursor:pointer;transition:transform .25s ease,background .25s ease;overflow:hidden;padding:0;border:none}
.chat-toggle:hover{transform:translateY(-3px);background:var(--theme-hover)}
.chat-toggle .icon{width:24px;height:24px}
.chat-toggle-img{width:100%;height:100%;object-fit:cover;border-radius:50%;display:block}
.chat-widget .ai-chat{position:absolute;right:0;bottom:72px;width:min(350px,calc(100vw - 32px));height:min(480px,calc(100dvh - 120px));min-height:260px;display:flex;flex-direction:column;padding:22px;margin:0;background:var(--paper);color:var(--ink);border:0;border-radius:12px;box-shadow:0 16px 48px #20251f50;opacity:0;visibility:hidden;transform:translateY(16px) scale(.96);transform-origin:bottom right;transition:opacity .3s ease,transform .3s ease,visibility .3s}
.chat-widget.is-open .ai-chat{opacity:1;visibility:visible;transform:translateY(0) scale(1)}
.chat-widget .chat-heading{flex:none;align-items:flex-start;padding-bottom:17px;border-bottom:1px solid var(--line)}
.chat-widget .chat-heading h3{font:21px var(--serif)}
.chat-widget .chat-caption{font:15px var(--serif);color:var(--rust);margin-bottom:4px}
.chat-widget .chat-heading .icon-button{flex:none;width:36px;height:36px}
.chat-widget .chat-content{flex:1;overflow:auto;padding-top:25px}
.chat-widget .chat-welcome{font:20px/1.5 var(--serif)}
.chat-widget .chat-help{margin-top:8px}
.chat-widget .chat-availability{font-size:12px;color:var(--muted);margin-top:18px}
.chat-widget .chat-form{display:flex;align-items:end;gap:10px;border-top:1px solid var(--line);padding-top:12px}
.chat-widget .chat-form textarea{margin:0;min-height:60px;resize:none}
.chat-widget .chat-form .small-button{margin:0;flex:none}
@media(max-width:480px){.chat-widget{right:16px;bottom:16px}.chat-widget .ai-chat{height:min(480px,calc(100dvh - 104px))}}
@media(prefers-reduced-motion:reduce){.chat-widget .ai-chat,.chat-toggle{transition:none}}
.chat-widget .chat-reset{align-self:flex-start;margin-top:12px;font-size:12px;text-decoration:none}
.chat-widget .chat-reset:disabled{opacity:.6}
.chat-widget .chat-message h4{font-size:14px;line-height:1.5;margin-top:14px}
.chat-widget .chat-message ul{padding-left:20px;margin:8px 0}
.chat-widget .chat-message li{font-size:13px;line-height:1.8;margin:5px 0;overflow-wrap:anywhere}
.chat-widget .chat-message div strong{font-weight:600;color:inherit}

/* Compact four-column library on wide screens; keep smaller screens readable. */
@media (min-width:1101px){
  .quote-grid{grid-template-columns:repeat(4,minmax(0,1fr))}
}
.library-order{display:flex;align-items:center;gap:12px;flex-shrink:0;font-size:12px;color:var(--muted)}
.library-order select{font:inherit;color:var(--ink);background:transparent;border:1px solid var(--line);border-radius:4px;padding:8px 28px 8px 10px;cursor:pointer}
.library-order select:focus-visible{outline:2px solid var(--olive);outline-offset:2px}
@media(max-width:800px){.library-tools{flex-wrap:wrap}.library-order{margin-left:auto}}
.copy-toast{position:fixed;z-index:40;bottom:24px;left:50%;transform:translate(-50%,8px);opacity:0;visibility:hidden;padding:10px 17px;border-radius:6px;background:var(--theme-button);color:var(--theme-button-label);font:13px var(--sans);box-shadow:0 8px 24px #17201b35;white-space:nowrap;pointer-events:none;transition:opacity .18s ease,transform .18s ease,visibility .18s}
.copy-toast.visible{opacity:1;visibility:visible;transform:translate(-50%,0)}
@media(prefers-reduced-motion:reduce){.copy-toast{transition:none}}

.note-bottom{justify-content:flex-end}


/* A spacious reading room; chat stays within the letter, not the viewport. */
.quote-dialog,.quote-dialog.no-image{width:92vw;max-width:1720px;height:88dvh;max-height:calc(100dvh - 48px);overflow:hidden}
.quote-dialog .dialog-shell{height:100%;min-height:0;grid-template-columns:minmax(280px,30%) minmax(0,1fr)}
.quote-dialog .dialog-shell.no-image{display:block}
.quote-dialog .detail-image{min-height:0;height:100%}
.quote-dialog .detail-body{height:100%;overflow:auto;overscroll-behavior:contain;padding:48px 80px 96px;scrollbar-gutter:stable}
.quote-dialog .detail-body>h2,.quote-dialog .detail-body>blockquote,.quote-dialog .meaning{max-width:75ch;overflow-wrap:anywhere}
.quote-dialog .meaning{font-size:14px}
.quote-dialog .letter-content {
  position: relative;
  isolation: isolate;
  max-width: 75ch;
}
.quote-dialog .letter-background {
  position: sticky;
  top: 15%;
  height: 0;
  z-index: -1;
  pointer-events: none;
}
.quote-dialog .letter-background::before {
  content: '';
  position: absolute;
  width: 100%;
  height: min(60dvh, 600px);
  background: url('/assets/backgroud_write.svg') center / min(100%, 600px) auto no-repeat;
  opacity: .38;
}
.quote-dialog[data-book="book-two"] .letter-background::before {
  background: url('/assets/backgroudbenhoan.svg') center / contain no-repeat;
  opacity: .22;
  -webkit-mask-image: radial-gradient(ellipse at center, #000 52%, transparent 96%);
  mask-image: radial-gradient(ellipse at center, #000 52%, transparent 96%);
}
.quote-dialog[data-book="book-three"] .letter-background::before {
  background: url('/assets/backgroudtinhban.svg') center / contain no-repeat;
  opacity: .22;
  -webkit-mask-image: radial-gradient(ellipse at center, #000 52%, transparent 96%);
  mask-image: radial-gradient(ellipse at center, #000 52%, transparent 96%);
}
.quote-dialog[data-book="book-four"] .letter-background::before { background: none; }

/* A torn sheet gathers before the real, interactive letter is revealed. */
@media (prefers-reduced-motion: no-preference) {
  .quote-dialog.paper-assembling { background-color: transparent; }
  .paper-assembly { position: absolute; inset: 0; z-index: 25; pointer-events: none; animation: paper-assembly-finish 1.2s linear both; }
  .paper-fragment { position: absolute; display: block; background: var(--theme-popup, var(--paper)); will-change: transform, opacity; animation: paper-fragment-gather 850ms cubic-bezier(.16, 1, .3, 1) var(--piece-delay) both; }
  .quote-dialog.paper-assembling .dialog-shell { animation: paper-letter-reveal 1.05s ease-out both; }
  @keyframes paper-fragment-gather {
    from { opacity: 0; transform: translate(var(--piece-x), var(--piece-y)) rotate(var(--piece-angle)) scale(.93); }
    18% { opacity: 1; }
    to { opacity: 1; transform: translate(0, 0) rotate(0) scale(1); }
  }
  @keyframes paper-assembly-finish { 0%, 64% { opacity: 1; } 100% { opacity: 0; } }
  @keyframes paper-letter-reveal { 0%, 48% { opacity: 0; } 100% { opacity: 1; } }
}
.quote-dialog .close-dialog{position:absolute;right:16px;top:16px;z-index:31}
.quote-dialog .chat-widget{position:absolute;right:20px;bottom:16px}
.quote-dialog .chat-toggle{width:46px;height:46px}
.quote-dialog .chat-toggle .icon{width:21px;height:21px}
.chat-widget.is-open .chat-toggle{visibility:hidden;pointer-events:none}
.chat-greeting{position:absolute;bottom:calc(100% + 10px);right:0;background:var(--theme-button);color:var(--theme-button-label);font-size:13px;font-family:var(--sans);padding:7px 13px;border-radius:20px;white-space:nowrap;box-shadow:0 4px 12px #00000030;pointer-events:none;animation:greet-in .35s ease both}
.chat-widget.is-open .chat-greeting{display:none}
@keyframes greet-in{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:translateY(0)}}
.quote-dialog .chat-greeting{animation:letter-greeting 8s ease-in-out infinite}
@keyframes letter-greeting {
  0%, 34% { opacity: 1; transform: translateY(0); }
  40%, 94% { opacity: 0; transform: translateY(4px); }
  100% { opacity: 1; transform: translateY(0); }
}
.quote-dialog .chat-widget .ai-chat{bottom:0;height:min(420px,calc(88dvh - 48px));width:340px;max-width:calc(92vw - 48px);min-height:0;padding:20px}
.post-comments{border-top:1px solid var(--line);padding-top:24px;margin-top:24px}
.comments-heading{display:flex;align-items:center;justify-content:space-between;gap:16px}
.comments-heading h3{font:22px var(--serif)}
.comments-heading button{font-size:12px}
.comments-order{font-size:12px;color:var(--muted);margin:10px 0 16px}
.comments-scroll{max-height:204px;overflow:auto;overscroll-behavior:contain;scrollbar-gutter:stable;padding-right:12px}
#comments-list{list-style:none;padding:0;margin:0}
.public-comment{display:flex;align-items:flex-start;gap:12px;padding:20px 0;border-bottom:1px solid var(--line)}
.public-comment:first-child{padding-top:4px}
.comment-avatar{width:34px;height:34px;flex:none;display:grid;place-items:center;border-radius:50%;background:var(--line);color:var(--ink)}
.comment-avatar .icon{width:19px;height:19px}
.comment-content{min-width:0;flex:1}
.comment-content strong{font-size:13px;font-weight:600}
.comment-content time{display:block;font-size:11px;line-height:1.6;color:var(--muted);margin-top:3px;font-variant-numeric:tabular-nums}
.comment-content p{font-size:14px;line-height:1.8;white-space:pre-wrap;overflow-wrap:anywhere;margin-top:10px}
#comments-status{font-size:13px;color:var(--muted)}
#comments-status:empty,#note-status:empty{display:none}
#comments-more{margin:16px 0;font-size:13px}
@media(max-width:1100px){
 .quote-dialog .dialog-shell{grid-template-columns:minmax(220px,28%) minmax(0,1fr)}
 .quote-dialog .detail-body{padding:48px 32px 96px}
}
@media(max-width:800px){
 .quote-dialog,.quote-dialog.no-image{width:calc(100vw - 24px);max-width:none;height:calc(100dvh - 32px);max-height:none}
 .quote-dialog .dialog-shell{display:block;overflow:auto;overscroll-behavior:contain}
 .quote-dialog .detail-image{height:200px;min-height:0}
 .quote-dialog .detail-body{height:auto;overflow:visible;padding:32px 24px 100px}
 .quote-dialog .chat-widget{right:16px;bottom:16px}
 .quote-dialog .chat-widget .ai-chat{width:340px;max-width:calc(100vw - 56px);height:min(420px,calc(100dvh - 80px))}
 .comments-scroll{max-height:204px}
 .comments-heading h3{font-size:20px}
}

.quote-dialog .detail-body > .detail-category,
.quote-dialog .detail-body > h2,
.quote-dialog .detail-body > blockquote,
.quote-dialog .detail-body > .letter-content,
.quote-dialog .detail-body > .detail-actions,
.quote-dialog .detail-body > audio,
.quote-dialog .detail-body > .private-note,
.quote-dialog .detail-body > .post-comments {
  width: min(100%, 720px);
  max-width: none;
  margin-inline: auto;
}

.quote-dialog .detail-body > audio:not([hidden]) { display: block; }
.quote-dialog .detail-body .meaning { max-width: none; text-align: justify; }

.card-caption > span { min-width: 0; overflow-wrap: anywhere; line-height: 1.6; }
.card-caption .caption-link { flex: none; white-space: nowrap; }

#ai-chat #chat-history { display: flex; flex-direction: column; gap: 14px; }
#ai-chat .chat-message { max-width: 88%; min-width: 0; padding: 0; border: 0; }
#ai-chat .chat-message.user { align-self: flex-end; }
#ai-chat .chat-message.user p {
  margin: 0; padding: 9px 13px; border-radius: 15px 15px 4px 15px;
  background: var(--olive); color: var(--theme-button-label); line-height: 1.65;
}
#ai-chat .chat-message.assistant { align-self: flex-start; }
#ai-chat .chat-message.assistant > strong { display: block; margin: 0 0 4px 2px; }
#ai-chat .chat-message.assistant > div {
  padding: 9px 13px; border-radius: 15px 15px 15px 4px;
  background: var(--theme-secondary); color: var(--theme-ink-readable);
}
#ai-chat .chat-message.assistant p { margin: 0; line-height: 1.65; }
#ai-chat .chat-message.assistant p + p { margin-top: 8px; }
