:root {
  --pw: 210mm;
  --ph: 148mm;
  --bg: #efe9df;
  --panel: #fbf8f3;
  --ink: #2b2522;
  --muted: #5f554d;
  --line: #d6cbbd;
  --accent: #b3262d;
  --accent-soft: #f6e3e1;
  --focus: #e8a0a4;
  --warn-bg: #fff4d6;
  --warn-line: #e3c46a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Yu Gothic UI", "Meiryo UI", sans-serif;
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
}

html { overflow: hidden; }
body { display: flex; overflow: hidden; }

/* ---------- 入力パネル ---------- */
.panel {
  width: clamp(380px, 28vw, 460px);
  flex-shrink: 0;
  height: 100%;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 14px 20px 32px;
}
@media (max-width: 1100px) {
  .panel { width: 330px; padding: 12px 14px 24px; }
}

.paper-pick { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; }
.paper-pick span { font-weight: bold; white-space: nowrap; }
.paper-pick select { flex: 1; }
.app-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.app-head .link { margin-left: auto; }
.ver { color: var(--muted); font-size: 12px; }
h1 { margin: 0; font-size: 22px; letter-spacing: .1em; }
h1 small, h2 small, summary small { font-size: 12px; color: var(--muted); font-weight: normal; letter-spacing: 0; }

section { border-top: 1px solid var(--line); padding: 14px 0 10px; }
h2 { margin: 0 0 10px; font-size: 17px; color: var(--accent); display: flex; align-items: center; gap: 8px; }
h3 { margin: 14px 0 8px; font-size: 14px; color: var(--ink); }
.step {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 14px;
}

.tabs { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 10px; }
.tabs button { border-radius: 16px; padding: 4px 11px; font-size: 14px; min-height: 32px; }
.tabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.chips { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin-bottom: 10px; }
.chips button { padding: 7px 2px; font-family: "Yu Mincho", serif; font-size: 15px; min-height: 38px; }
.chips button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: bold; }

.info {
  font-size: 13.5px;
  line-height: 1.65;
  background: #fff;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 4px;
  padding: 8px 10px;
  margin-bottom: 4px;
}
.info:empty { display: none; }
.info b { color: var(--accent); }
.info .sub { color: var(--muted); }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field > span { font-size: 13px; color: var(--muted); }
.field em { font-style: normal; color: var(--accent); }
.field .row { margin: 0; flex-wrap: nowrap; }
input[type=text], input[type=number], select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 7px 9px;
  font-size: 15px;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
  min-height: 36px;
}
textarea { resize: vertical; margin-bottom: 6px; }
textarea::placeholder, input::placeholder { color: #b3a89d; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, summary:focus-visible, .ink-toggle input:focus-visible + span {
  outline: 3px solid var(--focus); outline-offset: 1px; border-color: var(--accent);
}
input.invalid { border-color: #d33; background: #fff3f3; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.row { display: flex; gap: 6px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.row select { flex: 1; }
.row.end { justify-content: space-between; margin: 14px 0 0; }

input[type=radio], input[type=checkbox] { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); flex-shrink: 0; }
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 10px; }
.modes label, .submodes label {
  display: flex; align-items: center; gap: 6px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 8px; background: #fff; min-height: 38px;
}
.modes label { white-space: nowrap; font-size: 14px; padding: 7px 6px; gap: 5px; }
.grid2 .field { justify-content: flex-end; }
.modes label:has(input:checked), .submodes label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); font-weight: bold; }
.submodes { display: flex; flex-direction: column; gap: 5px; margin: -2px 0 10px; padding-left: 10px; border-left: 3px solid var(--accent-soft); }
.submodes:empty { display: none; }
.submodes label { min-height: 34px; padding: 5px 8px; font-size: 14px; }

.name-row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.name-row .num { width: 18px; color: var(--muted); font-size: 13px; text-align: right; }
.name-row input { flex: 1; }
.multi-ctrl { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; font-size: 14px; color: var(--muted); }
.multi-ctrl button { width: 34px; height: 34px; padding: 0; font-size: 18px; }
.note { font-size: 13px; color: var(--muted); margin: 0 0 10px; line-height: 1.65; }
.note:empty { display: none; }
.warn-text { color: #8a5a00; }

.check { display: flex; align-items: center; gap: 8px; margin: 4px 0 10px; cursor: pointer; }

.presets { display: flex; gap: 5px; margin-top: 8px; }
.presets select { flex: 1; min-width: 0; }

.ink-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ink-toggle label { cursor: pointer; position: relative; }
.ink-toggle input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; pointer-events: none; margin: 0; }
.ink-toggle span {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 52px; border: 1px solid var(--line); border-radius: 6px; background: #fff;
  font-size: 17px; font-family: "Yu Mincho", serif;
}
.ink-toggle span small { font-size: 12px; color: var(--muted); font-family: "Yu Gothic UI", sans-serif; }
.ink-toggle input:checked + span { border: 2px solid var(--accent); background: var(--accent-soft); font-weight: bold; }
.ink-toggle label:nth-child(2) span { color: rgb(90, 90, 90); }

details.adv { border-top: 1px solid var(--line); padding: 4px 0; }
details.adv > summary {
  cursor: pointer; list-style: none; padding: 10px 0; font-size: 16px; font-weight: bold; color: var(--ink);
  display: flex; align-items: center; gap: 8px;
}
details.adv > summary::-webkit-details-marker { display: none; }
details.adv > summary::before { content: '▸'; color: var(--accent); width: 14px; transition: transform .15s; }
details.adv[open] > summary::before { transform: rotate(90deg); }
details.adv[open] { padding-bottom: 12px; }
.howto { margin: 0 0 10px; padding-left: 1.4em; font-size: 13.5px; line-height: 1.7; color: var(--muted); }
#testPrintBtn { width: 100%; margin-bottom: 12px; min-height: 40px; }

button {
  font-family: inherit;
  font-size: 14px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 5px;
  padding: 6px 12px;
  cursor: pointer;
  color: var(--ink);
  min-height: 36px;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }
button.link { border: none; background: none; color: var(--muted); text-decoration: underline; padding: 4px 0; font-size: 13px; min-height: 0; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: bold; }
button.primary:hover:not(:disabled) { filter: brightness(1.1); }
button small { font-weight: normal; opacity: .85; font-size: 12px; }


/* ---------- プレビュー ---------- */
.preview {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 16px 24px 0;
  position: relative;
}
.paper-holder { position: relative; flex-shrink: 0; }
.paper {
  position: absolute;
  top: 0; left: 0;
  width: var(--pw);
  height: var(--ph);
  background: #fff;
  box-shadow: 0 6px 24px rgba(0,0,0,.18);
  transform-origin: 0 0;
  overflow: hidden;
}

.warnings {
  align-self: stretch;
  display: flex; flex-direction: column; gap: 4px;
  margin-bottom: 8px;
}
.warnings:empty { display: none; }
.warn-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  border-radius: 5px;
  padding: 6px 10px;
  font-size: 14px;
}
.warn-item span { flex: 1; }
.warn-item button { min-height: 30px; padding: 3px 10px; font-size: 13px; white-space: nowrap; }
.warn-more { align-self: flex-start; }

.bottom-bar {
  align-self: stretch;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 12px 0 16px;
}
.preview > .paper-holder { margin: auto 0; }
.bar-group { display: flex; align-items: center; gap: 6px; }
.bar-group.end { margin-left: auto; gap: 8px; }
.bar-group .label { color: var(--muted); font-size: 13px; }
.printer-info .link { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; color: var(--ink); }
.copies input { width: 56px; text-align: center; padding: 6px 2px; }
.copies button { width: 36px; padding: 0; font-size: 18px; }
.bottom-bar .end button { padding: 8px 16px; font-size: 15px; min-height: 42px; }
.bottom-bar .primary { padding: 8px 30px; font-size: 17px; min-width: 130px; }

.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%) translateY(10px);
  background: #2b2522; color: #fff; padding: 10px 18px; border-radius: 6px;
  font-size: 15px; box-shadow: 0 6px 20px rgba(0,0,0,.25);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 20; max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.error { background: #a3222a; }
.toast small { display: block; opacity: .8; font-size: 12px; margin-top: 2px; }

.placeholder-name { color: #c9bfb4 !important; }
.col.over { outline: 0.6mm solid rgba(211, 51, 51, .7); outline-offset: 0.5mm; }

.art { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; }
.art svg { display: block; }
html.testing .art { display: none; }
.guide.with-art .guide-band { background: none; }
.guide.with-art .guide-band span { display: none; }
.guide { position: absolute; inset: 0; pointer-events: none; }
.guide.hidden { display: none; }
.guide-area, .guide-band { position: absolute; left: 0; right: 0; }
.guide-area { border-top: 1px dashed #c9b9a8; border-bottom: 1px dashed #c9b9a8; }
.guide-band { background: repeating-linear-gradient(0deg, rgba(179,38,45,.08) 0 2mm, rgba(179,38,45,.16) 2mm 3mm); }
.guide-safe { position: absolute; inset: 0; border: solid rgba(120,120,120,.12); }
.guide span {
  position: absolute; left: 3mm; top: 1mm;
  font-size: 3mm; color: #b5a493;
  font-family: "Yu Gothic UI", sans-serif;
}
.guide-band span { color: rgba(179,38,45,.5); top: 50%; transform: translateY(-50%); }
.guide-area span, .guide-band span { left: calc(var(--safe, 0mm) + 2mm); }

.content { position: absolute; inset: 0; color: #000; }
.content.usuzumi { color: rgb(90, 90, 90); }
.area {
  position: absolute;
  left: 0; right: 0;
  display: flex;
  justify-content: center;
}
#omoteArea { align-items: center; }

.block { position: relative; display: flex; flex-direction: row-reverse; align-items: flex-start; }
.col {
  writing-mode: vertical-rl;
  text-orientation: upright;
  line-height: 1;
  white-space: nowrap;
}
.col .tcy { text-combine-upright: all; }
.side { position: absolute; }
.stack { display: flex; flex-direction: column; align-items: center; }

.test-sheet { position: absolute; inset: 0; display: none; }
.test-sheet svg { width: 100%; height: 100%; display: block; }
html.testing .test-sheet { display: block; }
html.testing .content { display: none; }

.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center;
  z-index: 10;
}
.modal.hidden { display: none; }
.modal-body {
  background: var(--panel);
  border-radius: 8px;
  padding: 20px 24px;
  width: min(520px, 92vw);
  box-shadow: 0 10px 40px rgba(0,0,0,.25);
  line-height: 1.7;
}
.modal-body ol { padding-left: 1.4em; margin: 0 0 8px; }
.big-steps li { font-size: 16px; margin-bottom: 8px; }


/* ---------- ウェブ版 ---------- */
.web-only { display: none; }
html.web .web-only { display: list-item; }
html.web .printer-only,
html.web #dialogPrintBtn,
html.web #pdfBtn,
html.web .printer-info,
html.web .copies { display: none !important; }

.pdf-actions { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.pdf-actions button, .pdf-actions .btn { min-height: 48px; font-size: 17px; }
.btn {
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: 5px; background: #fff; color: var(--ink);
  text-decoration: none; font-size: 15px; padding: 6px 12px;
}
.btn:hover { border-color: var(--accent); }
.btn[hidden], .pdf-actions button[hidden] { display: none; }

/* ---------- スマートフォン（iPhone など） ---------- */
@media (max-width: 820px) {
  html, body { overflow: visible; height: auto; }
  body {
    flex-direction: column;
    font-size: 16px;
    padding-bottom: calc(80px + env(safe-area-inset-bottom));
    -webkit-text-size-adjust: 100%;
  }
  .panel {
    width: auto; height: auto; overflow: visible;
    border-right: none;
    padding: 12px max(14px, env(safe-area-inset-left)) 24px max(14px, env(safe-area-inset-right));
  }
  .preview {
    order: -1;
    position: sticky; top: 0; z-index: 5;
    flex: none; height: auto; overflow: visible;
    padding: calc(8px + env(safe-area-inset-top)) 12px 10px;
    background: var(--bg);
    box-shadow: 0 4px 12px rgba(0,0,0,.10);
  }
  .preview > .paper-holder { margin: 0 auto; }
  .warnings { margin-bottom: 6px; }
  .warn-item { font-size: 13px; padding: 5px 8px; gap: 6px; }
  .warn-item button { min-height: 34px; }
  .bottom-bar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
    background: var(--panel); border-top: 1px solid var(--line);
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
    flex-wrap: nowrap; gap: 8px;
  }
  .bar-group { gap: 6px; }
  .bar-group.end { flex: 1; }
  .bottom-bar .end button { min-height: 50px; }
  .bottom-bar .primary { flex: 1; padding: 8px 12px; min-width: 0; font-size: 17px; }
  .bottom-bar .primary small { display: none; }
  #undoBtn, #redoBtn { min-height: 50px; padding: 4px 10px; font-size: 13px; }
  input[type=text], input[type=number], select, textarea { font-size: 16px; min-height: 44px; }
  button { min-height: 44px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { flex-shrink: 0; min-height: 38px; }
  .chips button { min-height: 44px; font-size: 16px; }
  .modes label { min-height: 44px; font-size: 15px; }
  .ink-toggle span { min-height: 56px; }
  .presets { flex-wrap: wrap; }
  .presets select { flex: 1 1 100%; }
  .presets button { flex: 1; }
  .toast { bottom: calc(96px + env(safe-area-inset-bottom)) !important; max-width: 92vw; text-align: center; }
  .modal-body { width: min(520px, 94vw); padding: 18px; max-height: 90vh; overflow-y: auto; }
}

/* ---------- 印刷 ---------- */
@media print {
  html, body {
    width: var(--pw);
    height: var(--ph);
    overflow: hidden;
    background: #fff;
  }
  html[data-orient^=portrait], html[data-orient^=portrait] body { width: var(--ph); height: var(--pw); }
  .panel, .warnings, .bottom-bar, .modal, .guide, .art, .toast, .placeholder-name { display: none !important; }
  .col.over { outline: none; }
  .preview { padding: 0; display: block; }
  .paper-holder { width: auto !important; height: auto !important; }
  .paper { transform: none !important; box-shadow: none; }
  html[data-orient=landscape180] .paper { transform: translate(var(--pw), var(--ph)) rotate(180deg) !important; }
  html[data-orient=portrait90] .paper { transform: translateX(var(--ph)) rotate(90deg) !important; }
  html[data-orient=portrait270] .paper { transform: translateY(var(--pw)) rotate(-90deg) !important; }
}
