/* せんとかたち：紙とインクの雰囲気 */
:root {
  --bg: #f6f3ec;
  --surface: #fffdf8;
  --paper: #fffdf8;          /* 図を描く紙。暗い画面でも白いまま（黒い線が見えるように） */
  --ink: #24221f;
  --sub: #6f6a61;
  --line: #e3ddd0;
  --accent: #c2553a;
  --accent-ink: #fff;
  --danger: #b2382c;
  --chip: #efe9dc;
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 4px 14px rgba(40, 30, 10, .05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1917;
    --surface: #24221f;
    --ink: #ece7dd;
    --sub: #a49d90;
    --line: #3a3732;
    --accent: #e0775b;
    --chip: #2f2c28;
    --danger: #ec7365;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1a1917; --surface: #24221f; --ink: #ece7dd; --sub: #a49d90; --line: #3a3732;
  --accent: #e0775b; --chip: #2f2c28; --danger: #ec7365; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
h2, h3 { margin: 0; line-height: 1.35; }
p { margin: 0 0 8px; }
[hidden] { display: none !important; }

/* ---------- 上の帯 ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.top-inner {
  max-width: 920px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { font-weight: 700; letter-spacing: .08em; text-decoration: none; font-size: 17px; white-space: nowrap; }
.tabs { display: flex; gap: 4px; }
.tabs a {
  position: relative; text-decoration: none; color: var(--sub);
  padding: 6px 12px; border-radius: 999px; font-size: 14px; white-space: nowrap;
}
.tabs a.on { background: var(--ink); color: var(--bg); }
.dot {
  position: absolute; top: 3px; right: 3px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--accent); border: 2px solid var(--bg);
}

.view {
  max-width: 920px; margin: 0 auto;
  padding: 16px 16px calc(110px + env(safe-area-inset-bottom));
}

/* ---------- ボタン ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink);
  font: inherit; font-size: 15px; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; }
.link { background: none; border: 0; padding: 0; font: inherit; font-size: 12px; color: var(--sub); cursor: pointer; text-decoration: underline; }
.link.danger { color: var(--danger); }

.fab {
  position: fixed; z-index: 9;
  right: max(16px, env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom));
  min-height: 52px; padding: 0 22px; border: 0; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink);
  font: inherit; font-weight: 700; font-size: 16px; letter-spacing: .04em;
  box-shadow: 0 6px 20px rgba(194, 85, 58, .35); cursor: pointer;
}

/* ---------- 文字まわり ---------- */
.small { font-size: 13px; color: var(--sub); }
.center { text-align: center; }
.lead { color: var(--sub); font-size: 14px; }
.anon { color: var(--sub); }
.loading, .empty { text-align: center; color: var(--sub); padding: 48px 8px; grid-column: 1 / -1; }
.empty .btn { margin-top: 16px; }
.demo-note {
  font-size: 12px; color: var(--sub); background: var(--chip);
  border-radius: 8px; padding: 6px 10px; margin-bottom: 12px; text-align: center;
}
.pill {
  display: inline-block; font-size: 12px; padding: 2px 10px; border-radius: 999px;
  background: var(--chip); color: var(--sub); white-space: nowrap; vertical-align: middle;
}
.pill.now { background: var(--ink); color: var(--bg); }
h3 .pill { margin-left: 8px; }

/* ---------- 紙（図） ---------- */
.paper {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  aspect-ratio: 1;
  overflow: hidden;
}
.paper canvas { display: block; width: 100%; height: 100%; }

/* ---------- 一覧 ---------- */
.search input, .box input, .field input, .field textarea, .who-name {
  width: 100%; font: inherit; font-size: 16px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px;
}
.search { margin-bottom: 16px; }
.search input { border-radius: 999px; }

.grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.card {
  position: relative; display: block; text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 8px 10px; box-shadow: var(--shadow);
}
.card .paper { border: 0; border-radius: 8px; }
.card-word { font-weight: 700; font-size: 17px; margin: 8px 4px 0; overflow-wrap: anywhere; }
.card-meta { font-size: 12px; color: var(--sub); margin: 0 4px; }
.badge {
  position: absolute; top: 4px; right: 4px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
}

/* ---------- メモ ---------- */
.back { display: inline-block; text-decoration: none; color: var(--sub); font-size: 14px; padding: 4px 0 12px; }
.memo { max-width: 560px; margin: 0 auto; }
.memo-head { display: flex; align-items: center; gap: 10px; }
.memo-word { font-size: 30px; letter-spacing: .04em; overflow-wrap: anywhere; }
.memo-meta { color: var(--sub); font-size: 13px; margin-bottom: 12px; }
.paper.big { box-shadow: var(--shadow); }
.memo-note { font-size: 17px; margin: 14px 2px 6px; white-space: pre-wrap; }
.memo-ver { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 4px 2px 0; }
.reason {
  flex-basis: 100%; margin: 6px 0 0; padding: 10px 12px;
  border-left: 3px solid var(--accent); background: var(--chip); border-radius: 0 8px 8px 0;
  font-size: 14px; white-space: pre-wrap;
}
.reason span { display: block; font-size: 11px; color: var(--sub); }

.history { margin-top: 24px; }
.history h3 { font-size: 15px; margin-bottom: 8px; }
.history-row { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x proximity; }
.hv {
  flex: 0 0 96px; scroll-snap-align: start;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: 0; padding: 0; font: inherit; color: var(--ink); cursor: pointer;
}
.hv .paper { width: 96px; transition: outline-color .15s; outline: 2px solid transparent; outline-offset: 1px; }
.hv.on .paper { outline-color: var(--accent); }
.hv-label { font-size: 13px; font-weight: 600; }
.hv .small { font-size: 11px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }

/* ---------- コメント ---------- */
.comments { max-width: 560px; margin: 36px auto 0; padding-top: 24px; border-top: 1px dashed var(--line); }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.sec-head h3 { font-size: 18px; }
.cgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 16px; }
.cgrid > .small { grid-column: 1 / -1; }
.ccard {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px; box-shadow: var(--shadow);
}
.ccard .paper { border: 0; }
.ccard p { font-size: 14px; margin: 8px 2px 2px; white-space: pre-wrap; overflow-wrap: anywhere; }
.cmeta { font-size: 11px; color: var(--sub); margin: 2px; }
.to-ver { color: var(--accent); }
.clist { list-style: none; padding: 0; margin: 16px 0 0; }
.clist li { padding: 10px 2px; border-top: 1px solid var(--line); }
.clist p { font-size: 14px; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- シート（描く画面） ---------- */
.sheet {
  border: 0; padding: 0; margin: 0;
  width: 100%; max-width: 100%; height: 100%; max-height: 100%;
  background: var(--bg); color: var(--ink);
}
@media (min-width: 640px) {
  .sheet { margin: auto; width: 560px; height: auto; max-height: 94vh; border-radius: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
}
.sheet::backdrop { background: rgba(20, 18, 15, .45); }
.sheet-inner {
  padding: calc(8px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto;
}
.sheet-head { position: relative; display: flex; align-items: center; justify-content: center; min-height: 48px; margin-bottom: 8px; }
.sheet-head h2 { font-size: 17px; text-align: center; padding: 0 44px; }
.sheet-close {
  position: absolute; left: -6px; top: 2px; width: 44px; height: 44px;
  border: 0; background: none; color: var(--sub); font-size: 20px; cursor: pointer;
}
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--sub); margin-bottom: 4px; }
.field em { font-style: normal; font-size: 12px; }
.field textarea { resize: vertical; line-height: 1.5; }
.sheet-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.sheet-actions .btn { flex: 1; }

.who { border: 0; padding: 0; margin: 8px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 8px 10px; align-items: center; }
.who legend { font-size: 13px; color: var(--sub); margin-bottom: 4px; padding: 0; }
.who-opt { display: flex; align-items: center; gap: 6px; font-size: 15px; white-space: nowrap; min-height: 40px; }
.who-opt:last-of-type { grid-column: 1 / -1; }
.who-name { padding: 8px 12px; }
.who input[type="radio"] { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }

/* 描く道具 */
.pad-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-bottom: 8px; }
.pad-colors, .pad-widths, .pad-acts { display: flex; gap: 6px; align-items: center; }
.swatch {
  width: 32px; height: 32px; border-radius: 50%; border: 0; padding: 0; cursor: pointer;
  background: var(--sw); outline: 2px solid transparent; outline-offset: 2px;
}
.swatch.on { outline-color: var(--ink); }
.wbtn {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; cursor: pointer; padding: 0;
}
.wbtn i { display: block; width: var(--d); height: var(--d); border-radius: 50%; background: var(--ink); }
.wbtn.on { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.tbtn {
  min-height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-size: 13px; cursor: pointer;
}
.tbtn.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.pad-paper {
  background: var(--paper); border: 1px solid var(--line); border-radius: 12px;
  aspect-ratio: 1; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(0,0,0,.02);
  max-height: 62vh; margin: 0 auto;
}
.pad-canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.pad-paper.erasing .pad-canvas { cursor: cell; }

/* ---------- 設定・入口 ---------- */
.page-title { font-size: 22px; margin-bottom: 16px; }
.box {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; max-width: 560px;
}
.box h3 { font-size: 16px; margin-bottom: 8px; }
.box.warn { border-color: var(--accent); }
.box .btn { margin-top: 6px; }
.row { display: flex; gap: 8px; margin: 4px 0 8px; }
.about p { color: var(--sub); font-size: 14px; }

.gate { max-width: 420px; margin: 0 auto; padding: 18vh 8px 0; text-align: center; }
.gate-title { font-size: 34px; letter-spacing: .14em; margin: 0 0 12px; }
.gate-lead { color: var(--sub); margin-bottom: 32px; }
.gate-alt { margin-top: 40px; padding-top: 24px; border-top: 1px dashed var(--line); }

/* ---------- お知らせ ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 100;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 14px; width: max-content; max-width: calc(100% - 32px); text-align: center;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
