/* WrapTexts tool UI (shared by every tool page). Brand tokens live in site.css. */
/* 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 #cddcf0; border-radius: .5rem; background: #fff; color: var(--ink); font: inherit; font-size: .875rem; font-weight: 600; 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 #cddcf0; 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 #cddcf0; 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 #cddcf0; 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 #cddcf0; 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, .fthumb { 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; }
.fthumb { width: 3rem; height: 3rem; flex: none; border: 1px solid var(--line); border-radius: .4rem; overflow: hidden; }
.fthumb 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: #e4eefb; 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(8,120,249,.55); }
#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(8,120,249,.7); border-radius: .6rem; background: rgba(230,242,255,.92); 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-family: var(--font-display); 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; } }

/* Select-object editor */
dialog.sel-dialog { width: min(96vw, 60rem); max-height: 96vh; overflow: auto; padding: 1rem; }
.sel-dialog .sel-intro { margin-top: .35rem; font-size: .8rem; }
.sel-tools { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .6rem 1rem; margin-top: .75rem; }
.sel-tools .seg { flex: 0 1 auto; }
.sel-size { width: 11rem; margin: 0; }
.sel-tools .row { display: flex; gap: .4rem; }
.sel-stage { margin-top: .75rem; display: flex; justify-content: center; background: #2b2b33; border-radius: .5rem; padding: .5rem; min-height: 8rem; }
.sel-frame { position: relative; line-height: 0; touch-action: none; box-shadow: 0 0 0 1px rgba(255,255,255,.15); }
.sel-frame canvas { display: block; width: 100%; height: 100%; }
#sel-marks { position: absolute; inset: 0; cursor: crosshair; touch-action: none; }
#sel-status { min-height: 1.3rem; margin-top: .5rem; }
.sel-opts { display: flex; flex-wrap: wrap; gap: .1rem 1.5rem; }
.sel-dialog .actions { margin-top: .6rem; }

/* ===== Canvas tools shell (add text, captions, curved/outline/shadow, layout) ===== */
.tool-shell { max-width: 1320px; margin: 18px auto 0; padding: 0 22px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.tool-shell .stage-col { min-width: 0; display: flex; flex-direction: column; gap: .6rem; }
.stage { position: relative; display: flex; align-items: center; justify-content: center; min-height: 260px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background-color: #e9f2fd; overflow: hidden; }
.stage.checker { background-color: #fff; }
.stage canvas { max-width: 100%; height: auto; display: block; box-shadow: 0 3px 18px rgba(16,33,63,.18); background: transparent; touch-action: none; }
.stage canvas.plain { box-shadow: none; }
.stage .preview-text { max-width: 100%; overflow-wrap: anywhere; text-align: center; }
.tool-shell .controls { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.tool-shell .panel { display: block; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.tool-shell .panel > h2 { font-size: .9rem; padding: .7rem 1rem; border-bottom: 1px solid var(--line); font-family: var(--font-display); }
.tool-shell .panel-body { padding: .9rem 1rem; }
.exportbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.exportbar .btn { flex: 1 1 8rem; }
.exportbar .btn-primary { min-height: 2.5rem; }
.pillrow { display: flex; flex-wrap: wrap; gap: .4rem; }
.pillrow .btn { min-height: 2rem; font-size: .78rem; padding: 0 .6rem; }
.tog-row { display: flex; gap: .4rem; flex-wrap: wrap; }
.tog-row .tog { font-weight: 700; }
.layer-list { display: flex; flex-direction: column; gap: .3rem; max-height: 11rem; overflow-y: auto; margin: 0; padding: 0; list-style: none; }
.layer-list button { width: 100%; text-align: left; min-height: 2.25rem; border: 1px solid #cddcf0; border-radius: .5rem; background: #fff; font: inherit; font-size: .85rem; padding: 0 .6rem; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.layer-list button[aria-current="true"] { border-color: var(--blue); background: var(--accent-soft); font-weight: 700; }
.code-box { position: relative; }
.code-box pre { margin: 0; padding: .8rem; border-radius: .5rem; background: #0f1c35; color: #d7e6ff; font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-all; max-height: 11rem; overflow: auto; }
.swatches { display: flex; flex-wrap: wrap; gap: .35rem; }
.swatches button { width: 1.75rem; height: 1.75rem; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px #b9cbe4; cursor: pointer; padding: 0; }
.swatches button:hover { box-shadow: 0 0 0 2px var(--blue); }
@media (min-width: 980px) {
  .tool-shell { grid-template-columns: minmax(0, 1fr) 360px; }
  .tool-shell .stage-col.sticky { position: sticky; top: 70px; }
  .stage { min-height: 420px; }
}
.btn-primary { background: #0a66d8; border-color: #0a66d8; }
.btn-primary:hover:not(:disabled) { background: #0856b8; }

/* ===== Wrap tool: first load and small screens ===== */
.loading{position:absolute;inset:0;display:grid;place-items:center;margin:0;color:var(--muted);font-size:.9rem;text-align:center;padding:1rem}
@media (max-width: 1023px) {
  /* keep the live preview in view while editing on a phone */
  .grid .preview{position:sticky;top:58px;z-index:8;background:#fff;padding:.3rem 0 .4rem;margin:0;gap:.3rem;box-shadow:0 8px 12px -10px #13274640}
  .toolbar{flex-wrap:nowrap;overflow-x:auto;scrollbar-width:none;-webkit-overflow-scrolling:touch}
  .toolbar::-webkit-scrollbar{display:none}
  .toolbar>*{flex:none}
  .toolbar .right{margin-left:.5rem}
  #viewport{height:min(36vh,320px);min-height:200px;padding:8px}
  .tabs{position:static}
  .tabs button{min-height:3rem}
}
@media (max-width: 380px) {
  .toolbar .btn-ghost[title="Actual size"]{display:none}
}
