:root {
  --bg: #f4f1ea; --fg: #1d1d1b; --muted: #6a675f; --card: #fff; --line: #d9d4c7;
  --accent: #1f3a5f; --accent-fg: #fff; --danger: #b3261e;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 16px/1.5 -apple-system, "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", sans-serif; }
body.editing, body.writing { overflow: hidden; }
#app { min-height: 100%; display: flex; flex-direction: column; }
.muted { color: var(--muted); font-size: 14px; }
.bar { display: flex; align-items: center; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: var(--accent); color: var(--accent-fg); }
.bar h1 { flex: 1; margin: 0; font-size: 20px; }
.bar .btn.ghost { color: var(--accent-fg); }
.page { padding: 16px; display: grid; gap: 16px; max-width: 720px; width: 100%; margin: 0 auto; align-content: start; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px;
  font: inherit; font-weight: 600; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--fg);
  text-decoration: none; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 40px; padding: 0 12px; font-size: 15px; }
.btn.big { min-height: 56px; font-size: 18px; }
.btn:disabled { opacity: .45; }
.cards { display: grid; gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; gap: 10px; }
.card-main { color: inherit; text-decoration: none; }
.card-title { font-size: 18px; font-weight: 700; }
.card-actions { display: flex; gap: 8px; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 18px; border-radius: 999px; z-index: 100; font-size: 15px; }

/* editor */
.title-input { flex: 1; min-width: 0; font: inherit; font-size: 17px; padding: 8px 10px; border-radius: 8px; border: 0; }
.editor { flex: 1; display: flex; flex-direction: column; min-height: 0; height: calc(100dvh - 60px - env(safe-area-inset-top)); }
.stage-wrap { flex: 1; min-height: 0; overflow: auto; display: flex; padding: 12px; background: #e3ded2; }
.paper { position: relative; margin: auto; flex: none; box-shadow: 0 1px 6px rgba(0,0,0,.25); overflow: hidden; }
.block { cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
.block.selected { outline: 1.5px dashed #2a7de1; outline-offset: 2px; }
.toolrow { display: flex; gap: 8px; padding: 6px 12px; justify-content: space-between; background: var(--bg); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 4px 12px; background: var(--bg); }
.chip { flex: none; min-height: 38px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: #fff; font: inherit; }
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip.add { border-style: dashed; }
.sheet { background: #fff; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; max-height: 42vh; overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom); }
.tabs { display: flex; position: sticky; top: 0; background: #fff; border-bottom: 1px solid var(--line); }
.tab { flex: 1; min-height: 44px; border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; }
.tab.on { color: var(--accent); border-bottom-color: var(--accent); }
.sheet-body { padding: 12px; display: grid; gap: 12px; }
.sheet textarea, .sheet select, .sheet input[type=number], .sheet input[type=text] { width: 100%; font: inherit; font-size: 17px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; }
.field { display: grid; gap: 4px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 600; }
.num { display: grid; grid-template-columns: 48px 1fr 48px; gap: 6px; }
.range { display: grid; grid-template-columns: 1fr 52px; gap: 8px; align-items: center; }
.range input { width: 100%; height: 32px; }
.seg, .row, .swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.row .btn { flex: 1; }
.swatch { width: 40px; height: 40px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); }
input[type=color] { width: 56px; height: 44px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

/* dialog */
.dialog-back { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.dialog { background: #fff; border-radius: 16px; padding: 20px; max-width: 420px; width: 100%; display: grid; gap: 12px; max-height: 100%; overflow: auto; }
.dialog h2 { margin: 0; }
.warn { font-size: 20px; font-weight: 700; color: var(--danger); margin: 0; }
.warn2 { background: #fff4d6; padding: 8px 10px; border-radius: 8px; font-size: 14px; margin: 0; }
fieldset { border: 1px solid var(--line); border-radius: 10px; display: grid; gap: 6px; }
.radio { display: flex; gap: 10px; align-items: center; min-height: 40px; }
.radio input { width: 22px; height: 22px; }

/* 清書モード */
body.writing { background: #fff; overscroll-behavior: none; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.write-screen { position: fixed; inset: 0; background: #fff; display: flex; align-items: center; justify-content: center;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.write-paper { position: relative; background: #fff; flex: none; }
.block-write { pointer-events: none; }
.exit-zone { position: fixed; right: 0; bottom: 0; width: 88px; height: 88px; display: flex; align-items: flex-end; justify-content: flex-end; padding: 10px; }
.exit-zone::before { content: ''; position: absolute; right: 10px; bottom: 10px; width: 14px; height: 14px; border-radius: 50%; background: #d0d0d0; }
.exit-ring { position: absolute; right: -20px; bottom: -20px; width: 140px; height: 140px; border-radius: 50%; background: rgba(200,0,0,.25); transform: scale(0); transform-origin: 85% 85%; pointer-events: none; }

/* input tab / settings */
.group { display: grid; gap: 8px; }
.group h3 { margin: 0; font-size: 15px; }
.tags { display: flex; flex-wrap: wrap; gap: 8px; }
.tag { min-height: 44px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font: inherit; font-size: 17px; }
.tag.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.daiji-out { font-size: 24px; padding: 8px 12px; background: #faf8f2; border-radius: 8px; border: 1px solid var(--line); min-height: 48px; }
.section { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: grid; gap: 10px; }
.section h2 { margin: 0; font-size: 17px; }
.list-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.list-row input { width: 100%; font: inherit; font-size: 16px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; min-width: 0; }
.inline { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.calib-card { position: relative; margin: 12px auto; border: 2px solid #1f3a5f; border-radius: 4mm; background: rgba(31,58,95,.08); }

body.writing.inverted, .write-screen.invert, .write-screen.invert .write-paper { background: #000; }
.write-screen.invert .exit-zone::before { background: #555; }
