/* WrapTexts - plain CSS, no build step. */
:root {
  --ink: #17171c;
  --muted: #5d5d68;
  --line: #e3e3ea;
  --surface: #f6f6f9;
  --accent: #c93f1d;
  --accent-strong: #a93216;
  --accent-soft: #fdebe5;
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: Georgia, "Times New Roman", serif;
}
*, *::before, *::after { box-sizing: border-box; }
html { scroll-padding-top: 4.5rem; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: #fbfbfd; color: var(--ink); font-family: var(--font-sans);
  line-height: 1.5; -webkit-font-smoothing: antialiased; overflow-x: hidden;
  display: flex; min-height: 100vh; flex-direction: column;
}
main { flex: 1; }
h1, h2, h3, p { margin: 0; }
a { color: var(--accent-strong); text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; }
.skip-link { position: absolute; left: .75rem; top: -4rem; z-index: 100; background: var(--ink); color: #fff; padding: .5rem .9rem; border-radius: .5rem; font-weight: 600; }
.skip-link:focus { top: .75rem; }
.wrap { max-width: 72rem; margin: 0 auto; padding: 0 1.25rem; }

/* Header / footer */
.site-header { position: sticky; top: 0; z-index: 50; background: rgba(255,255,255,.94); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.site-header .wrap { display: flex; align-items: center; gap: 1.25rem; min-height: 3.5rem; flex-wrap: wrap; }
.logo { font-family: var(--font-display); font-weight: 700; font-size: 1.3rem; color: var(--ink); text-decoration: none; letter-spacing: -.01em; }
.logo span { color: var(--accent); }
.site-header nav { margin-left: auto; display: flex; gap: 1.1rem; font-size: .9rem; }
.site-header nav a { color: var(--ink); text-decoration: none; font-weight: 500; padding: .5rem 0; }
.site-header nav a:hover { color: var(--accent-strong); text-decoration: underline; }
.site-footer { border-top: 1px solid var(--line); background: #fff; margin-top: 4rem; padding: 1.75rem 0; font-size: .875rem; color: var(--muted); }
.site-footer .wrap { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; justify-content: space-between; }

/* Intro */
.intro { padding-top: 1.5rem; padding-bottom: 1rem; }
.intro h1 { font-family: var(--font-display); font-size: clamp(1.7rem, 4vw, 2.4rem); line-height: 1.12; letter-spacing: -.02em; }
.intro p { margin-top: .5rem; max-width: 46rem; color: var(--muted); }
.noscript { margin: 1rem 0; padding: .75rem 1rem; border: 1px solid #f0c36d; background: #fff7e0; border-radius: .5rem; }

/* Buttons and fields */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 2.25rem; padding: 0 .75rem;
  border: 1px solid var(--line); border-radius: .5rem; background: #fff; color: var(--ink); font: inherit; font-size: .875rem; font-weight: 500; cursor: pointer;
}
.btn:hover:not(:disabled) { background: var(--surface); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn-danger { color: #b42318; border-color: #f3c6c1; }
.btn-danger:hover:not(:disabled) { background: #fef3f2; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-icon { width: 2.25rem; padding: 0; }
.btn-lg { min-height: 2.5rem; width: 100%; }
.btn[aria-pressed="true"].btn-ghost { background: var(--surface); }
.btn svg, .seg svg { width: 16px; height: 16px; flex: none; }

.field { margin-bottom: .85rem; }
.field-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; margin-bottom: .25rem; }
.field label, .lbl { display: block; font-size: .75rem; font-weight: 600; color: var(--muted); margin-bottom: .25rem; }
.field-head label { margin-bottom: 0; }
.field-head output { font-size: .75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.hint { margin-top: .25rem; font-size: .75rem; line-height: 1.35; color: var(--muted); }
input[type="text"], input[type="number"], select, textarea {
  width: 100%; min-height: 2.25rem; padding: .35rem .6rem; border: 1px solid #cfcfd9; border-radius: .5rem; background: #fff; color: var(--ink); font: inherit; font-size: .9rem;
}
textarea { min-height: 10rem; resize: vertical; line-height: 1.5; }
input[type="range"] { width: 100%; accent-color: var(--accent); height: 1.5rem; margin: 0; }
input[type="color"] { width: 3rem; height: 2.25rem; padding: 2px; border: 1px solid #cfcfd9; border-radius: .5rem; background: #fff; cursor: pointer; }
input[type="checkbox"] { width: 1rem; height: 1rem; accent-color: var(--accent); margin: 0; }
.check { display: flex; align-items: center; gap: .5rem; min-height: 2.25rem; font-size: .875rem; cursor: pointer; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.row { display: flex; gap: .5rem; }
.row > * { flex: 1; }
.stack { display: flex; flex-direction: column; gap: .75rem; }
.stack > .field { margin-bottom: 0; }

.seg { display: flex; border: 1px solid #cfcfd9; border-radius: .5rem; overflow: hidden; background: #fff; }
.seg button { flex: 1; min-height: 2.25rem; border: 0; border-right: 1px solid var(--line); background: transparent; font: inherit; font-size: .8rem; font-weight: 500; color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; padding: 0 .4rem; }
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--surface); }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.tog { width: 2.25rem; height: 2.25rem; border: 1px solid #cfcfd9; border-radius: .5rem; background: #fff; cursor: pointer; font: inherit; font-size: 1rem; color: var(--ink); }
.tog:hover { background: var(--surface); }
.tog[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }

.notice { border: 1px solid; border-radius: .5rem; padding: .5rem .65rem; font-size: .75rem; line-height: 1.4; }
.notice.ok { border-color: #bbe5c3; background: #f0fbf2; color: #14532d; }
.notice.warn { border-color: #f5d9a1; background: #fffbeb; color: #7a4a00; }
.notice.err { border-color: #fecaca; background: #fef2f2; color: #7f1d1d; }
.notice button.link { display: block; margin-top: .4rem; background: none; border: 0; padding: 0; font: inherit; font-weight: 600; color: inherit; text-decoration: underline; cursor: pointer; }
.swatch { display: inline-block; width: .9rem; height: .9rem; border: 1px solid #0003; border-radius: 3px; vertical-align: -2px; margin: 0 .15rem; }

.dropzone { border: 2px dashed var(--line); border-radius: .6rem; background: var(--surface); padding: 1rem; text-align: center; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone p:first-of-type { font-size: .9rem; font-weight: 600; }
.dropzone .hint { margin-top: .15rem; }
.dropzone .row { margin-top: .75rem; justify-content: center; flex-wrap: wrap; }
.dropzone .row > * { flex: 0 0 auto; }
.fileinfo { display: flex; align-items: center; gap: .75rem; border: 1px solid var(--line); background: var(--surface); border-radius: .5rem; padding: .5rem; }
.fileinfo .name { font-size: .875rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fileinfo .meta { font-size: .75rem; color: var(--muted); }
.fileinfo > div:last-child { min-width: 0; flex: 1; }
.checker, .thumb { background-color: #fff; background-image: linear-gradient(45deg, #ececf1 25%, transparent 25%, transparent 75%, #ececf1 75%), linear-gradient(45deg, #ececf1 25%, transparent 25%, transparent 75%, #ececf1 75%); background-size: 16px 16px; background-position: 0 0, 8px 8px; }
.thumb { width: 3rem; height: 3rem; flex: none; border: 1px solid var(--line); border-radius: .4rem; overflow: hidden; }
.thumb canvas { width: 100%; height: 100%; object-fit: contain; display: block; }
.bgbox { border: 1px solid var(--line); border-radius: .6rem; padding: .7rem; background: #fff; }
.bgbox h3 { font-size: .85rem; margin-bottom: .35rem; }
.sub { margin-top: .6rem; padding-top: .6rem; border-top: 1px dashed var(--line); }
.colorline { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.colorline .btn { min-height: 2rem; font-size: .8rem; }

/* Editor layout */
#editor { max-width: 1680px; margin: 0 auto; padding: 0 .5rem 1rem; }
.grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: .75rem; }
.preview { order: 1; display: flex; flex-direction: column; gap: .5rem; min-width: 0; min-height: 0; }
.tabs { order: 2; display: grid; grid-template-columns: repeat(4, 1fr); gap: .25rem; border: 1px solid var(--line); border-radius: .5rem; background: #fff; padding: .25rem; }
.tabs button { min-height: 2.75rem; border: 0; border-radius: .4rem; background: transparent; font: inherit; font-size: .875rem; font-weight: 500; cursor: pointer; color: var(--ink); }
.tabs button[aria-selected="true"] { background: var(--ink); color: #fff; }
.aside-left { order: 3; } .aside-right { order: 4; }
.panel { display: none; border: 1px solid var(--line); border-radius: .5rem; background: #fff; }
.panel > h2 { font-size: .95rem; padding: .75rem 1rem; border-bottom: 1px solid var(--line); }
.panel-body { padding: 1rem; }
#editor[data-tab="image"] .panel-image, #editor[data-tab="text"] .panel-text,
#editor[data-tab="page"] .panel-page, #editor[data-tab="export"] .panel-export { display: block; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; border: 1px solid var(--line); border-radius: .5rem; background: #fff; padding: .35rem; }
.toolbar .sep { width: 1px; height: 1.25rem; background: var(--line); margin: 0 .2rem; }
.toolbar .zoomval { min-width: 3rem; text-align: center; font-size: .75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.toolbar .right { margin-left: auto; display: flex; gap: .3rem; }
.toolbar .btn { font-size: .78rem; }

#viewport { position: relative; overflow: auto; background: #e9e9ef; padding: 16px; border-radius: .5rem; min-height: 320px; }
#viewport.over { outline: 2px dashed var(--accent); outline-offset: -6px; }
#page { position: relative; margin: 0 auto; box-shadow: 0 2px 16px rgba(20,20,40,.18); }
#page canvas.main { display: block; }
#imgbox { position: absolute; touch-action: none; cursor: pointer; }
#imgbox:hover { outline: 2px dashed rgba(201,63,29,.5); }
#imgbox.selected { cursor: move; outline: 2px dashed var(--accent); }
#imgbox .handle { position: absolute; width: 14px; height: 14px; border: 2px solid var(--accent); background: #fff; border-radius: 2px; touch-action: none; display: none; }
#imgbox.selected .handle { display: block; }
.handle.nw { left: -7px; top: -7px; cursor: nwse-resize; } .handle.ne { right: -7px; top: -7px; cursor: nesw-resize; }
.handle.sw { left: -7px; bottom: -7px; cursor: nesw-resize; } .handle.se { right: -7px; bottom: -7px; cursor: nwse-resize; }
#emptycard { position: absolute; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .4rem; border: 2px dashed rgba(201,63,29,.6); border-radius: .6rem; background: rgba(253,235,229,.85); padding: .5rem; text-align: center; min-width: 150px; min-height: 110px; }
#emptycard p { font-size: .75rem; font-weight: 600; }
#emptycard .row { flex: none; justify-content: center; flex-wrap: wrap; gap: .35rem; }
#emptycard .btn { min-height: 2rem; font-size: .75rem; padding: 0 .5rem; flex: none; }

@media (min-width: 1024px) {
  .grid { grid-template-columns: 320px minmax(0, 1fr) 320px; height: max(640px, calc(100dvh - 12rem)); }
  .tabs { display: none; }
  .preview { order: 2; } .aside-left { order: 1; } .aside-right { order: 3; }
  .aside-left, .aside-right { overflow-y: auto; min-height: 0; border: 1px solid var(--line); border-radius: .5rem; background: #fff; }
  .panel { display: block !important; border: 0; border-radius: 0; }
  .panel + .panel { border-top: 1px solid var(--line); }
  #viewport { flex: 1; min-height: 0; }
}

/* Content sections */
.content { max-width: 52rem; margin: 3.5rem auto 0; padding: 0 1.25rem; }
.content h2 { font-size: 1.5rem; line-height: 1.25; letter-spacing: -.01em; margin: 2.75rem 0 .75rem; }
.content h2:first-child { margin-top: 0; }
.content h3 { font-size: 1.05rem; margin: 1.4rem 0 .4rem; }
.content p, .content li { line-height: 1.7; color: #2b2b33; }
.content p { margin: .8rem 0; }
.content ul, .content ol { padding-left: 1.4rem; margin: .8rem 0; }
.content li { margin: .3rem 0; }
details { border: 1px solid var(--line); border-radius: .6rem; background: #fff; margin: .6rem 0; }
details summary { cursor: pointer; padding: .85rem 1rem; font-weight: 600; }
details p { padding: 0 1rem 1rem; margin: 0; }
dialog { width: min(92vw, 26rem); border: 1px solid var(--line); border-radius: .75rem; padding: 1.25rem; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h2 { font-size: 1rem; } dialog p { margin-top: .5rem; font-size: .875rem; color: var(--muted); }
dialog .actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; scroll-behavior: auto !important; } }
