:root {
  color-scheme: light;
  --paper: #f4efe4;
  --ink: #332b23;
  --muted: #6f6253;
  --rule: #c8b9a4;
  --accent: #783e33;
  --chinese: "Year Print", "Songti TC", "Noto Serif CJK TC", serif;
  --editorial: "Ribbon Type", "Courier New", Courier, var(--chinese);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--editorial);
  font-synthesis: none;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 360px; }
button, input, textarea { font: inherit; }
button { color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
button, input, textarea { -webkit-tap-highlight-color: transparent; }

.page { width: min(1320px, calc(100% - 100px)); margin: 0 auto; }
.masthead {
  position: relative;
  text-align: center;
  padding: 20px 0 19px;
  margin: 0 0 23px;
  border-bottom: 3px double var(--rule);
}
.masthead h1 {
  margin: 0;
  font-size: clamp(2rem, 4.65vw, 4.15rem);
  line-height: 1.03;
  font-weight: 400;
  letter-spacing: 0.055em;
  color: #342820;
  text-shadow: 0.28px 0.18px #3525143a;
}
.masthead-spacer { block-size: 1.34375rem; margin-top: 9px; }

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 0.78fr) minmax(0, 1.22fr);
  align-items: start;
  gap: clamp(25px, 4vw, 58px);
  padding-bottom: 36px;
}
.editor { min-width: 0; }
.collection-notice { margin: 0 0 16px; color: var(--muted); font: 0.82rem/1.55 var(--chinese); }
.editor-section { padding: 0 0 16px; margin: 0 0 16px; border-bottom: 1px solid var(--rule); }
.finish-section { padding-bottom: 13px; }
.editor-section:last-child { border-bottom: 0; margin-bottom: 0; }
.heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 0 12px; }
h2 { margin: 0; font: 400 1.12rem/1.25 var(--chinese); letter-spacing: 0.045em; }
.paper-heading { margin-top: 15px; }
.paper-palette .swatch { aspect-ratio: 1.35; border-radius: 2px; background-size: cover; }
.detail { color: var(--muted); font-size: 0.85rem; }
.palette { display: flex; flex-wrap: wrap; gap: clamp(7px, 0.8vw, 13px); padding: 2px 2px 1px; }
.swatch {
  width: clamp(31px, 3.08vw, 44px);
  aspect-ratio: 1;
  padding: 0;
  background: var(--swatch);
  border: 1px solid #48312444;
  border-radius: 50%;
  box-shadow: inset 0 1px 3px #fff6;
}
.swatch[aria-pressed="true"] { outline: 1px solid var(--ink); outline-offset: 3px; }
.swatch:hover { box-shadow: inset 0 0 0 2px #fff9; }
.swatch:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.keywords { display: flex; flex-wrap: wrap; gap: 7px; }
.keyword {
  border-radius: 3px;
  padding: 5px 9px;
  min-height: 30px;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  border: 1px solid #bfaf98;
  background: #fcf7ed80;
  font-weight: 400;
  font-size: 0.89rem;
}
.keyword[aria-pressed="true"] { color: #fff5e8; background: #63483c; border-color: #63483c; }
.keyword:hover { border-color: var(--accent); }
.add-form { display: flex; gap: 8px; margin-top: 11px; }
.add-form input, .memory-text {
  border: 1px solid #cbbb9f;
  background: #fffcf36b;
  border-radius: 3px;
  color: var(--ink);
}
.add-form input { flex: 1; min-width: 0; padding: 8px 10px; font-size: 0.9rem; }
.add-form input::placeholder, .memory-text::placeholder { color: #786d5e; opacity: 1; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 6px 13px;
  border: 1px solid #b5a58d;
  border-radius: 3px;
  background: #f9f3e8;
  font-weight: 400;
  white-space: nowrap;
  font-size: 0.9rem;
}
.button:hover { background: #ece1cf; border-color: #85715b; }
.button svg, .memory button svg { width: 17px; height: 17px; stroke: currentColor; stroke-width: 1.6; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.primary { background: #47362d; color: #fff7e9; border-color: #47362d; }
.primary:hover { background: #63483c; }
.danger { background: #783e33; color: #fff7e9; border-color: #783e33; }
.danger:hover { background: #8b4b3d; color: #fff7e9; }

.memories { display: grid; gap: 6px; }
.memory {
  display: grid;
  grid-template-columns: 26px minmax(5.3em, 28%) minmax(0, 1fr) 26px;
  align-items: center;
  gap: 6px;
  min-height: 43px;
  background: #fffaf143;
  border: 1px solid #d5c7b4;
  border-radius: 4px;
  padding: 4px 5px;
}
.memory:focus-within { border-color: #a77964; background: #fff9f0; }
.memory.dragging { opacity: 0.48; }
.memory.drop-before { box-shadow: inset 0 2px var(--accent); }
.memory.drop-after { box-shadow: inset 0 -2px var(--accent); }
.memory label { font-size: 0.9rem; font-weight: 400; overflow-wrap: anywhere; }
.memory-text { font-size: 0.92rem; font-weight: 400; width: 100%; min-height: 31px; max-height: 180px; padding: 5px 7px; line-height: 1.25; resize: vertical; }
.memory button { display: grid; place-items: center; width: 26px; height: 31px; border: 0; border-radius: 3px; background: transparent; padding: 0; color: #765e4d; }
.memory button:hover { background: #efe3d2; color: var(--accent); }
.memory .handle { cursor: grab; }
.memory .handle:active { cursor: grabbing; }
.empty, .form-message, .status { margin: 10px 0 0; font-size: 0.91rem; color: var(--muted); }

.preview {
  --preview-size: min(100%, max(420px, calc(100svh - 238px)));
  position: sticky;
  top: 14px;
  min-width: 0;
}
.viewfinder {
  width: var(--preview-size);
  margin-inline: auto;
  background: #e4d9c7;
  border: 1px solid #9f8b72;
  border-radius: 4px;
  padding: 4px;
  box-shadow: 0 7px 19px #49362115;
}
.viewfinder canvas { display: block; width: 100%; height: auto; }
.toolbar { width: var(--preview-size); display: flex; gap: 8px; margin: 11px auto 0; }
.toolbar .icon-button { min-width: 41px; padding-inline: 9px; }
#save-options { margin-left: auto; }
.status { text-align: right; }

.masthead h1, h2, .detail, .memory label { transform: scaleY(0.93); }

dialog {
  color: var(--ink);
  background: var(--paper);
  border: 1px solid #a99477;
  border-radius: 4px;
}
dialog::backdrop { background: #30271f99; }
.confirm { width: min(415px, calc(100% - 32px)); padding: 25px; }
.confirm p { font-size: 0.94rem; line-height: 1.65; }
.dialog-actions { display: flex; justify-content: end; gap: 8px; }
.export-dialog { width: min(730px, calc(100% - 30px)); padding: 18px; box-shadow: 0 15px 50px #2f211d42; }
.export-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.export-kinds { display: flex; gap: 2px; min-inline-size: 0; margin: 0; padding: 2px; border: 1px solid var(--rule); border-radius: 4px; }
.export-kinds label { position: relative; }
.export-kinds input { position: absolute; inline-size: 1px; block-size: 1px; opacity: 0; }
.export-kinds span { display: block; padding: 6px 11px; border-radius: 2px; font-size: 0.9rem; cursor: pointer; }
.export-kinds input:checked + span { background: #63483c; color: #fff5e8; }
.export-kinds input:focus-visible + span, .export-preview:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.export-preview { max-height: 61dvh; overflow: auto; padding: 10px; background: #e7ddcd; border: 1px solid var(--rule); border-radius: 3px; scrollbar-gutter: stable both-edges; }
.export-preview canvas { display: block; width: min(100%, 400px, 50dvh); height: auto; margin: 0 auto; box-shadow: 0 3px 13px #4936212d; }
.export-preview[data-kind="scene"] canvas { width: min(100%, 540px, 57dvh); }
.export-footer { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.export-footer .status { margin: 0 auto 0 0; text-align: start; }
.export-footer button:disabled { opacity: 0.6; cursor: default; }
.full { width: 100vw; height: 100dvh; max-width: none; max-height: none; padding: 0; border: 0; border-radius: 0; margin: 0; }
.full[open] { display: grid; grid-template-rows: auto minmax(0, 1fr); }
.full-toolbar { padding: 8px clamp(12px, 3vw, 40px); display: flex; justify-content: end; border-bottom: 1px solid var(--rule); }
.full-scroll { overflow: auto; background: #cfc1ad; }
.full-scroll canvas { display: block; width: min(100%, calc(100dvh - 57px), 1200px); height: auto; margin: 0 auto; }

@media (min-width: 780px) and (max-width: 1060px) {
  .page { width: calc(100% - 46px); }
  .workbench { gap: 22px; grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr); }
}
@media (max-width: 779px) {
  .page { width: calc(100% - 32px); }
  .masthead { padding-top: 23px; }
  .workbench { grid-template-columns: 1fr; }
  .preview { position: static; grid-row: 1; }
}

