/* メモ — Cairn と同じ「紙のような画面」のデザイン */
:root {
  --bg: #f2f2ef;
  --card: #ffffff;
  --fg: #1b1b1d;
  --sub: #a3a3a6;
  --sub2: #c6c6c8;
  --hairline: #e7e7e4;
  --pill: #4a4a4c;
  --red: #e5484d;
  --blue: #2f6bff;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  /* iPhone を横にしたとき、切り欠き（ノッチ）のある側に文字やボタンが入りこまないように */
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --pad-l: calc(20px + var(--safe-left));
  --pad-r: calc(20px + var(--safe-right));
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161618;
    --card: #232326;
    --fg: #ececee;
    --sub: #86868a;
    --sub2: #5a5a5e;
    --hairline: #313134;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
button, input, textarea { font: inherit; color: var(--fg); }
button { background: none; border: 0; padding: 0; cursor: pointer; }
button:active, .btn-dark:active, .note-row:active { transform: scale(0.97); }
button, .btn-dark, .note-row { transition: transform 0.12s var(--ease), background 0.15s; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }

.view { min-height: 100dvh; display: flex; flex-direction: column; animation: fade 0.18s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---- 見出しとピル ---- */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 14px) var(--pad-r) 10px var(--pad-l);
}
.list-header { justify-content: flex-end; }
.page-title { font-size: 27px; font-weight: 800; letter-spacing: 0.01em; margin: 0; }
.header-pill {
  display: flex; align-items: center; gap: 2px;
  background: var(--pill); border-radius: 999px; padding: 3px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
.pill-icon { position: relative; width: 38px; height: 34px; border-radius: 999px; color: #fff; display: grid; place-items: center; }
.pill-icon svg { width: 19px; height: 19px; }
.pill-icon:active { background: rgba(255, 255, 255, 0.12); }
.dot { position: absolute; top: 6px; right: 7px; width: 7px; height: 7px; border-radius: 50%; background: #5ad17a; }

/* ---- さがす ---- */
.search-bar { display: flex; gap: 12px; align-items: center; padding: 0 var(--pad-r) 8px var(--pad-l); }
.search-bar input {
  flex: 1; border: 0; outline: 0; border-radius: 12px; padding: 9px 12px;
  background: var(--card); font-size: 16px;
}
.search-bar button { color: var(--sub); font-size: 14px; }

/* ---- 一覧 ---- */
.list-scroll { flex: 1; padding-bottom: calc(var(--safe-bottom) + 100px); }
.note-list { list-style: none; margin: 0; padding: 4px 0; }
.note-row { display: block; padding: 12px var(--pad-r) 12px var(--pad-l); cursor: pointer; user-select: none; }
.note-title { font-size: 16.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-meta { font-size: 12.5px; color: var(--sub); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-meta .shared { color: var(--fg); }
.empty-hint { color: var(--sub); text-align: center; margin-top: 30vh; font-size: 14px; padding: 0 var(--pad-r) 0 var(--pad-l); }

.fab {
  position: fixed; right: calc(22px + var(--safe-right)); bottom: calc(var(--safe-bottom) + 22px);
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--fg); color: var(--bg);
  display: grid; place-items: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}
.fab svg { width: 24px; height: 24px; stroke-width: 2.2; }
.fab:active { transform: scale(0.9); }

/* ---- 書く画面 ---- */
#view-editor { height: 100dvh; }
.editor-header {
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 10px) var(--pad-r) 6px calc(10px + var(--safe-left));
}
.plain-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; }
.plain-btn svg { width: 24px; height: 24px; stroke-width: 2; }
.save-state { flex: 1; font-size: 12px; color: var(--sub); }
.save-state.error { color: var(--red); }
.editor-scroll {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; cursor: text;
  padding: 8px var(--pad-r) calc(var(--safe-bottom) + 40px) var(--pad-l);
}
.ed-title, .ed-body {
  display: block; width: 100%; resize: none; border: 0; outline: 0; background: transparent;
  padding: 0; margin: 0; overflow: hidden;
  font-size: 17px; line-height: 1.75;
}
.ed-title { font-weight: 700; }
.ed-body { min-height: 60dvh; }
.ed-title::placeholder { color: var(--sub2); font-weight: 400; }

/* ---- 下から出るメニュー ---- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.25); animation: fade 0.2s ease; z-index: 10; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11;
  background: var(--card); border-radius: 22px 22px 0 0;
  padding: 8px calc(8px + var(--safe-right)) calc(var(--safe-bottom) + 14px) calc(8px + var(--safe-left));
  box-shadow: 0 -2px 20px rgba(0, 0, 0, 0.1);
  animation: sheet-up 0.3s var(--ease);
  max-width: 560px; margin: 0 auto;
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
.sheet-grip { width: 36px; height: 5px; border-radius: 3px; background: var(--sub2); margin: 0 auto 8px; }
.sheet-note { font-size: 13px; color: var(--sub); padding: 6px 14px 10px; line-height: 1.6; }
.sheet-title { font-size: 13px; font-weight: 700; padding: 8px 14px 2px; }
.sheet-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; text-align: left; padding: 14px; border-radius: 12px; font-size: 16px;
}
.sheet-item:active { background: var(--bg); transform: none; }
.sheet-item.danger { color: var(--red); }
.sheet-item .sub { color: var(--sub); font-size: 13px; }
.share-url {
  margin: 4px 14px 8px; padding: 10px 12px; border-radius: 10px; background: var(--bg);
  font-size: 13px; word-break: break-all; user-select: all;
}

/* スイッチ */
.toggle { position: relative; width: 46px; height: 28px; border-radius: 999px; background: var(--sub2); flex: none; transition: background 0.2s; }
.toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); transition: transform 0.2s var(--ease);
}
.toggle.on { background: var(--fg); }
.toggle.on::after { transform: translateX(18px); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 96px); transform: translateX(-50%);
  background: #3d3d3f; color: #fff; font-size: 14px; padding: 10px 16px; border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28); z-index: 20; white-space: nowrap; animation: fade 0.2s ease;
}

/* ---- ログイン ---- */
.login { margin: auto; padding: 0 28px; max-width: 420px; text-align: center; }
.login-text { color: var(--sub); font-size: 14px; line-height: 1.7; margin: 14px 0 26px; }
.login-error { color: var(--red); font-size: 13px; margin-top: 18px; line-height: 1.6; }
.btn-dark {
  display: inline-block; background: var(--fg); color: var(--bg); text-decoration: none;
  padding: 13px 24px; border-radius: 999px; font-weight: 600; font-size: 15px;
}

/* ---- 見せる用のページ（/s/〜） ---- */
.share-page { max-width: 720px; margin: 0 auto; padding: calc(var(--safe-top) + 28px) var(--pad-r) calc(var(--safe-bottom) + 40px) var(--pad-l); }
.share-meta { font-size: 12px; color: var(--sub); margin-bottom: 18px; }
.share-body { font-size: 17px; line-height: 1.8; white-space: pre-wrap; word-break: break-word; }
.share-body a { color: inherit; }
.share-actions { display: flex; gap: 18px; margin-top: 40px; }
.text-btn { color: var(--sub); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }

/* ---- 大きい画面では、真ん中に寄せる ---- */
@media (min-width: 760px) {
  .view > * { width: 100%; max-width: 720px; margin-left: auto; margin-right: auto; }
  .fab { right: max(calc(22px + var(--safe-right)), calc(50% - 360px + 22px)); }
}

/* ---- PDF で保存（印刷）するときは、メモの文字だけを出す ---- */
.print-area { display: none; }
@media print {
  @page { margin: 18mm 16mm; }
  body { background: #fff; color: #000; }
  body.printing > *:not(#print-area) { display: none !important; }
  body.printing #print-area { display: block; font-size: 11pt; line-height: 1.8; white-space: pre-wrap; word-break: break-word; }
  body.share .share-meta, body.share .share-actions { display: none; }
  body.share .share-page { padding: 0; }
  body.share .share-body { font-size: 11pt; color: #000; }
}
