/* Stationery and wallpaper share motifs but are selected independently. */
[data-theme="classic"] {
  --paper-ground: #f4eee1;
  --paper-motif: repeating-linear-gradient(0deg, #765d3820 0 1px, transparent 1px 5px);
  --paper-repeat: 100% 100%;
}
[data-pattern="plain"] { --paper-ground: #eee6d8; --paper-motif: none; --paper-repeat: auto }
:is([data-theme="birthday"], [data-pattern="birthday"]) {
  --paper-ground: #f4e5ce;
  --paper-motif: radial-gradient(circle at 23% 28%, #a66a3d65 0 1.5px, transparent 2px),
    radial-gradient(circle at 76% 63%, #b4494b66 0 1px, transparent 1.5px);
  --paper-repeat: 22px 21px;
}
:is([data-theme="festival"], [data-pattern="festival"]) {
  --paper-ground: #efd9d0;
  --paper-motif: repeating-linear-gradient(45deg, #8f361c4a 0 1px, transparent 1px 8px),
    repeating-linear-gradient(-45deg, #8f361c42 0 1px, transparent 1px 8px);
  --paper-repeat: auto;
}
:is([data-theme="valentine"], [data-pattern="valentine"]) {
  --paper-ground: #ecdee6;
  --paper-motif: radial-gradient(ellipse at 50% 50%, transparent 36%, #93547963 38% 42%, transparent 45%);
  --paper-repeat: 36px 17px;
}
:is([data-theme="christmas"], [data-pattern="christmas"]) {
  --paper-ground: #dce6dd;
  --paper-motif: repeating-linear-gradient(90deg, #35624a43 0 1px, transparent 1px 12px, #35624a32 12px 16px, transparent 16px 28px),
    repeating-linear-gradient(0deg, #35624a43 0 1px, transparent 1px 12px, #35624a32 12px 16px, transparent 16px 28px);
  --paper-repeat: auto;
}
:is([data-theme="classmates"], [data-pattern="classmates"]) {
  --paper-ground: #e1eaf0;
  --paper-motif: repeating-linear-gradient(0deg, #4b6c8852 0 1px, transparent 1px 9px);
  --paper-repeat: auto;
}
:is([data-theme="elders"], [data-pattern="elders"]) {
  --paper-ground: #e7e8d6;
  --paper-motif: radial-gradient(ellipse at 40% 45%, transparent 36%, #6271485b 38% 41%, transparent 43% 51%, #62714851 53% 55%, transparent 57%);
  --paper-repeat: 38px 30px;
}
:is([data-theme="confession"], [data-pattern="confession"]) {
  --paper-ground: #eededb;
  --paper-motif: repeating-linear-gradient(-35deg, #9b4c5c51 0 2px, transparent 2px 10px);
  --paper-repeat: auto;
}

body[data-pattern]:is([data-panel="editor"], [data-panel="reader"]) {
  background-color: var(--paper-ground);
  background-image: linear-gradient(#fffaf1ca, #fffaf1ca), var(--paper-motif);
  background-size: auto, var(--paper-repeat);
}
body[data-panel="reader"][data-pattern] {
  background-image: radial-gradient(ellipse at 50% 12%, #fffdf7ea, #fffaf1bd 55%, #fffaf184 100%), var(--paper-motif);
}
:is(.editor-page, .reader-page) .paper-head {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 64px;
  padding: 8px 12px 8px 16px;
  margin: 0 0 24px;
  border-inline-start: 3px solid var(--theme-accent);
  background-color: var(--paper-ground);
  background-image: linear-gradient(90deg, var(--paper-ground) 46%, transparent 86%), var(--paper-motif);
  background-size: auto, var(--paper-repeat);
}
:is(#reader.reader-page, #editor.editor-page) .paper-head .letter-edition {
  display: grid;
  gap: 4px;
  margin: 0;
  color: var(--theme-ink);
  font: 500 12px/1.3 var(--sans);
  letter-spacing: .05em;
  opacity: 1;
}
.paper-head .letter-edition span:last-child {
  font: 400 18px/1.24 var(--serif);
  font-synthesis: none;
  letter-spacing: .035em;
}
.paper-device {
  position: relative;
  flex: none;
  inline-size: 48px;
  block-size: 40px;
  color: var(--theme-accent);
  background: radial-gradient(circle, currentColor 0 2px, transparent 3px 10px, currentColor 11px 12px, transparent 13px 16px, currentColor 17px 18px, transparent 19px);
}
[data-theme="birthday"] .paper-head { border-inline-start-style: dotted; border-start-end-radius: 16px }
[data-theme="birthday"] .paper-device {
  background: radial-gradient(ellipse 4px 6px at 50% 13%, #b76729 72%, transparent),
    repeating-linear-gradient(135deg, #ae4a44 0 3px, #fff0d9 3px 6px) center 14px / 8px 22px no-repeat,
    linear-gradient(#ae4a44, #ae4a44) center bottom 2px / 30px 2px no-repeat;
}
[data-theme="festival"] .paper-head { justify-content: flex-start; border-inline-start-width: 6px }
[data-theme="festival"] .paper-device { order: -1; background: none }
[data-theme="festival"] .paper-device::before {
  content: "";
  position: absolute;
  inset: 10px 14px;
  border: 5px double currentColor;
  transform: rotate(45deg);
}
[data-theme="valentine"] .paper-head { border: 1px dashed #a06380; border-inline-end-width: 3px }
[data-theme="valentine"] .paper-device {
  inline-size: 40px;
  block-size: 23px;
  border: 1px solid currentColor;
  border-inline-end: 5px double currentColor;
  background: linear-gradient(currentColor, currentColor) 6px 7px / 16px 1px no-repeat,
    linear-gradient(currentColor, currentColor) 6px 12px / 11px 1px no-repeat;
}
[data-theme="christmas"] .paper-head { border-inline-start: 0; border-block-start: 3px double var(--theme-accent) }
[data-theme="christmas"] .paper-device {
  inline-size: 37px;
  background: currentColor;
  clip-path: polygon(50% 2%, 75% 34%, 65% 34%, 87% 61%, 75% 61%, 99% 87%, 56% 87%, 56% 99%, 44% 99%, 44% 87%, 1% 87%, 25% 61%, 13% 61%, 35% 34%, 25% 34%);
}
[data-theme="classmates"] .paper-head { border-inline-start: 4px double #536d83 }
[data-theme="classmates"] .paper-device {
  background: radial-gradient(circle at 12px 10px, #536d83 0 3px, transparent 4px),
    radial-gradient(circle at 12px 25px, #536d83 0 3px, transparent 4px),
    repeating-linear-gradient(0deg, transparent 0 6px, currentColor 6px 7px) 23px center / 25px 28px no-repeat;
}
[data-theme="elders"] .paper-head { border-inline-start: 0; border-block-end: 2px solid #788064; border-start-start-radius: 24px }
[data-theme="elders"] .paper-device {
  background: radial-gradient(ellipse at 42% 48%, #78806433 0 8px, #788064 9px 10px, transparent 11px 15px, currentColor 16px 17px, transparent 18px),
    radial-gradient(ellipse at 75% 47%, transparent 4px, currentColor 5px 6px, transparent 7px);
}
[data-theme="confession"] .paper-head { flex-direction: row-reverse; text-align: end; border-inline-start: 0; border-block-end: 2px dashed var(--theme-accent) }
[data-theme="confession"] .paper-device {
  background: radial-gradient(circle at 36% 56%, transparent 0 8px, currentColor 9px 10px, transparent 11px),
    radial-gradient(circle at 62% 43%, transparent 0 8px, currentColor 9px 10px, transparent 11px);
}

#reader.reader-page {
  --sheet-border: color-mix(in srgb, var(--theme-ink) 25%, transparent);
  --sheet-light: color-mix(in srgb, var(--theme-paper) 38%, #fffdf6);
  --sheet-shadow: color-mix(in srgb, var(--theme-paper) 82%, var(--paper-ground));
  inline-size: min(100%, 704px);
  margin-block: clamp(20px, 3vw, 40px) 0;
}
#reader.reader-page .book {
  display: block;
  min-height: 0;
  border-color: var(--sheet-border);
  border-radius: 0;
  overflow: visible;
  box-shadow: 0 2px 5px #4332220b, 0 15px 28px -20px #43322260;
}
#reader.reader-page .sheet {
  position: relative;
  display: block;
  padding: clamp(20px, 4vw, 40px) clamp(17px, 5.6vw, 48px) clamp(24px, 4vw, 42px);
  background: linear-gradient(#fffdf693, #fffdf693), var(--grain),
    linear-gradient(145deg, var(--sheet-light), var(--sheet-shadow));
}
#reader.reader-page .sheet::before {
  content: "";
  position: absolute;
  inset: clamp(7px, 1vw, 12px);
  border: 1px solid var(--sheet-border);
  box-shadow: inset 0 0 0 2px #fffdf466;
  pointer-events: none;
}
#reader.reader-page .paper-head {
  min-height: 52px;
  padding: 0 0 10px;
  margin-block-end: clamp(12px, 2vw, 18px);
  justify-content: space-between;
  border: 0;
  border-block-end: 1px solid var(--sheet-border);
  border-radius: 0;
  background: none;
}
#reader.reader-page .paper-stamp {
  position: relative;
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
  flex: none;
  inline-size: 40px;
  block-size: 42px;
  border: 1px dashed var(--sheet-border);
  outline: 1px solid #fffdf2;
  outline-offset: -4px;
  background: var(--grain), color-mix(in srgb, var(--theme-accent) 8%, var(--sheet-light));
}
#reader.reader-page .paper-stamp::before {
  content: "";
  position: absolute;
  inset-inline-end: 100%;
  inline-size: 23px;
  block-size: 12px;
  background: linear-gradient(to left, var(--sheet-border) 70%, transparent 100%);
  mask-image: repeating-linear-gradient(to bottom, #000 0 1px, transparent 1px 5px);
  pointer-events: none;
}
#reader.reader-page[data-theme="confession"] .paper-stamp::before {
  inset-inline: 100% auto;
  transform: scaleX(-1);
}
#reader.reader-page .paper-stamp .paper-device { transform: scale(.65); opacity: .82 }
#reader.reader-page #gift-title {
  margin: 0 0 12px;
  font: 400 clamp(30px, 5vw, 46px)/1.25 var(--serif);
  font-synthesis: none;
  letter-spacing: .035em;
}
#reader.reader-page #gift-text {
  white-space: normal;
  font: 400 clamp(17px, 2.3vw, 19px)/1.7 var(--serif);
  font-synthesis: none;
  letter-spacing: .02em;
}
#reader.reader-page #gift-text p { margin: 0; white-space: pre-wrap }
#reader.reader-page #gift-text p + p { margin-block-start: clamp(12px, 1.7vw, 16px) }
#reader .gift-photo-status { margin-block: 16px 0; color: var(--ink-soft); font-size: 14px }
#reader.reader-page .letter-foot { justify-content: flex-end; gap: 12px; padding-top: clamp(16px, 2vw, 20px) }
#reader.reader-page .letter-rule {
  flex: 0 1 32px;
  height: 5px;
  border-block: 1px solid var(--sheet-border);
  background: none;
}
#reader.reader-page .sound-head, #reader.reader-page .sample-palette h2 { font-size: 12px; letter-spacing: .04em }
#reader.reader-page #example-themes button, #reader.reader-page #reader-actions button { min-height: 44px; font-size: 13px; letter-spacing: .035em }

#editor.editor-page { inline-size: min(100%, 1040px); margin-block-start: clamp(20px, 4vw, 52px) }
#editor .editor-head { position: relative; padding-bottom: 20px }
#editor .editor-head h1 { font-size: clamp(34px, 5vw, 56px) }
#editor .editor-head .help { margin-block-start: 8px; font-size: 14px; line-height: 1.7 }
#editor .editor-form { margin-top: 24px }
#editor .editor-grid { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 24px clamp(28px, 5vw, 64px) }
#editor .compose-block { padding-block: 20px }
#editor .compose-block:first-child { padding-block-start: 0 }
#editor .compose-head { display: block; margin-bottom: 12px }
#editor .compose-head h2 { font: 500 clamp(21px, 2.6vw, 26px)/1.3 var(--serif-jp); letter-spacing: .035em }
#editor .names label { font: 500 13px/1.4 var(--sans); letter-spacing: 0 }
#editor .names { gap: 16px }
#editor .field-note { display: block; text-align: end }
#editor .editor-aside { display: grid; gap: 16px; scroll-margin-top: 16px }
#editor .editor-preview { display: block; min-height: 0; overflow: hidden }
#editor .preview-sheet { min-height: 0; padding: 16px; background: var(--theme-paper) }
#editor .preview-sheet .paper-head { min-height: 56px; margin-bottom: 12px }
#editor #selected-paper-name { letter-spacing: .045em }
#editor .preview-to { margin: 0 0 8px; font-size: 21px }
#editor .preview-text { -webkit-line-clamp: 2; min-height: 2em; font-size: 14px }
#editor .preview-sign { margin: 8px 0 0 }
#editor .preview-sign:empty { display: none }
#editor .paper-picker legend { margin-bottom: 8px; font: 600 14px/1.5 var(--sans); letter-spacing: 0 }
#editor #theme-options { gap: 8px }
#editor .theme-choice { grid-template-columns: 36px minmax(0, 1fr); gap: 8px; padding: 4px 8px; background-color: #fffcf4 }
#editor .theme-choice:has(:checked) { background: #fbefe5 }
#editor .theme-choice:has(:checked)::after { display: none }
#editor .theme-thumb {
  width: 36px;
  aspect-ratio: 5/4;
  background-color: var(--paper-ground);
  background-image: var(--paper-motif);
  background-size: var(--paper-repeat);
}
#editor .theme-thumb::after { display: none }
#editor .theme-thumb::before { inset: 3px; border-color: #fffcf6b0 }
#editor .theme-category { font-size: 11px; letter-spacing: 0 }
#editor .theme-name { font-size: 13px; letter-spacing: 0 }
#editor #background-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px }
#editor .background-choice { display: flex; align-items: center; gap: 6px; min-height: 44px; padding-inline: 6px; grid-template-columns: none; font-size: 12px; margin: 0 }
#editor .background-choice .theme-thumb { flex: 0 0 18px; inline-size: 18px; block-size: 18px; border-radius: 50% }
#editor .background-choice[data-pattern="auto"] .theme-thumb { background: conic-gradient(#dcd7ba 0 25%, #dce6dd 0 50%, #efd9d0 0 75%, #e1eaf0 0) }
#editor .background-choice .theme-thumb::before { display: none }
#editor .form-actions { grid-column: 1 / -1; padding-block: 16px; margin: 0; border-block-start: 1px solid var(--line) }
#editor .compose-block > small { font-size: 13px; letter-spacing: 0 }
#editor .input-actions :is(button, .pick) { font-size: 14px; letter-spacing: 0 }

.attachment-feedback:not(:empty), .recording-meter {
  margin-block: 12px;
  border-inline-start: 3px solid #426950;
  background: #e8efe4;
  color: #274132;
  padding: 12px;
  font-size: 14px;
  font-weight: 550;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.attachment-feedback:is([data-state="error"], [data-state="warning"]) { border-color: #a12920; background: #f8e5dd; color: #781f19 }
.recording-meter { border-color: #9e342a; background: #fff9ed; color: #302820 }
.recording-meter[data-near-limit] { border-color: #a12920; background: #f8e5dd }
.recording-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums }
.recording-line:first-child { color: #8c271f; margin-bottom: 8px }
.recording-line label { margin: 0; padding: 0; color: inherit; font-size: 13px }
.recording-line meter { width: 45%; height: 12px; min-height: 0 }
.recording-meter progress { inline-size: 100%; block-size: 8px; accent-color: #a12920 }
#editor button#record[data-recording] { background: #8c271f; border-color: #8c271f; color: #fff8eb }
.recording-backup { display: inline-flex; align-items: center; min-height: 44px; color: #781f19; text-underline-offset: 3px }

@media (max-width: 860px) {
  #editor .editor-grid { grid-template-columns: minmax(0, 1fr) }
  #editor .editor-aside { border-top: 1px solid var(--line); padding-top: 20px }
}
@media (max-width: 640px) {
  #editor .names { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px }
  #editor .names input:not([type=file]) { font-size: 16px }
  #editor .names input::placeholder { font-size: 13px; opacity: 1 }
  #editor textarea::placeholder { opacity: 1 }
}

#editor .editor-option {
  margin: 0;
  padding: 0;
  border: 0;
  border-top: 1px solid var(--line);
}
#editor .editor-option > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding-block: 8px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 550;
  cursor: pointer;
  list-style: none;
}
#editor .editor-option > summary::-webkit-details-marker { display: none }
#editor .editor-option > summary span { margin-inline-start: auto; color: var(--ink-soft); font-size: 13px; font-weight: 400 }
#editor .editor-option > summary::after {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  margin-inline: 4px;
  border: solid var(--ink-soft);
  border-width: 0 1.5px 1.5px 0;
  transform: translateY(-2px) rotate(45deg);
}
#editor .editor-option[open] > summary::after { transform: translateY(2px) rotate(225deg) }
#editor .editor-option-body { padding-block: 8px 20px }
#editor .editor-option-body > small { display: block; margin: 8px 0 0; color: var(--ink-soft); font-size: 13px }
#editor .editor-appearance-options { display: grid; gap: 16px }
#editor .form-actions { position: relative; z-index: 2 }
#editor .form-secondary {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}
#editor .form-secondary:not(:has(button:not([hidden]))) { display: none }
#editor #preview {
  padding-inline: 16px;
  border: 1px solid #9a8e7f;
  border-radius: 2px;
  color: var(--ink);
  background: var(--paper-2);
  font-size: 14px;
  letter-spacing: 0;
  text-decoration: none;
}
#editor #save { min-height: 44px; border-radius: 2px; border-color: var(--shu-deep); background: var(--shu-deep); font-size: 14px; letter-spacing: 0 }
#editor #save:hover { background: var(--ink); border-color: var(--ink) }
#editor textarea { min-height: 136px; padding: 12px }
#editor .editor-head { padding-bottom: 12px }
#editor .editor-head h1 { font-size: clamp(32px, 5vw, 52px) }

@media (max-width: 860px) {
  #editor .editor-grid { gap: 8px }
  #editor .editor-aside { align-self: start }
}
@media (max-width: 640px) {
  body[data-panel="editor"] { overflow-x: clip }
  #editor .editor-form { margin-top: 16px }
  #editor .gift-mode { margin-block-end: 16px }
  #editor .compose-block { padding-block: 12px }
  #editor .compose-head { margin-bottom: 8px }
  #editor :is(.editor-option, textarea, .pick, #record) { scroll-margin-bottom: 88px }
  #editor .form-actions {
    position: sticky;
    bottom: 0;
    align-self: end;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 8px 0 max(8px, env(safe-area-inset-bottom));
    background: var(--paper);
    box-shadow: 0 -5px 12px #4e312915;
  }
  #editor #save, #editor #preview { width: 100%; min-width: 0; padding-inline: 8px }
}
