@page { size: portrait; margin: 14mm; }
:root {
  color-scheme: light;
  --ink: #24231f;
  --muted: #666258;
  --paper: #fffdf8;
  --canvas: #f1eee6;
  --line: #d8d2c5;
  --accent: #b7432d;
  --accent-dark: #8b301f;
  --teal: #315f5b;
  --focus: #1769aa;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
}
* { box-sizing: border-box; }
html { background: var(--canvas); }
body { min-width: 320px; margin: 0; color: var(--ink); background: radial-gradient(circle at 8% 4%, #c64d3414, transparent 28rem), linear-gradient(180deg, #faf8f2, var(--canvas) 28rem); font-size: 16px; line-height: 1.5; }
button, input, textarea { font: inherit; }
button, a, label { -webkit-tap-highlight-color: transparent; }
button, a, input, textarea { touch-action: manipulation; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0.6rem; font-size: clamp(2rem, 4vw, 3rem); line-height: 1.05; letter-spacing: -0.045em; }
h2 { margin-bottom: 0; font-size: clamp(1.4rem, 3vw, 1.8rem); line-height: 1.2; letter-spacing: -0.025em; }
h3 { margin-bottom: 0.5rem; font-size: 1.25rem; }
.app-header { display: flex; gap: 1rem; align-items: flex-start; width: min(1120px, calc(100% - 2rem)); margin: 0 auto; padding: 2.5rem 0 1.75rem; }
.brand-mark { display: grid; flex: 0 0 auto; width: 3.25rem; height: 3.25rem; place-items: center; border-radius: 1rem 1rem 1rem 0.25rem; color: white; background: var(--accent); font-weight: 800; letter-spacing: -0.04em; }
.header-copy { flex: 1; }
.eyebrow { margin-bottom: 0.5rem; color: var(--accent-dark); font-size: 12px; font-weight: 750; letter-spacing: 0.11em; text-transform: uppercase; }
.intro { max-width: 40rem; margin-bottom: 0; color: var(--muted); line-height: 1.6; }
.projects-link { display: inline-flex; min-height: 44px; align-items: center; padding: 0.5rem; color: var(--teal); font-size: 14px; text-underline-offset: 4px; white-space: nowrap; }
.projects-link:hover { color: var(--accent-dark); }
.app-shell { width: min(1120px, calc(100% - 2rem)); margin: 0 auto 3rem; }
.control-panel, .print-sheet { border: 1px solid #82796338; border-radius: 1rem; background: var(--paper); box-shadow: 0 12px 34px #2f2a1f0d; }
.control-panel { margin-bottom: 1.25rem; padding: clamp(1rem, 3vw, 1.5rem); }
.section-heading, .storyboard-heading { display: flex; gap: 1rem; align-items: flex-end; justify-content: space-between; }
.privacy-note, .story-count { margin: 0; color: var(--muted); font-size: 14px; }
.privacy-note { text-align: right; }
.privacy-note::before { content: "●"; margin-right: 0.4rem; color: var(--teal); }
.toolbar { display: grid; grid-template-columns: minmax(13rem, 1fr) auto auto; gap: 1rem; align-items: start; margin-top: 1.25rem; padding-top: 1.25rem; border-top: 1px solid var(--line); }
.file-control { padding-top: 1.8rem; }
.field-help { max-width: 25rem; margin: 0.5rem 0 0; color: var(--muted); font-size: 13px; }
.primary-button, .secondary-button, .print-button, .move-button, .remove-button { display: inline-flex; min-width: 44px; min-height: 44px; align-items: center; justify-content: center; border-radius: 0.5rem; font-weight: 700; cursor: pointer; }
.primary-button, .print-button { border: 1px solid var(--accent); padding: 0.65rem 1rem; color: white; background: var(--accent); }
.primary-button:hover:not(:disabled), .print-button:hover:not(:disabled) { border-color: var(--accent-dark); background: var(--accent-dark); }
.secondary-button { border: 1px solid var(--line); padding: 0.65rem 1rem; color: var(--ink); background: white; }
.secondary-button:hover:not(:disabled) { border-color: var(--teal); background: #edf6f4; }
.print-button { margin-top: 1.8rem; }
button:disabled { cursor: not-allowed; }
.print-button:disabled, .primary-button:disabled, .secondary-button:disabled { border-color: #d3cec2; color: #686357; background: #e8e3d9; }
.orientation-control { min-width: 15rem; margin: 0; padding: 0; border: 0; }
.orientation-control legend { margin-bottom: 0.5rem; padding: 0; color: var(--muted); font-size: 14px; font-weight: 700; }
.segmented-control { display: grid; grid-template-columns: 1fr 1fr; padding: 3px; border: 1px solid var(--line); border-radius: 0.65rem; background: #ebe7dc; }
.segmented-control label { position: relative; cursor: pointer; }
.segmented-control input { position: absolute; left: 0.65rem; top: 50%; width: 1rem; height: 1rem; margin: 0; transform: translateY(-50%); accent-color: var(--teal); cursor: pointer; }
.segmented-control span { display: flex; min-height: 44px; align-items: center; justify-content: center; border-radius: 0.4rem; padding: 0.5rem 0.75rem 0.5rem 2rem; font-size: 14px; font-weight: 700; }
.segmented-control input:checked + span { color: var(--teal); background: white; box-shadow: 0 2px 7px #2f2a1f1f; }
.segmented-control input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.live-status { min-height: 1.5em; margin: 1rem 0 0; color: var(--teal); font-size: 14px; }
.message-panel { margin-top: 1rem; border-left: 4px solid var(--accent); padding: 0.85rem 1rem; color: #6f2518; background: #fff0eb; overflow-wrap: anywhere; }
.message-panel h3 { font-size: 16px; }
.message-panel ul { margin: 0; padding-left: 1.25rem; font-size: 14px; }
.print-sheet { min-height: 28rem; padding: clamp(1rem, 3vw, 2rem); }
.storyboard-heading { margin-bottom: 1.25rem; padding-bottom: 1rem; border-bottom: 2px solid var(--ink); }
.story-count { white-space: nowrap; }
.sequence-help { margin-bottom: 1.25rem; color: var(--muted); font-size: 14px; }
.empty-state { display: grid; justify-items: center; max-width: 34rem; margin: 3rem auto 2rem; text-align: center; }
.empty-state p { max-width: 29rem; color: var(--muted); line-height: 1.6; }
.empty-state .empty-note { max-width: 24rem; margin: 1rem 0 0; font-size: 13px; }
.empty-illustration { position: relative; width: 9.5rem; height: 6.5rem; margin-bottom: 1.4rem; }
.empty-illustration span { position: absolute; width: 5.2rem; height: 4rem; border: 2px solid var(--ink); border-radius: 0.3rem; background: #e9c88e; box-shadow: 0 5px 0 #23231f14; }
.empty-illustration span::after { content: ""; position: absolute; inset: 0.6rem; background: linear-gradient(145deg, transparent 48%, var(--teal) 49% 70%, transparent 71%); }
.empty-illustration span:nth-child(1) { left: 0; top: 1rem; transform: rotate(-8deg); }
.empty-illustration span:nth-child(2) { left: 2.1rem; background: #b9d1ca; transform: rotate(2deg); }
.empty-illustration span:nth-child(3) { right: 0; top: 1.3rem; background: #d99b87; transform: rotate(9deg); }
.storyboard { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.15rem; margin: 0; padding: 0; list-style: none; }
body[data-orientation="landscape"] .storyboard { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.story-card { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 0.5rem; background: white; }
.story-card[draggable="true"] { cursor: grab; }
.story-card.dragging { opacity: 0.45; }
.story-card.drop-before { box-shadow: 0 -5px 0 var(--accent); }
.story-card.drop-after { box-shadow: 0 5px 0 var(--accent); }
.image-wrap { position: relative; display: grid; place-items: center; overflow: hidden; border-bottom: 1px solid var(--line); background: #eeeae1; }
.image-wrap img { display: block; width: 100%; height: 17rem; object-fit: contain; }
.sequence-number { position: absolute; top: 0.75rem; left: 0.75rem; display: grid; width: 2rem; height: 2rem; place-items: center; border: 2px solid white; border-radius: 50%; color: white; background: var(--ink); font-size: 14px; font-weight: 800; box-shadow: 0 2px 8px #0003; }
.card-content { padding: 1rem; }
.card-meta { display: flex; gap: 0.7rem; justify-content: space-between; margin-bottom: 0.85rem; color: var(--muted); font-size: 12px; }
.file-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drag-hint { flex: 0 0 auto; }
.caption-label { display: block; margin-bottom: 0.4rem; font-size: 14px; font-weight: 700; cursor: text; }
.caption-input { display: block; width: 100%; min-height: 6rem; resize: vertical; overflow-wrap: anywhere; border: 1px solid #aaa394; border-radius: 0.35rem; padding: 0.7rem; color: var(--ink); background: #fffefb; line-height: 1.5; cursor: text; }
.caption-input::placeholder { color: #716d64; opacity: 1; }
.caption-input:hover { border-color: #837d70; }
.print-caption { display: none; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.card-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.85rem; }
.move-button, .remove-button { border: 1px solid var(--line); padding: 0.5rem 0.65rem; color: var(--ink); background: #f7f4ec; font-size: 14px; }
.move-button:hover:not(:disabled) { border-color: var(--teal); color: var(--teal); background: #edf6f4; }
.move-button:disabled { color: #817b70; background: #f4f2ec; }
.remove-button { margin-left: auto; border-color: transparent; color: var(--accent-dark); background: transparent; }
.remove-button:hover { background: #fff0eb; }
.session-note { margin: 1rem 0 0; color: var(--muted); font-size: 13px; text-align: center; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; overflow: hidden !important; clip-path: inset(50%) !important; white-space: nowrap !important; }
[hidden] { display: none !important; }
@media (max-width: 850px) {
  .toolbar { grid-template-columns: 1fr 1fr; }
  .file-control { grid-column: 1 / -1; padding-top: 0; }
  .print-button { width: 100%; }
  body[data-orientation="landscape"] .storyboard { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .app-header, .app-shell { width: calc(100% - 1rem); }
  .app-header { flex-wrap: wrap; gap: 0.75rem; padding-top: 1rem; }
  .brand-mark { width: 2.75rem; height: 2.75rem; }
  .header-copy { flex-basis: calc(100% - 3.5rem); }
  .projects-link { margin-left: 3rem; }
  .section-heading { flex-direction: column; align-items: flex-start; }
  .privacy-note { text-align: left; }
  .privacy-note br { display: none; }
  .toolbar, .storyboard, body[data-orientation="landscape"] .storyboard { grid-template-columns: 1fr; }
  .orientation-control { min-width: 0; }
  .print-button { margin-top: 0; }
  .image-wrap img { height: min(70vw, 21rem); }
  .drag-hint { display: none; }
  .empty-state { margin: 2rem auto 1rem; }
}
@media (prefers-reduced-motion: no-preference) {
  button { transition: border-color 150ms ease, background-color 150ms ease; }
}
@media print {
  html, body { background: white !important; }
  body { min-width: 0; margin: 0; color: #111; }
  .app-header, .control-panel, .screen-only, .session-note, noscript, .caption-help { display: none !important; }
  .app-shell { width: auto; margin: 0; }
  .print-sheet { min-height: 0; padding: 0; border: 0; border-radius: 0; background: white; box-shadow: none; }
  .storyboard-heading { margin-bottom: 5mm; padding-bottom: 3mm; }
  .storyboard-heading h2 { font-size: 18pt; }
  .story-count { color: #333; font-size: 10pt; }
  .storyboard, body[data-orientation="landscape"] .storyboard {
    display: block;
    width: auto;
    overflow: visible;
    font-size: 11pt;
    break-inside: auto;
    page-break-inside: auto;
  }
  .story-card, body[data-orientation="landscape"] .story-card {
    display: block;
    width: auto;
    height: auto;
    max-height: none;
    margin: 0 0 5mm;
    overflow: visible;
    break-inside: auto;
    page-break-inside: auto;
    border: 0.3mm solid #aaa;
    border-radius: 0;
    box-shadow: none;
    font-size: 11pt;
    box-decoration-break: slice;
    -webkit-box-decoration-break: slice;
  }
  .story-card > article, .card-content {
    display: block;
    height: auto;
    max-height: none;
    overflow: visible;
    break-inside: auto;
    page-break-inside: auto;
  }
  .image-wrap {
    display: block;
    overflow: visible;
    background: #f4f4f4;
    break-inside: avoid;
    page-break-inside: avoid;
    break-after: avoid;
    page-break-after: avoid;
  }
  .image-wrap img { width: 100%; height: 60mm; object-fit: contain; }
  body[data-orientation="landscape"] .image-wrap img { height: 48mm; }
  .sequence-number { top: 3mm; left: 3mm; width: 7mm; height: 7mm; border-width: 0.5mm; font-size: 9pt; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .card-content { padding: 4mm; }
  .caption-input, .caption-label { display: none; }
  .print-caption {
    display: block;
    height: auto;
    min-height: 1.2em;
    max-height: none;
    overflow: visible;
    font-size: 11pt;
    line-height: 1.35;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    break-inside: auto;
    page-break-inside: auto;
    orphans: 2;
    widows: 2;
  }
}

/* Named external page rules keep orientation compatible with the strict CSP. */
@page photo-portrait { size: portrait; margin: 14mm; }
@page photo-landscape { size: landscape; margin: 14mm; }
@media print {
  body[data-orientation="portrait"] { page: photo-portrait; }
  body[data-orientation="landscape"] { page: photo-landscape; }
}
