:root {
  --bg: #f4f5f7; --panel: #ffffff; --text: #1f2328; --muted: #6b7280;
  --line: #e2e5ea; --accent: #2563eb; --accent-weak: #e8efff; --danger: #b91c1c;
  --header-h: 50px; --adband-h: 122px;
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: system-ui, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.6;
}
a { color: var(--accent); }

/* ---------- header / footer ---------- */
.site-header {
  display: flex; align-items: center; gap: 16px; height: var(--header-h); padding: 0 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.site-header .logo { font-weight: 700; font-size: 16px; color: var(--text); text-decoration: none; white-space: nowrap; }
.site-header .local { font-size: 12px; color: var(--muted); }
.site-header nav { display: flex; gap: 16px; margin-left: auto; font-size: 13px; }
.site-header nav a { color: var(--muted); text-decoration: none; white-space: nowrap; }
.site-header nav a:hover, .site-header nav a.on { color: var(--accent); }
.site-footer {
  border-top: 1px solid var(--line); background: var(--panel); padding: 24px 16px; text-align: center;
  font-size: 12px; color: var(--muted);
}
.site-footer nav { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; margin-bottom: 8px; }
.site-footer a { color: var(--muted); }

/* ---------- ad slots ---------- */
.ad-wrap { display: flex; flex-direction: column; align-items: center; width: 100%; }
.ad-caption { font-size: 10px; color: #9aa1ac; letter-spacing: .08em; margin-bottom: 2px; align-self: center; }
.ad { width: 100%; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.ad.placeholder {
  background: repeating-linear-gradient(45deg, #eef0f3, #eef0f3 10px, #e7eaee 10px, #e7eaee 20px);
  border: 1px dashed #c5cad3; color: #9aa1ac; font-size: 12px;
}
.ad-hidden { display: none !important; }
.ad-band { padding: 8px 16px; height: var(--adband-h); }
.ad-top { max-width: 970px; height: 90px; }
.ad-rect { width: 300px; height: 250px; }
.ad-tall { width: 300px; height: 600px; }
.ad-inarticle { min-height: 250px; }
.ad-bottom { max-width: 970px; min-height: 250px; }

/* ---------- tool layout ---------- */
.tool {
  display: grid; grid-template-columns: 290px minmax(0, 1fr) 332px;
  height: calc(100vh - var(--header-h) - var(--adband-h)); min-height: 600px;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.controls {
  background: var(--panel); border-right: 1px solid var(--line); padding: 14px;
  overflow-y: auto; display: flex; flex-direction: column; gap: 16px;
}
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.rail {
  border-left: 1px solid var(--line); padding: 12px 16px; display: flex; flex-direction: column;
  align-items: center; gap: 16px; overflow: hidden;
}
.rail .ad-wrap.tall-only { display: none; }
@media (min-height: 860px) {
  .rail .ad-wrap.tall-only { display: flex; }
  .rail .ad-wrap.rect-only { display: none; }
}
@media (max-width: 1279px) {
  .tool { grid-template-columns: 290px minmax(0, 1fr); }
  .rail { display: none; }
}
/* narrow screens (content pages; the tool page is driven by body.layout-mobile below) */
@media (max-width: 860px) {
  :root { --adband-h: 132px; }
  .site-header .local, .site-header nav a.sub { display: none; }
  .ad-top { height: 100px; max-width: 320px; }
}

/* ---------- mobile layout (chosen in app.js: finger-first device or very narrow screen) ---------- */
.tabbar { display: none; }
body.layout-mobile { --adband-h: 76px; }
body.layout-mobile .site-header .local, body.layout-mobile .site-header nav a.sub { display: none; }
body.layout-mobile .ad-top { height: 50px; max-width: 320px; }
body.layout-mobile .tool {
  display: flex; flex-direction: column;
  height: calc(100svh - var(--header-h) - var(--adband-h)); min-height: 520px;
}
body.layout-mobile .stage { order: 1; flex: 1 1 auto; min-height: 0; height: auto; }
body.layout-mobile .rail { display: none; }
body.layout-mobile .controls {
  order: 2; flex: 0 0 auto; max-height: 42%; overflow-y: auto;
  border-right: 0; border-top: 1px solid var(--line); padding: 12px; gap: 12px;
  box-shadow: 0 -4px 12px rgba(0,0,0,.06);
}
body.layout-mobile .controls.closed { display: none; }
body.layout-mobile .controls > :not([data-tab]) { display: none; }
body.layout-mobile .controls[data-active="auto"] > :not([data-tab~="auto"]):not([data-tab~="always"]),
body.layout-mobile .controls[data-active="hide"] > :not([data-tab~="hide"]):not([data-tab~="always"]),
body.layout-mobile .controls[data-active="mark"] > :not([data-tab~="mark"]):not([data-tab~="always"]),
body.layout-mobile .controls[data-active="save"] > :not([data-tab~="save"]):not([data-tab~="always"]) { display: none; }
body.layout-mobile .tabbar {
  order: 3; display: flex; background: var(--panel); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; border: 0; background: none; padding: 6px 0 7px; font-size: 11px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 1px; cursor: pointer;
}
.tabbar button .ic { font-size: 19px; line-height: 1.2; }
.tabbar button.on { color: var(--accent); font-weight: 700; }
body.layout-mobile .thumbs { padding: 6px 10px; gap: 8px; }
body.layout-mobile .thumb { width: 60px; height: 46px; }
body.layout-mobile .thumbs .count-label { display: none; }
body.layout-mobile .canvas-area { padding: 8px; }
body.layout-mobile .canvas-tools { padding: 5px 8px; gap: 6px; }
body.layout-mobile .canvas-tools .btn { padding: 7px 10px; font-size: 12px; }
body.layout-mobile .canvas-tools .info { font-size: 11px; }
body.layout-mobile .pc-text { display: none; }
body.layout-mobile .btn, body.layout-mobile .seg button { min-height: 40px; }
body.layout-mobile .seg.five button, body.layout-mobile .seg.four button { font-size: 12px; }
body.layout-mobile select, body.layout-mobile .text-input { min-height: 40px; font-size: 16px; } /* 16px stops iOS auto-zoom */
/* touch-capable PC: keep the PC layout but make targets easier to hit */
body.touch-pc .btn, body.touch-pc .seg button { min-height: 38px; }
body.touch-pc .tabbar { display: none; }

/* magnifier shown while operating with a finger */
.loupe { position: absolute; top: 10px; left: 10px; z-index: 5; pointer-events: none; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.loupe canvas {
  width: 132px; height: 132px; border-radius: 50%; border: 3px solid #fff;
  box-shadow: 0 4px 16px rgba(0,0,0,.35); background: #e5e7eb;
}
.loupe-cap { font-size: 11px; background: rgba(15,23,42,.8); color: #fff; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.loupe-cap:empty { display: none; }
.btns.three { grid-template-columns: repeat(3, 1fr); }
.btns.three .btn { padding: 6px 2px; font-size: 12px; }
.dlg-sub { margin: 16px 0 6px; font-size: 14px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 4px; font-size: 14px; }
.set-row select { width: auto; min-width: 150px; }

/* thumbnails */
.thumbs {
  display: flex; gap: 10px; padding: 10px 12px; overflow-x: auto; background: var(--panel);
  border-bottom: 1px solid var(--line); flex: 0 0 auto; align-items: center;
}
.thumb {
  position: relative; flex: 0 0 auto; width: 84px; height: 62px; border: 2px solid transparent;
  border-radius: 6px; cursor: pointer; background: #e5e7eb; margin-top: 4px;
}
.thumb canvas { width: 100%; height: 100%; object-fit: contain; display: block; border-radius: 4px; }
.thumb.on { border-color: var(--accent); }
.thumb .x {
  position: absolute; top: -7px; right: -7px; width: 18px; height: 18px; border-radius: 50%;
  background: #374151; color: #fff; border: 0; font-size: 11px; line-height: 18px; padding: 0; cursor: pointer;
}
.thumb .count, .thumb .gps {
  position: absolute; bottom: 2px; font-size: 10px; padding: 0 5px; border-radius: 8px; color: #fff; line-height: 16px;
}
.thumb .count { left: 2px; background: rgba(37, 99, 235, .92); }
.thumb .gps { right: 2px; background: #d97706; }
.thumb.add {
  display: flex; align-items: center; justify-content: center; border: 2px dashed #c5cad3;
  color: var(--muted); font-size: 24px; background: #fff;
}
.thumbs .count-label { font-size: 12px; color: var(--muted); white-space: nowrap; margin-left: auto; padding-left: 8px; }
.canvas-area {
  flex: 1; position: relative; display: flex; align-items: center; justify-content: center;
  padding: 16px; min-height: 0; overflow: hidden;
}
.drop {
  border: 2px dashed #c5cad3; border-radius: 12px; padding: 44px 36px; text-align: center;
  color: var(--muted); background: #fff; cursor: pointer; max-width: 480px;
}
.drop strong { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }
.sp-only { display: none; }
body.layout-mobile .pc-only, body.touch-input .pc-only { display: none; }
body.layout-mobile .sp-only, body.touch-input .sp-only { display: inline; }
.canvas-area.dragover .drop { border-color: var(--accent); background: var(--accent-weak); }
.canvas-wrap { position: relative; display: none; box-shadow: 0 2px 12px rgba(0,0,0,.12); background: #fff; }
.canvas-wrap canvas { display: block; position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
#overlay { cursor: crosshair; touch-action: none; }
.info { position: absolute; bottom: 6px; right: 12px; font-size: 12px; color: var(--muted); }

/* controls */
.group h2 { font-size: 12px; color: var(--muted); margin: 0 0 8px; font-weight: 600; letter-spacing: .04em; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.seg.five { grid-template-columns: repeat(5, 1fr); }
.seg button {
  padding: 8px 2px; border: 1px solid var(--line); background: #fff; border-radius: 6px;
  cursor: pointer; font-size: 13px; color: var(--text); white-space: nowrap;
}
.seg.five button { font-size: 12px; }
.seg button.on { background: var(--accent-weak); border-color: var(--accent); color: var(--accent); font-weight: 600; }
label.row { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
input[type=range] { width: 100%; }
.btn {
  width: 100%; padding: 9px; border-radius: 6px; border: 1px solid var(--line);
  background: #fff; cursor: pointer; font-size: 13px; color: var(--text);
}
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.danger { color: var(--danger); }
.btns { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.stack { display: flex; flex-direction: column; gap: 6px; }
select { width: 100%; padding: 7px; border-radius: 6px; border: 1px solid var(--line); font-size: 13px; background: #fff; }
.field-label { font-size: 12px; color: var(--muted); margin: 2px 0; }
.check { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--text); }
.tip { font-size: 12px; color: var(--muted); line-height: 1.6; background: #fafbfc; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; }
.status { font-size: 12px; color: var(--accent); min-height: 1em; }
.auto-box { border: 1px solid #c7d7fb; background: #f5f8ff; border-radius: 8px; padding: 10px; }
.auto-box h2 { color: var(--accent); }
.selpanel {
  border: 1px solid var(--accent); background: var(--accent-weak); border-radius: 8px; padding: 10px;
  font-size: 12px; color: var(--accent);
}
.selpanel b { display: block; margin-bottom: 4px; font-size: 13px; }
.selpanel .btn { padding: 6px; font-size: 12px; }
.list { display: flex; flex-direction: column; gap: 3px; max-height: 180px; overflow-y: auto; }
.list .item {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px; border: 1px solid var(--line);
  border-radius: 6px; font-size: 12px; cursor: pointer; background: #fff;
}
.list .item:hover { border-color: #b9c3d3; }
.list .item.on { border-color: var(--accent); background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.list .item span { flex: 1; }
.list .item button { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 14px; padding: 0 2px; }
.list .item button:hover { color: var(--danger); }
.list .empty { font-size: 12px; color: var(--muted); }

[hidden] { display: none !important; }
.seg.four { grid-template-columns: repeat(4, 1fr); }
.seg.four button { font-size: 12px; }
h2.with-btn { display: flex; align-items: center; justify-content: space-between; }
.link-btn { border: 0; background: none; color: var(--accent); font-size: 12px; cursor: pointer; padding: 0; font-weight: 600; }
.link-btn:hover { text-decoration: underline; }
.color-input { width: 100%; height: 34px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.text-input { width: 100%; padding: 7px 9px; border-radius: 6px; border: 1px solid var(--line); font-size: 13px; }
.canvas-tools {
  display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; padding: 8px 12px;
  background: var(--panel); border-top: 1px solid var(--line); flex: 0 0 auto;
}
.canvas-tools .btn { width: auto; padding: 7px 16px; }
/* file name on its own line, buttons on the line below */
.canvas-tools .info {
  position: static; flex: 0 0 100%; text-align: right; margin-top: -2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.name-row {display: flex; align-items: center; gap: 4px; }
.name-row .text-input { flex: 1; min-width: 0; }
.name-row span { font-size: 13px; color: var(--muted); }
.chips {display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chips button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 2px 9px; font-size: 11px; cursor: pointer; color: var(--text); }
.chips button:hover { border-color: var(--accent); color: var(--accent); }
.opt-box { border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: #fcfcfd; }
.small { font-size: 12px; color: var(--muted); margin: 0 0 8px; line-height: 1.6; }
.thumb .warn { position: absolute; top: 2px; left: 2px; background: #dc2626; color: #fff; font-size: 10px; font-weight: 700; border-radius: 8px; padding: 0 5px; line-height: 16px; }

/* dialogs */
.dlg {
  border: 0; border-radius: 14px; padding: 22px 24px; width: min(520px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(0,0,0,.25); color: var(--text);
}
.dlg::backdrop { background: rgba(15, 23, 42, .45); }
.dlg h3 { margin: 0 0 8px; font-size: 18px; }
.dlg p { font-size: 14px; }
.dlg ul.found { padding-left: 18px; font-size: 14px; max-height: 260px; overflow-y: auto; }
.dlg ul.found small { color: var(--muted); }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.dlg-actions .btn { width: auto; padding: 9px 16px; }
.feat-list { display: flex; flex-direction: column; gap: 2px; max-height: 60vh; overflow-y: auto; }
.feat-row { display: flex; align-items: center; gap: 14px; padding: 10px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.feat-row:last-child { border-bottom: 0; }
.feat-text { flex: 1; font-size: 14px; line-height: 1.5; }
.feat-text small { color: var(--muted); font-size: 12px; }
.tag { display: inline-block; font-size: 10px; font-weight: 700; border-radius: 4px; padding: 0 6px; margin-left: 6px; vertical-align: 1px; }
.tag.std { background: var(--accent-weak); color: var(--accent); }
.tag.opt { background: #f3f4f6; color: var(--muted); }
.switch {
  appearance: none; -webkit-appearance: none; width: 42px; height: 24px; border-radius: 999px; background: #d1d5db;
  position: relative; cursor: pointer; flex: 0 0 auto; transition: background .15s; margin: 0;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }

/* no ads configured yet: remove the reserved space */
body.no-ads .ad-band, body.no-ads .ad-wrap, body.no-ads .rail { display: none !important; }
body.no-ads .tool { grid-template-columns: 290px minmax(0, 1fr); }

/* ---------- content pages ---------- */
.content { max-width: 860px; margin: 32px auto; padding: 0 16px; display: flex; flex-direction: column; gap: 24px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px 28px; }
.card h1 { font-size: 24px; margin: 0 0 12px; line-height: 1.4; }
.card h2 { font-size: 19px; margin: 28px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.card h2:first-child { margin-top: 0; }
.card h3 { font-size: 16px; margin: 20px 0 6px; }
.card p, .card li { font-size: 15px; }
.card .lead { color: var(--muted); }
.card table { border-collapse: collapse; width: 100%; font-size: 14px; }
.card th, .card td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.card th { background: #fafbfc; }
.steps { counter-reset: s; list-style: none; padding: 0; }
.steps li { counter-increment: s; position: relative; padding-left: 40px; margin-bottom: 12px; }
.steps li::before {
  content: counter(s); position: absolute; left: 0; top: 0; width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; font-size: 14px;
}
.faq dt { font-weight: 700; margin-top: 14px; }
.faq dd { margin: 4px 0 0; color: #374151; }
.cta { display: inline-block; background: var(--accent); color: #fff; padding: 10px 18px; border-radius: 8px; text-decoration: none; font-weight: 600; }
.note-box { background: #fff8eb; border: 1px solid #f3d9a4; border-radius: 8px; padding: 10px 14px; font-size: 14px; }
@media (max-width: 860px) { .card { padding: 18px 16px; } }
