:root {
  color-scheme: light;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: #202b26;
  background: #f5f7f3;
  --muted: #56645d;
  --border: #dce3dc;
  --accent: #176749;
  --accent-dark: #0d5339;
  --paper-ink: #25342c;
}
* { box-sizing: border-box; }
body { margin: 0; }
button, input, select, textarea { font: inherit; }
button {
  min-height: 44px; padding: 8px 13px; border: 1px solid var(--border);
  border-radius: 9px; background: white; color: inherit; cursor: pointer;
  font-weight: 600; transition: background .15s, border-color .15s;
}
button:hover { background: #eef3ee; border-color: #b7c9bf; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid #35a078; outline-offset: 2px;
}
button:disabled { opacity: .45; cursor: default; }
.primary { background: var(--accent); border-color: var(--accent); color: white; }
.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.danger { color: #9b332d; }
.top {
  padding: 13px max(22px, calc((100vw - 1520px) / 2)); background: #1d2c25;
  color: #fff; display: flex; gap: 16px; align-items: center; justify-content: space-between;
}
.brand, .top-actions, .project-actions, .panel-head, .preview-head, .dialog-head {
  display: flex; gap: 12px; align-items: center;
}
.brand strong { font-size: 1.2rem; white-space: nowrap; }
.brand strong span { color: #bccec1; font-size: .8rem; letter-spacing: .13em; margin-left: 5px; }
.mark { width: 26px; height: 26px; border: 2px solid #aee3bf; border-radius: 4px; position: relative; }
.mark::after { content: ""; position: absolute; inset: 5px -5px -5px 5px; border: 2px solid #aee3bf; border-radius: 4px; }
.dark-button { color: #fff; border-color: #52685b; background: transparent; }
.dark-button:hover { background: #34473c; }
main { max-width: 1564px; margin: auto; padding: 28px 22px; }
.project { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.project p { margin: 0 0 5px; font-size: .875rem; color: var(--muted); }
.project h1 { margin: 0; font-size: clamp(1.55rem, 3vw, 2.25rem); letter-spacing: -.035em; overflow-wrap: anywhere; }
#save-status { color: var(--muted); font-size: .875rem; }
.workspace { display: grid; grid-template-columns: minmax(190px, 230px) minmax(0, 1fr) minmax(254px, 285px); gap: 13px; align-items: start; }
.sheets, .inspector, .preview { min-width: 0; background: white; border: 1px solid var(--border); border-radius: 14px; }
.sheets, .inspector { padding: 13px; }
.panel-head, .preview-head, .dialog-head { justify-content: space-between; }
h2 { font-size: 1rem; margin: 0; }
.panel-head h2 span { margin-left: 4px; color: var(--muted); font-weight: 400; }
.icon { width: 44px; padding: 0; font-size: 1.35rem; }
#sheet-list { list-style: none; margin: 12px 0; padding: 0; display: grid; gap: 5px; max-height: 55vh; overflow: auto; }
.sheet-item { width: 100%; display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 9px; text-align: left; align-items: center; border-color: transparent; padding: 8px; }
.sheet-item[aria-current="true"] { background: #e5f2e8; border-color: #b8d8c4; color: #164f39; }
.sheet-item span { overflow-wrap: anywhere; font-size: .91rem; }
.sheet-item .number { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; text-align: center; }
.import { border-style: dashed; width: 100%; text-align: left; }
.import span { display: block; margin-top: 2px; font-size: .8rem; font-weight: 400; color: var(--muted); }
.preview { overflow: hidden; }
.preview-head { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.preview-head span { font-size: .875rem; color: var(--muted); }
.preview-area {
  display: grid; justify-items: center; align-items: center; padding: clamp(13px, 3vw, 40px);
  min-height: clamp(320px, 46vw, 660px); background-color: #edf0eb;
  background-image: radial-gradient(#bdc8be 1px, transparent 1px); background-size: 17px 17px;
}
.sheet { background: white; color: var(--paper-ink); width: 100%; aspect-ratio: 297 / 210; display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; min-width: 0; min-height: 0; padding: 4.2% 5%; overflow: hidden; }
.preview-area .sheet { box-shadow: 0 6px 22px #1d2c2520; container-type: inline-size; }
.preview-area .sheet.portrait { max-width: 75%; aspect-ratio: 210 / 297; }
.sheet-heading { padding-bottom: 2%; }
.sheet-heading small { font-size: clamp(8px, 1.9cqw, 15px); color: #536359; overflow-wrap: anywhere; }
.sheet-heading h3 { margin: .15em 0 0; font-size: clamp(12px, 4cqw, 29px); line-height: 1.15; overflow-wrap: anywhere; }
.sheet-art { display: grid; place-items: center; min-height: 0; overflow: hidden; }
.sheet-art img, .sheet-art canvas { width: 100%; height: 100%; min-height: 0; object-fit: contain; }
.marked-art { container-type: size; }
.art-stage { position: relative; width: min(100cqw, calc(100cqh * var(--ratio))); aspect-ratio: var(--ratio); }
.art-stage > img, .art-stage > canvas { position: absolute; inset: 0; }
.art-pin, .key-pin {
  display: inline-grid; place-items: center; width: 1.55em; height: 1.55em;
  color: white; background: #176749; border: 1px solid white; border-radius: 50%; font-weight: 700;
}
.art-pin {
  position: absolute; transform: translate(-50%, -50%); font-size: clamp(9px, 2.2cqw, 16px);
  min-height: 0; padding: 0; pointer-events: none;
}
.sheet-keys { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 8px; margin-bottom: 3px; }
.sheet-key { display: flex; gap: .35em; align-items: baseline; overflow-wrap: anywhere; }
.key-pin { flex: none; }
.placing .art-stage { cursor: crosshair; }
#mark-editor { padding-top: 8px; border-top: 1px solid var(--border); }
#mark-editor h3, #ai-result h3 { font-size: .95rem; margin: 0 0 5px; }
.mark-row { display: flex; gap: 4px; align-items: end; margin-bottom: 5px; }
.mark-row label { flex: 1 1 0; }
.mark-row button { flex: none; min-height: 42px; }
.mark-row .icon { width: 36px; }
.hint { color: var(--muted); font-size: .875rem; }
#ai-sheets { border: 1px solid var(--border); border-radius: 8px; margin: 0; max-height: 160px; overflow: auto; }
#ai-selection { display: grid; gap: 3px; }
#ai-selection label { display: flex; align-items: center; gap: 8px; }
#ai-selection input { width: 19px; min-height: 24px; flex: none; }
#ai-proposals { padding-inline-start: 22px; }
#ai-proposals li { margin-bottom: 9px; }
.proposal-preview { padding: 7px; background: #edf0eb; }
.proposal-preview .sheet { container-type: inline-size; }
.proposal-preview .portrait { width: 68%; aspect-ratio: 210 / 297; margin-inline: auto; }
.sheet-art .empty { font-size: clamp(8px, 2.5cqw, 16px); color: var(--muted); }
.sheet-note { margin: .35em 0; font-size: clamp(8px, 2cqw, 14px); white-space: pre-wrap; overflow-wrap: anywhere; }
.sheet-foot { border-top: 1px solid #a9b5ac; padding-top: 1.2%; font-size: clamp(8px, 1.9cqw, 13px); display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px; overflow-wrap: anywhere; }
#inspector-fields, .dialog-inner { display: grid; gap: 13px; }
#inspector-fields { margin-top: 13px; }
#inspector-fields[hidden] { display: none; }
label { display: grid; gap: 5px; min-width: 0; font-size: .875rem; font-weight: 600; }
input, select, textarea { width: 100%; padding: 9px; border: 1px solid #cdd8d0; background: #fff; border-radius: 8px; color: #202b26; min-height: 42px; font-weight: 400; }
textarea { resize: vertical; }
.field-row { display: grid; grid-template-columns: 1fr 1.65fr; gap: 7px; }
.file-row { display: grid; gap: 5px; }
.file-row span { color: var(--muted); font-size: .875rem; overflow-wrap: anywhere; }
.sheet-actions, .dialog-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.sheet-actions button { flex: 1; padding-inline: 7px; }
dialog { width: min(520px, calc(100% - 30px)); max-height: calc(100% - 30px); border: 1px solid var(--border); border-radius: 15px; padding: 0; color: inherit; }
dialog::backdrop { background: #1222199e; }
.dialog-inner { padding: 18px; }
.dialog-inner p, #checklist { margin: 0; }
#checklist { padding-left: 20px; }
#notice { position: fixed; z-index: 2; bottom: 16px; left: 16px; right: 16px; width: fit-content; max-width: calc(100% - 32px); padding: 12px 16px; color: white; background: #1d2c25; border-radius: 9px; }
#print-area { display: none; }
@media (max-width: 1100px) {
  .workspace { grid-template-columns: 180px minmax(0, 1fr); }
  .inspector { grid-column: 2; }
}
@media (max-width: 620px) {
  .top { padding: 10px 12px; flex-wrap: wrap; }
  .top-actions { gap: 6px; }
  main { padding: 15px 12px; }
  .project { flex-wrap: wrap; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .inspector { grid-column: auto; }
  #sheet-list { max-height: 210px; }
  .preview-area { min-height: 240px; }
}
@media (prefers-reduced-motion: reduce) { button { transition: none; } }
@page a4l { size: A4 landscape; margin: 0; }
@page a4p { size: A4 portrait; margin: 0; }
@page a3l { size: A3 landscape; margin: 0; }
@page a3p { size: A3 portrait; margin: 0; }
@media print {
  html, body { margin: 0; background: white; }
  body > :not(#print-area) { display: none !important; }
  #print-area { display: block; }
  #print-area .sheet { break-after: page; padding: 10mm 12mm; aspect-ratio: auto; print-color-adjust: exact; }
  #print-area .sheet:last-child { break-after: auto; }
  .sheet.a4.landscape { page: a4l; width: 297mm; height: 209.8mm; }
  .sheet.a4.portrait { page: a4p; width: 210mm; height: 296.8mm; }
  .sheet.a3.landscape { page: a3l; width: 420mm; height: 296.8mm; }
  .sheet.a3.portrait { page: a3p; width: 297mm; height: 419.8mm; }
  .sheet-heading h3 { font-size: 23pt; }
  .sheet-heading small, .sheet-note, .sheet-foot { font-size: 10pt; }
  .art-pin { font-size: 10pt; }
  .sheet-art .empty { font-size: 12pt; }
}
