/* Adapted from Kami's Letter template (MIT). Existing site colours take precedence.
   https://github.com/tw93/Kami/blob/main/skills/kami/assets/templates/letter.html */
:root {
  --letter-serif: "Noto Serif SC Variable", "Noto Serif CJK SC", "Source Han Serif SC", "Songti SC", "STSong", Georgia, serif;
  --letter-ui: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}
body { font-family: var(--letter-ui); font-weight: 400; }
.view-nav, .typesetting-toolbar, .form-label, .form-status, .upload-hint, .record-meta, .record-date, .page-position, .form-submit, .upload-button, .text-link, .reply-entry-button, .pagination, .view-kicker, .letter-category { font-family: var(--letter-ui); }
.view-heading h1 { font-family: var(--letter-serif); font-size: clamp(30px,4vw,40px); font-weight: 500; line-height: 1.3; letter-spacing: .03em; }
.view-heading p:last-child { font-family: var(--letter-serif); font-size: 16px; line-height: 1.75; }
.letter-card h2, .recent-link, .free-board h2, .sticky-dialog-heading h2, .reply-compose h2 { font-family: var(--letter-serif); font-weight: 500; }
.letter-card h2 { font-size: 22px; line-height: 1.55; }
.letter-excerpt { font-size: 16px; line-height: 1.75; letter-spacing: 0; }
.sticky-note .record-content { font-family: var(--letter-serif); font-size: 18px; line-height: 1.8; }
input.form-field, select.form-field { height: 50px; min-height: 50px; min-width: 0; max-width: 100%; padding: 0 14px; font: 400 16px/normal var(--letter-ui); letter-spacing: 0; }
textarea.form-field { font: 400 18px/1.8 var(--letter-serif); padding: 14px; }
select.form-field, input[type="search"] { font-family: var(--letter-ui); font-size: 16px; }
/* Reading column and Letter slots follow Kami's Letter template. */
.letter-shell { width: min(100%,880px); }
.letter-paper { padding: clamp(40px,6vw,76px) clamp(28px,7vw,104px) 52px; }
.reader-paper { max-width: 880px; }
.letterhead { margin: 0 0 38px; }
.letterhead .letterhead-line { display: flex; justify-content: space-between; align-items: baseline; gap: 20px; margin-bottom: 28px; font: 11px/1.5 var(--letter-ui); letter-spacing: .12em; color: var(--ink-soft); }
.letterhead .letterhead-line span:last-child { letter-spacing: 0; }
.subject { margin: 0; }
.subject .label { margin: 0 0 10px; font: 12px/1.4 var(--letter-ui); color: var(--ink-soft); letter-spacing: .08em; }
.subject .title { margin: 0; color: var(--ink); font-family: var(--letter-serif); font-size: clamp(30px,4vw,40px); font-weight: 500; line-height: 1.35; letter-spacing: .02em; text-align: left; text-wrap: balance; overflow-wrap: anywhere; }
.letterhead .letterhead-meta { margin: 20px 0 0; font: 12px/1.6 var(--letter-ui); color: var(--ink-soft); }
.kami-letter { --letter-size: 20px; max-width: 36em; margin-inline: auto; font-family: var(--letter-serif); font-size: var(--letter-size); font-weight: 400; line-height: 1.75; letter-spacing: 0; color: var(--ink); line-break: strict; word-break: normal; overflow-wrap: anywhere; }
.kami-letter .salutation { margin: 0 0 28px; font-size: 1.1em; font-weight: 500; line-height: 1.55; text-indent: 0; }
.kami-letter .body-content p { margin: 0 0 1.2em; font-size: inherit; font-weight: 400; line-height: 1.75; text-align: justify; text-justify: inter-ideograph; text-indent: 2em; widows: 3; orphans: 3; }
.kami-letter .body-content p:last-child { margin-bottom: 0; }
.kami-letter .body-content .no-indent { text-indent: 0; text-align: left; }
.kami-letter .body-content .letter-postscript { margin-top: 1.75em; font-size: .9em; text-indent: 0; }
.kami-letter .closing { margin-top: 2em; text-align: right; break-inside: avoid; }
.kami-letter .closing .regards { margin: 0 0 .6em; font-size: inherit; line-height: 1.55; }
.kami-letter .closing .signature { margin: .6em 0 0; font-size: 1.1em; font-weight: 500; line-height: 1.55; }
.kami-letter .closing .signoff-meta { margin: .5em 0 0; font: 12px/1.6 var(--letter-ui); color: var(--ink-soft); }
.kami-letter .letter-raw { white-space: pre-wrap; line-height: 1.75; overflow-wrap: anywhere; }
.reader-content, .original-text { white-space: normal; }
.letter-copy:not(.kami-letter) { font-size: inherit; line-height: inherit; letter-spacing: 0; }
.typesetting-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 0; padding: 12px 0; color: var(--ink-soft); }
.layout-mode-group, .type-size-group { display: inline-flex; align-items: center; gap: 3px; }
.layout-mode-group { padding: 3px; border: 1px solid var(--paper-edge); border-radius: 999px; background: rgba(255,250,241,.62); }
.layout-button { min-height: 38px; padding: 7px 12px; border: 0; border-radius: 999px; background: transparent; color: var(--ink-soft); font: 12px/1.4 var(--letter-ui); cursor: pointer; transition: background-color 180ms ease,transform 180ms ease; }
.layout-button[aria-pressed="true"] { background: var(--ivory); color: var(--ink); box-shadow: 0 2px 7px var(--warm-shadow); }
.layout-button:disabled { opacity: .38; cursor: default; }
.layout-button:hover:not(:disabled) { background: rgba(243,221,200,.55); }
.type-size { min-width: 36px; padding-inline: 7px; font-family: Georgia,serif; font-size: 15px; }
.reading-length { margin-left: auto; font-size: 11px; line-height: 1.5; white-space: nowrap; }
.print-letter { border: 1px solid var(--paper-edge); }
.reading-controls { width: min(100%,880px); margin: 8px auto 15px; }
.showcase-reading-controls { margin-top: 0; margin-bottom: 30px; padding-bottom: 12px; border-bottom: 1px solid var(--paper-edge); }
.reader-heading { border: 0; padding-bottom: 0; margin-bottom: 24px; }
.reader-paper .reader-heading h1 { font: inherit; }
.reader-paper .reader-heading .subject .title { font-size: clamp(30px,4vw,40px); font-weight: 500; line-height: 1.35; }
.reader-paper .record-image-frame { margin-top: 36px; }
.letter-paper > .reply-entry-button, .letter-copy > .reply-entry-button { margin-top: 36px; }
.letter-copy > .keepsake-figure { margin-top: 36px; }
/* Writing and preview share the same typesetting engine and paper components. */
#view-compose > .page-view { width: min(100%,1260px); }
.compose-grid { grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 28px; }
.compose-preview { position: sticky; top: 22px; min-width: 0; }
.compose-preview-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.compose-preview-header h2 { margin: 0; font: 13px/1.6 var(--letter-ui); color: var(--ink-soft); }
.preview-paper { position: relative; min-height: 450px; max-height: 78svh; overflow-y: auto; padding: 40px 36px; border: 1px solid var(--paper-edge); border-radius: 9px; background: var(--ivory); box-shadow: 0 12px 32px var(--warm-shadow); scrollbar-color: var(--kraft-light) transparent; }
.preview-paper .subject .title { font-size: 28px; line-height: 1.4; }
.preview-paper .kami-letter { font-size: calc(var(--letter-size) - 2px); }
.preview-paper .letterhead { margin-bottom: 30px; }
.preview-placeholder { margin: 22px 0 0; font: 16px/1.9 var(--letter-serif); color: var(--ink-soft); }
.preview-image { display: block; width: 100%; max-height: 280px; object-fit: contain; margin-top: 28px; border-radius: 6px; }
.recent-letters-section { margin-top: 32px; }
.recent-letters-section .saved-list { grid-template-columns: repeat(3,minmax(0,1fr)); gap: 14px; }
.recent-letters-section > h2 { margin-bottom: 8px; font-size: 20px; font-weight: 500; }
.recent-letters-section > .text-link { margin-bottom: 12px; }
.recent-letters-section .record-date { font-size: 11px; }
.reply-page h1 { font-family: var(--letter-serif); font-weight: 500; font-size: clamp(30px,4vw,40px); line-height: 1.35; }
.reply-note .kami-letter { margin: 0; font-size: 18px; }
.reply-note .kami-letter .body-content p { text-align: left; text-indent: 0; margin-bottom: .8em; }
.reply-note .kami-letter .salutation { margin-bottom: 1em; }
.original-letter-copy { padding: 30px clamp(20px,5vw,60px); }
.original-letter-copy .kami-letter { font-size: 18px; }
.original-letter-copy h2 { font: 500 24px/1.5 var(--letter-serif); margin-bottom: 25px; }
@media (max-width:960px) {
  .compose-grid { grid-template-columns: minmax(0,1fr); }
  .compose-preview { position: static; }
  .preview-paper { max-height: none; }
}
@media (max-width:767px) {
  .view-heading h1 { font-size: 30px; }
  .letter-paper, .reader-paper { padding: 36px 23px 38px; }
  .subject .title, .reader-paper .reader-heading .subject .title { font-size: 30px; }
  .letterhead { margin-bottom: 28px; }
  .letterhead .letterhead-line { margin-bottom: 24px; gap: 12px; font-size: 10px; }
  .kami-letter { font-size: calc(var(--letter-size) - 2px); line-height: 1.75; }
  .kami-letter .body-content p { margin-bottom: 1.1em; }
  .kami-letter .salutation { margin-bottom: 24px; }
  .typesetting-toolbar { gap: 7px; }
  .layout-button { min-height: 42px; padding: 7px 9px; }
  .type-size { padding-inline: 6px; }
  .reading-length { width: 100%; margin: 2px 0 0; }
  .preview-paper { padding: 32px 24px; min-height: 360px; }
  .preview-paper .subject .title { font-size: 26px; }
  .recent-letters-section .saved-list { grid-template-columns: 1fr; }
  .reply-note .kami-letter { font-size: 17px; }
}
@page { size: A4; margin: 23mm; }
@media print {
  html,body { min-width: 0; background: var(--ivory); }
  body::before,body::after,.view-nav,.typesetting-toolbar,.sticker-row,.ornament,.envelope-wrap,.open-hint,.reply-entry-button,.reader-lightbox,.photo-lightbox,.touch-toast { display: none !important; }
  .app-shell,.page-view,.scene { width: 100%; max-width: none; min-height: 0; margin: 0; padding: 0; }
  .view-panel[hidden] { display: none !important; }
  .letter-shell { display: block; width: 100%; grid-template-rows: 1fr; opacity: 1; margin: 0; }
  .letter-clip { overflow: visible; }
  .letter-paper,.reader-paper { opacity: 1; transform: none; width: 100%; max-width: none; border: 0; border-radius: 0; margin: 0; padding: 0; box-shadow: none; background: none; overflow: visible; }
  .letter-paper::before,.letter-paper::after { display: none; }
  .kami-letter { max-width: none; font-size: 12pt; line-height: 1.55; }
  .kami-letter .body-content p { line-height: 1.55; margin-bottom: 14pt; }
  .subject .title,.reader-paper .reader-heading .subject .title { font-size: 22pt; }
  .keepsake-figure,.record-image-frame { break-inside: avoid; }
  *,*::before,*::after { animation: none !important; transition: none !important; }
}
@media (prefers-reduced-motion:reduce) { .layout-button { transition: none; } }
@media print {
  .library-page > .text-link, #readerStatus { display: none !important; }
}
@media (max-width:767px) {
  .reading-length { width: auto; flex: 1 1 110px; }
  .print-letter { margin-left: auto; }
}
