:root {
  --bg: #f4f5f8;
  --card: #ffffff;
  --text: #1d2233;
  --muted: #646b80;
  --line: #e2e5ec;
  --accent: #1b3d93;
  --accent-soft: #e8eefc;
  --shadow: 0 1px 2px rgba(20, 30, 60, 0.06), 0 6px 20px rgba(20, 30, 60, 0.06);
  --radius: 14px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
code, kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.86em;
  background: #eef0f5;
  border-radius: 5px;
  padding: 1px 5px;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px max(16px, calc((100% - 1360px) / 2));
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); text-decoration: none; }
.brand-mark { width: 36px; height: 36px; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 700; }
.brand-by { font-size: 11.5px; font-weight: 500; color: var(--muted); }
.site-header nav { display: flex; align-items: center; gap: 18px; }
.install-btn {
  border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 999px;
  padding: 6px 14px; font-weight: 600; font-size: 13.5px; cursor: pointer;
}
.install-btn[hidden] { display: none; }
.site-header nav a { color: var(--muted); text-decoration: none; font-weight: 500; }
.site-header nav a:hover { color: var(--accent); }

.hero { text-align: center; padding: 34px 16px 10px; }
.hero h1 { margin: 0 0 8px; font-size: clamp(26px, 4vw, 40px); letter-spacing: -0.02em; }
.hero p { margin: 0 auto; max-width: 680px; color: var(--muted); }

.tool {
  display: grid;
  grid-template-columns: minmax(330px, 420px) 1fr;
  gap: 22px;
  max-width: 1360px;
  margin: 18px auto 0;
  padding: 0 16px;
  align-items: start;
}
.panel { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px 16px;
  box-shadow: var(--shadow);
}
.card[open] { padding-bottom: 16px; }
.card > summary {
  cursor: pointer;
  list-style: none;
  font-weight: 650;
  padding: 12px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.card > summary::-webkit-details-marker { display: none; }
.card > summary::after { content: "▾"; color: var(--muted); transition: transform 0.2s; }
.card:not([open]) > summary::after { transform: rotate(-90deg); }
.count { margin-left: auto; font-weight: 500; color: var(--muted); font-size: 13px; }

textarea {
  width: 100%;
  min-height: 190px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fbfbfd;
  tab-size: 6;
}
textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.text-tools { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.stats { font-size: 12.5px; color: var(--muted); margin-right: auto; }
.mini-btn {
  position: relative; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 4px 10px;
  font-size: 12.5px; font-weight: 550; cursor: pointer; color: var(--accent);
}
.mini-btn:hover { border-color: var(--accent); }
.mini-btn input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.range { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); margin-left: auto; }
.range input { width: 58px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 6px; }
.progress {
  display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 8px 12px; margin: -4px 0 14px; font-size: 13.5px;
}
.progress[hidden] { display: none; }
.progress .bar { flex: 1; height: 8px; background: #e9ecf3; border-radius: 99px; overflow: hidden; }
.progress .bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.lang-select { margin: 0 0 12px; }
.lang-hint {
  background: #fff7e0; border: 1px solid #f1d68a; color: #6b5310; border-radius: 10px;
  padding: 8px 10px; margin-bottom: 8px; font-size: 13px;
}
.lang-hint[hidden] { display: none; }
.lang-hint .link { font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chips button {
  border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 10px;
  font-size: 12.5px; cursor: pointer; font-family: ui-monospace, Menlo, monospace;
}
.chips button:hover { border-color: var(--accent); color: var(--accent); }
.hint { font-size: 12.5px; color: var(--muted); margin: 10px 0 0; }

.font-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
  padding: 2px;
}
.font-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left;
  border: 1.5px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 10px; cursor: pointer;
}
.font-card .sample { font-size: 21px; line-height: 1.25; color: #1b3d93; white-space: nowrap; overflow: hidden; max-width: 100%; }
.font-card .meta { display: flex; flex-direction: column; line-height: 1.2; }
.font-card b { font-size: 12.5px; font-weight: 600; }
.font-card small { font-size: 11.5px; color: var(--muted); }
.font-card[aria-checked="true"], .paper-card[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }

.upload { display: block; margin-top: 10px; cursor: pointer; }
.upload input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.upload span {
  display: block; text-align: center; padding: 8px; border: 1.5px dashed #c5cbd8; border-radius: 10px;
  color: var(--accent); font-weight: 550; font-size: 13.5px;
}
.upload:hover span { background: var(--accent-soft); }

.paper-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
  padding: 2px;
}
.paper-card {
  display: flex; flex-direction: column; gap: 4px; border: 1.5px solid var(--line); border-radius: 10px;
  background: #fff; padding: 5px; cursor: pointer; font-size: 11px; line-height: 1.2; text-align: center;
}
.paper-card canvas { width: 100%; height: auto; border-radius: 4px; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.06); }

.row { margin-top: 12px; }
.row label { display: flex; justify-content: space-between; font-size: 13.5px; font-weight: 550; }
.row output { color: var(--muted); font-weight: 500; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.field-label { font-size: 13.5px; font-weight: 550; margin-bottom: 8px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.swatch {
  width: 32px; height: 32px; border-radius: 50%; border: 3px solid #fff; cursor: pointer;
  box-shadow: 0 0 0 1px var(--line); position: relative;
}
.swatch.on { box-shadow: 0 0 0 2px var(--accent); }
.swatch.custom { background: conic-gradient(#e33, #ec3, #3c5, #3be, #44e, #c3c, #e33); overflow: hidden; }
.swatch.custom input { opacity: 0; width: 100%; height: 100%; cursor: pointer; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.select, .fields label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 550; margin-top: 10px; }
.fields .wide { grid-column: 1 / -1; }
select, .fields input {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; background: #fff; font-weight: 400;
}
.check { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 13.5px; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 8px 4px; cursor: pointer; font-weight: 550; font-size: 13.5px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-checked="true"] { background: var(--accent); color: #fff; }

.link { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; font-weight: 550; font-size: 13px; }
.card > .link { margin-top: 14px; }

.preview { position: sticky; top: 12px; min-width: 0; }
.toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px;
  box-shadow: var(--shadow); margin-bottom: 14px;
}
.status { color: var(--muted); font-size: 13.5px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  border-radius: 10px; padding: 8px 14px; font-weight: 600; cursor: pointer; font-size: 14px;
  border: 1px solid var(--line); background: #fff;
}
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: #142f75; }
.btn.ghost:hover { border-color: var(--accent); color: var(--accent); }

.pages {
  display: flex; flex-direction: column; align-items: center; gap: 22px;
  max-height: calc(100vh - 100px); overflow-y: auto; padding: 6px 6px 24px;
}
.page { margin: 0; width: 100%; max-width: 640px; }
.page canvas { width: 100%; height: auto; aspect-ratio: 1240 / 1754; display: block; background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12), 0 12px 32px rgba(0, 0, 0, 0.10); }
.page figcaption { display: flex; justify-content: space-between; padding: 8px 2px 0; font-size: 13px; color: var(--muted); }

.content { max-width: 860px; margin: 60px auto 0; padding: 0 16px; }
.content h2 { font-size: 22px; margin: 36px 0 10px; }
.content p, .content li { color: #3a4157; }
.content li { margin-bottom: 6px; }
.content details { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; margin-bottom: 8px; }
.content summary { cursor: pointer; font-weight: 600; }
.content details p { margin: 8px 0 0; }

.site-footer { text-align: center; color: var(--muted); font-size: 13px; padding: 40px 16px; }
.site-footer a { color: var(--accent); font-weight: 600; text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }

#print-root { display: none; }

@media (max-width: 900px) {
  .tool { grid-template-columns: 1fr; }
  .preview { position: static; }
  .pages { max-height: none; overflow: visible; }
  .toolbar { position: sticky; top: 0; z-index: 5; }
  .site-header nav a { display: none; }
}
@media (max-width: 480px) {
  .paper-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .actions { width: 100%; }
  .actions .btn { flex: 1 1 auto; padding: 8px 10px; }
}

@page { size: A4; margin: 0; }
@media print {
  body { background: #fff; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block; }
  #print-root img { display: block; width: 210mm; height: 297mm; page-break-after: always; break-after: page; }
  #print-root img:last-child { page-break-after: auto; break-after: auto; }
}
