.weekly-app {
  max-width: 1100px;
  margin: auto;
  padding: 24px;
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', sans-serif;
}
.weekly-app [hidden] { display: none !important; }
.weekly-app button, .weekly-app input, .weekly-app select, .weekly-app textarea {
  font: inherit;
  font-size: 16px;
  min-height: 46px;
  max-width: 100%;
}
.weekly-app button {
  cursor: pointer;
  padding: 10px 16px;
  border: 1px solid #d9c9aa;
  border-radius: 8px;
  background: #fffaf0;
  color: #604820;
  touch-action: manipulation;
}
.weekly-app button:disabled { opacity: .5; cursor: wait; }
.weekly-app :is(button, input, select, textarea, summary):focus-visible {
  outline: 2px solid #886733;
  outline-offset: 3px;
}
.weekly-app input, .weekly-app select, .weekly-app textarea {
  padding: 10px;
  border: 1px solid #d9c9aa;
  border-radius: 6px;
  background: #fff;
  color: #292620;
  min-width: 0;
}
.weekly-app label { display: flex; gap: 8px; align-items: center; }
.weekly-app .section { margin-bottom: 20px; min-width: 0; }
.weekly-app .toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.week-picker { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 16px; align-items: end; }
.week-picker label { flex-direction: column; align-items: stretch; }
.week-picker input, .week-picker select { width: 100%; }
#publication { grid-column: 1 / -1; color: var(--text-muted); font-size: 14px; }
#signs { display: flex; gap: 8px; flex-wrap: wrap; margin: 24px 0; }
#signs button[aria-pressed=true], .weekly-app .primary-action { background: #755b32; color: white; }
.weekly-app .mobile-sign-picker { display: none; }
.cards { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; }
.cards label { display: block; }
.cards select { width: 100%; margin: 5px 0; }
.metadata { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 24px; }
.metadata label { flex-direction: column; align-items: stretch; }
#previous { grid-column: 1 / -1; margin: 0; color: var(--text-muted); font-size: 14px; }
.reading-section { padding: 24px 0; border-bottom: 1px solid #e8decc; }
.reading-section:first-child { padding-top: 0; }
.reading-section:last-child { border-bottom: 0; padding-bottom: 0; }
.reading-section header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.reading-section header button { flex-shrink: 0; }
.reading-section textarea { width: 100%; min-height: 260px; margin-top: 16px; line-height: 1.9; resize: vertical; }
.reading-section p, .preview-text { white-space: pre-wrap; overflow-wrap: anywhere; font-family: Georgia, 'Songti SC', serif; line-height: 2.1; }
#status, #warnings, #stale, #action-feedback { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.7; }
#warnings, #stale { color: #986219; }
#status.error, #action-feedback.error { color: #a63832; }
#stale:empty, #warnings:empty, #status:empty, #action-feedback:empty { display: none; }
#template-issues { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.template-notes summary { cursor: pointer; min-height: 44px; padding: 10px 0; }
.weekly-app h2, .weekly-app h3 { font-family: Georgia, 'Songti SC', serif; }
#unpublish { background: transparent; color: var(--text-muted); }
.draft-actions { position: sticky; bottom: 0; z-index: 3; padding: 16px; border: 1px solid #dfd4bf; border-radius: 12px; background: #fffdf9; box-shadow: 0 -3px 16px #4b351010; }
#action-feedback { display: none; }
#preview-dialog { max-width: 800px; width: 90%; max-height: 85vh; overflow: auto; overscroll-behavior: contain; border: 1px solid #dfd4bf; border-radius: 12px; padding: 0 30px 30px; background: #faf7ef; color: #39352e; }
#preview-dialog::backdrop { background: #0006; }
.preview-toolbar { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; background: #faf7ef; border-bottom: 1px solid #dfd4bf; }
.preview-sign { padding: 32px 12px; border-bottom: 1px solid #ddd; text-align: center; overflow-wrap: anywhere; }
.preview-text { text-align: left; }

@media (max-width: 700px) {
  .weekly-app { padding: 20px 12px calc(184px + env(safe-area-inset-bottom)); }
  .weekly-app .header { margin-bottom: 24px; text-align: left; }
  .weekly-app .header a { display: inline-flex; align-items: center; min-height: 44px; }
  .weekly-app .header h1 { font-size: 24px; margin: 12px 0 8px; }
  .weekly-app .header p { margin: 0; color: var(--text-muted); font-size: 14px; }
  .weekly-app .section { padding: 16px; margin-bottom: 16px; }
  .week-picker { grid-template-columns: minmax(0, 1fr) auto; gap: 12px; }
  #current-week { grid-column: 1 / -1; }
  .sign-navigation { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 10px 0; margin-bottom: 12px; }
  #signs { display: none; }
  .weekly-app .mobile-sign-picker { display: flex; gap: 16px; color: var(--text-muted); }
  #sign-select { flex: 1; width: 0; }
  .cards { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .cards > div { display: grid; grid-template-columns: 64px minmax(0, 1fr) minmax(76px, .8fr); align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid #eee5d6; }
  .cards label { font-size: 14px; }
  .cards select { margin: 0; padding: 8px; }
  .metadata { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .generate-actions { display: grid !important; grid-template-columns: minmax(0, 1fr); }
  .generate-actions button { width: 100%; }
  .reading-section { scroll-margin-top: 80px; }
  .reading-section textarea { min-height: 42vh; min-height: 42dvh; padding: 12px; }
  .publication-actions .toolbar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .draft-actions { position: fixed; left: 0; right: 0; bottom: 0; border-radius: 0; border-width: 1px 0 0; padding: 10px max(12px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  .draft-actions .toolbar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #action-feedback { display: block; max-height: 4.8em; overflow-y: auto; margin: 0 0 8px; font-size: 13px; }
  #preview-dialog { width: 100%; max-width: none; height: 100vh; height: 100dvh; max-height: 100vh; max-height: 100dvh; margin: 0; border: 0; border-radius: 0; padding: 0 20px calc(24px + env(safe-area-inset-bottom)); }
  .preview-toolbar { padding-top: max(12px, env(safe-area-inset-top)); }
  .preview-sign { padding: 28px 0; }
}
/* The on-screen keyboard needs the available height more than the draft toolbar. */
@media (max-width: 700px) and (max-height: 500px) {
  .weekly-app:focus-within .draft-actions { position: static; border-radius: 8px; }
  .weekly-app:focus-within .sign-navigation { position: static; }
}
