:root {
  --main: #155e75;
  --main-dark: #0e4152;
  --ink: #1f2933;
  --muted: #5f6b76;
  --line: #d5dbe1;
  --bg: #f3f5f7;
  --desk: #5b6470;
  --danger: #b42318;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- 一覧 ---------- */
#home { min-height: 100%; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.home-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; background: #fff; border-bottom: 1px solid var(--line);
}
.home-head img { border-radius: 10px; }
.home-head h1 { margin: 0; font-size: 22px; }
.home-head .sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.net { margin-left: auto; font-size: 13px; padding: 4px 10px; border-radius: 99px; background: #e7f6ec; color: #17663a; }
.net.off { background: #fff1e6; color: #a04a00; }
.home-body { max-width: 760px; margin: 0 auto; padding: 16px; }
.home-body h2 { font-size: 16px; margin: 24px 0 8px; color: var(--muted); }
.big-btn {
  display: flex; align-items: center; justify-content: center;
  min-height: 56px; padding: 0 20px; width: 100%;
  background: var(--main); color: #fff; border: 0; border-radius: 12px;
  font-size: 18px; font-weight: 700; cursor: pointer;
}
.big-btn:active { background: var(--main-dark); }
.big-btn.ghost { background: #fff; color: var(--main); border: 2px solid var(--main); }
.empty { color: var(--muted); background: #fff; border: 1px dashed var(--line); border-radius: 12px; padding: 20px; }
.docs { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.docs li { display: flex; background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.docs .open { flex: 1; text-align: left; background: none; border: 0; padding: 14px 16px; cursor: pointer; min-width: 0; }
.docs .open:active { background: #eef3f6; }
.docs .name { display: block; font-size: 17px; font-weight: 700; overflow-wrap: anywhere; }
.docs .meta { display: block; margin-top: 4px; font-size: 13px; color: var(--muted); }
.docs .del { background: none; border: 0; border-left: 1px solid var(--line); color: var(--danger); padding: 0 18px; cursor: pointer; }
.help { margin-top: 28px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; }
.help summary { cursor: pointer; font-weight: 700; }
.help li { margin: 8px 0; line-height: 1.6; }
.storage { color: var(--muted); font-size: 13px; }

/* ---------- 書き込み ---------- */
#editor {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.toolbar {
  background: #fff; border-bottom: 1px solid var(--line);
  padding: calc(6px + env(safe-area-inset-top)) calc(8px + env(safe-area-inset-right)) 6px calc(8px + env(safe-area-inset-left));
  display: grid; gap: 6px; z-index: 2;
}
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.title { flex: 1; min-width: 80px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.save-state { font-size: 13px; color: var(--muted); white-space: nowrap; }
.save-state.err { color: var(--danger); font-weight: 700; }
.page-no { font-size: 14px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.group { display: flex; gap: 4px; align-items: center; padding-right: 8px; border-right: 1px solid var(--line); }
.group:last-child { border-right: 0; }
.tb {
  min-height: 44px; min-width: 44px; padding: 0 12px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  font-size: 15px; cursor: pointer; white-space: nowrap;
}
.tb:active { background: #eef3f6; }
.tb.on { background: var(--main); border-color: var(--main); color: #fff; }
.tb.primary { background: var(--main); border-color: var(--main); color: #fff; font-weight: 700; }
.tb:disabled { opacity: .4; }
.tb.warn { border-color: #d97706; color: #b45309; font-weight: 700; }
.swatch { width: 40px; height: 40px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line); cursor: pointer; padding: 0; }
.swatch.on { box-shadow: 0 0 0 3px var(--main); }
.swatch[data-color="black"] { background: #111111; }
.swatch[data-color="red"] { background: #e11d24; }
.swatch[data-color="blue"] { background: #1d4ed8; }
.swatch[data-color="green"] { background: #15803d; }
.swatch[data-color="yellow"] { background: #facc15; }
.group.disabled { opacity: .35; pointer-events: none; }

#viewport {
  position: relative; flex: 1; overflow: hidden; background: var(--desk);
  touch-action: none; overscroll-behavior: none;
}
#stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.page { position: absolute; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.35); overflow: hidden; }
.page canvas.pdf { position: absolute; inset: 0; width: 100%; height: 100%; }
.page svg.ink { position: absolute; inset: 0; width: 100%; height: 100%; overflow: hidden; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 18px; }

/* ---------- 書き出し・お知らせ ---------- */
dialog { border: 0; border-radius: 16px; padding: 20px; width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h3 { margin: 0 0 6px; }
.export-name { color: var(--muted); overflow-wrap: anywhere; margin: 0 0 16px; }
.dlg-btns { display: grid; gap: 10px; }
.scale-btns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.scale-btns .tb.on { background: var(--main); border-color: var(--main); color: #fff; }
.note { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.6; }
.busy { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 20; }
.busy div { background: #fff; padding: 18px 24px; border-radius: 12px; font-weight: 700; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 30;
  display: flex; align-items: center; gap: 12px;
  max-width: calc(100vw - 32px); padding: 10px 16px;
  background: #1f2933; color: #fff; border-radius: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.3);
}
.toast .tb { color: var(--ink); }
