/* =========================================================
   みんなのメモ帳  スタイル  ── アナログ（紙ノート）風
   ========================================================= */
:root{
  --ink:#33312c;            /* 文字（黒インク） */
  --ink-soft:#6b6658;
  --paper:#fbf7ec;          /* 紙の色 */
  --paper-2:#fffdf6;
  --line:#e3dcc6;           /* ノートの罫線 */
  --green:#5a7a52;          /* メイン（インクの緑） */
  --green-d:#3d5a3d;
  --tape:#ecd9a4;           /* マスキングテープ */
  --red:#c0392b;            /* 赤ペン */
  --hi:#fff3a8;             /* 蛍光マーカー */
  --shadow:0 3px 0 #e4dac1;
}
*{ box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
/* hidden属性は最優先で非表示に（.overlay/.busy の display:flex に打ち消されないように） */
[hidden]{ display:none !important; }
html,body{ margin:0; padding:0; }
body{
  font-family:"Zen Maru Gothic","Yusei Magic",system-ui,-apple-system,sans-serif;
  color:var(--ink); line-height:1.8; font-size:16px;
  background:var(--paper);
  background-image:
    radial-gradient(circle at 18px 50%, #e7c7c1 2.6px, transparent 3px),  /* 左の綴じ穴 */
    linear-gradient(#0000 31px, var(--line) 32px);
  background-size: 100% 56px, 100% 32px;
  background-attachment: local;
  padding-left:8px;
}
@media(min-width:700px){ body{ padding-left:0; background-size:100% 56px,100% 34px; } }

/* ---------- ヘッダー ---------- */
.topbar{
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  padding:14px 18px; background:var(--green-d); color:#fdfcf5;
  box-shadow:0 2px 8px #0003; position:sticky; top:0; z-index:20;
}
.brand{ display:flex; align-items:center; gap:12px; }
.brand-ic{ font-size:30px; }
.topbar h1{ font-size:21px; margin:0; letter-spacing:.02em; }
.tagline{ font-size:12px; margin:0; color:#cfe0c4; }
.top-actions{ display:flex; gap:8px; }

/* ---------- ボタン共通 ---------- */
.btn{ font-family:inherit; font-size:15px; font-weight:700; cursor:pointer;
  border:none; border-radius:12px; padding:11px 16px; color:#fff; background:var(--green);
  box-shadow:0 3px 0 var(--green-d); transition:transform .05s; }
.btn:active{ transform:translateY(2px); box-shadow:0 1px 0 var(--green-d); }
.btn.primary{ background:var(--green); }
.btn.ghost{ background:#fff; color:var(--green-d); box-shadow:0 2px 0 #d7cdb2; border:1px solid #e0d6bd; }
.btn.danger{ background:#fff; color:var(--red); box-shadow:0 2px 0 #e3c4bf; border:1px solid #e8cdc8; }
.btn.ai{ background:#caa14a; box-shadow:0 3px 0 #a07f2f; }
.btn.big-new{ font-size:17px; padding:13px 20px; }
.icon-btn{ background:transparent; border:none; font-size:24px; cursor:pointer; color:#fff; padding:4px 8px; line-height:1; }
.sheet .icon-btn{ color:var(--ink-soft); }

/* ---------- 検索 ---------- */
.searchwrap{ max-width:880px; margin:22px auto 6px; padding:0 16px; }
.searchbox{ display:flex; align-items:center; gap:10px; background:#fff;
  border:2.5px solid var(--green); border-radius:16px; padding:6px 14px;
  box-shadow:0 4px 0 #d7cdb2; }
.search-ic{ font-size:22px; }
#search{ flex:1; border:none; outline:none; font-family:inherit; font-size:19px; background:transparent; color:var(--ink); padding:8px 0; }
.clear-search{ border:none; background:#eee5cf; color:#7a7158; width:30px; height:30px; border-radius:50%; font-size:20px; cursor:pointer; }
.search-hint{ font-size:12.5px; color:var(--ink-soft); margin:8px 4px 0; }

/* ---------- ツールバー ---------- */
.toolbar{ max-width:880px; margin:10px auto; padding:0 16px; display:flex;
  align-items:center; gap:12px; flex-wrap:wrap; justify-content:space-between; }
.cat-chips{ display:flex; gap:8px; flex-wrap:wrap; }
.chip{ font-family:inherit; font-size:14px; cursor:pointer; border:1.5px solid #d8cdaf;
  background:#fff; color:var(--ink-soft); border-radius:30px; padding:6px 14px; }
.chip.on{ background:var(--tape); color:var(--ink); border-color:#d6bd7e; font-weight:700;
  box-shadow:0 2px 0 #cdb579; }

/* ---------- メモ一覧（インデックスカード） ---------- */
.cards{ max-width:880px; margin:8px auto 60px; padding:0 16px;
  display:grid; grid-template-columns:repeat(auto-fill,minmax(250px,1fr)); gap:18px; }
.card{ position:relative; background:var(--paper-2); border:1px solid #e6ddc4;
  border-radius:6px 6px 10px 10px; padding:18px 16px 14px; cursor:pointer;
  box-shadow:var(--shadow); overflow:hidden;
  background-image:linear-gradient(#0000 27px, #eee6d0 28px); background-size:100% 28px; }
.card::before{ /* 上のマスキングテープ */
  content:""; position:absolute; top:-9px; left:50%; transform:translateX(-50%) rotate(-1.5deg);
  width:78px; height:20px; background:var(--tape); opacity:.85; border-radius:2px; box-shadow:0 1px 2px #0001; }
.card:hover{ transform:translateY(-2px) rotate(-.3deg); box-shadow:0 7px 14px #00000018; }
.card .no{ font-family:"Klee",serif; font-size:13px; color:#b08d3c; font-weight:700; }
.card .cat-tab{ position:absolute; top:14px; right:-2px; background:var(--green);
  color:#fff; font-size:11px; padding:2px 12px 2px 10px; border-radius:10px 0 0 10px; }
.card h3{ font-family:"Klee",serif; font-size:18px; margin:4px 0 6px; line-height:1.45; color:var(--ink); }
.card .snippet{ font-size:13.5px; color:var(--ink-soft); white-space:pre-wrap;
  display:-webkit-box; -webkit-line-clamp:4; -webkit-box-orient:vertical; overflow:hidden; }
.card .thumbs{ display:flex; gap:5px; margin-top:8px; }
.card .thumbs img{ width:44px; height:44px; object-fit:cover; border-radius:5px; border:2px solid #fff; box-shadow:0 1px 3px #0002; }
.card .tags{ margin-top:10px; display:flex; flex-wrap:wrap; gap:5px; }
.tag{ font-size:11px; background:var(--hi); color:#6b5a00; padding:1px 8px; border-radius:4px; }
.card .pin{ position:absolute; top:-4px; left:10px; font-size:18px; }
mark{ background:var(--hi); color:inherit; padding:0 2px; border-radius:3px; }

.empty{ text-align:center; color:var(--ink-soft); margin:60px auto; }
.empty-big{ font-size:22px; }

/* ---------- 使い方フッター ---------- */
.howto{ max-width:880px; margin:0 auto 80px; padding:0 16px; }
.howto details{ background:#fffdf6; border:1px dashed #cdbf99; border-radius:12px; padding:4px 16px; }
.howto summary{ cursor:pointer; font-weight:700; color:var(--green-d); padding:10px 0; font-size:15px; }
.howto-body p{ font-size:14px; margin:10px 0; }
.howto-body b{ color:var(--green-d); }

/* ---------- オーバーレイ＆シート ---------- */
.overlay{ position:fixed; inset:0; background:#33312caa; backdrop-filter:blur(2px);
  display:flex; align-items:flex-end; justify-content:center; z-index:40; }
@media(min-width:700px){ .overlay{ align-items:center; } }
.sheet{ background:var(--paper-2); width:100%; max-width:640px; max-height:92vh; overflow:auto;
  border-radius:18px 18px 0 0; box-shadow:0 -6px 30px #0005; }
@media(min-width:700px){ .sheet{ border-radius:18px; } }
.sheet-head{ display:flex; align-items:center; justify-content:space-between;
  padding:14px 18px; border-bottom:2px dashed #ddd2b4; position:sticky; top:0; background:var(--paper-2); z-index:2; }
.note-no{ font-family:"Klee",serif; font-weight:700; color:var(--green-d); font-size:17px; }
.sheet-body{ padding:18px; }
.sheet-foot{ display:flex; align-items:center; gap:10px; padding:14px 18px;
  border-top:2px dashed #ddd2b4; position:sticky; bottom:0; background:var(--paper-2); }
.spacer{ flex:1; }

/* ---------- フォーム ---------- */
.fld{ display:block; margin-bottom:16px; }
.fld-row{ display:flex; gap:12px; align-items:flex-end; }
.fld.grow{ flex:1; }
.fld-label{ display:block; font-size:13px; font-weight:700; color:var(--green-d); margin-bottom:6px; }
.fld-label small{ font-weight:400; color:var(--ink-soft); }
.fld input, .fld select, .fld textarea, #newCat{
  width:100%; font-family:inherit; font-size:16px; color:var(--ink);
  background:#fffef9; border:1.5px solid #d8cdaf; border-radius:10px; padding:11px 12px; outline:none; }
.fld textarea{ line-height:1.9; resize:vertical;
  background-image:linear-gradient(#0000 30px,#eee6d0 31px); background-size:100% 31px; }
.fld input:focus, .fld textarea:focus, .fld select:focus{ border-color:var(--green); box-shadow:0 0 0 3px #5a7a5233; }
.ai-bar{ margin:-6px 0 16px; }
.ai-bar .btn{ width:100%; }

/* 画像トレイ */
.img-tray{ display:flex; flex-wrap:wrap; gap:8px; margin-bottom:10px; }
.img-tray .thumb{ position:relative; }
.img-tray img{ width:84px; height:84px; object-fit:cover; border-radius:8px; border:3px solid #fff; box-shadow:0 2px 6px #0003; }
.img-tray .del{ position:absolute; top:-7px; right:-7px; width:24px; height:24px; border-radius:50%;
  background:var(--red); color:#fff; border:2px solid #fff; cursor:pointer; font-size:14px; line-height:1; }
.img-actions{ display:flex; flex-wrap:wrap; gap:8px; }
.img-actions .btn{ font-size:14px; padding:10px 12px; }

/* ---------- 詳細表示 ---------- */
.viewer .v-cat{ display:inline-block; background:var(--green); color:#fff; font-size:12px; padding:2px 12px; border-radius:20px; margin-bottom:8px; }
.viewer h2{ font-family:"Klee",serif; font-size:23px; margin:.1em 0 .4em; }
.v-body{ font-size:16.5px; white-space:pre-wrap; line-height:2; }
.v-images{ display:flex; flex-wrap:wrap; gap:10px; margin:16px 0; }
.v-images img{ max-width:100%; width:260px; border-radius:8px; border:4px solid #fff; box-shadow:0 3px 10px #0003; cursor:zoom-in; }
.v-tags{ margin-top:14px; display:flex; flex-wrap:wrap; gap:6px; }
.v-meta{ margin-top:18px; font-size:12px; color:var(--ink-soft); border-top:1px dashed #ddd2b4; padding-top:10px; }

/* ---------- QR ---------- */
.qr-body{ text-align:center; }
.qr-lead{ font-size:15px; }
.qr-img{ display:inline-block; padding:14px; background:#fff; border-radius:12px; box-shadow:0 3px 10px #0002; }
.qr-img img, .qr-img canvas, .qr-img table{ width:220px!important; height:220px!important; }
.qr-url{ font-size:12px; color:var(--ink-soft); word-break:break-all; }
.qr-status{ font-size:14px; color:var(--green-d); font-weight:700; }

/* ---------- カテゴリ管理 ---------- */
.cat-list{ list-style:none; padding:0; margin:0 0 14px; }
.cat-list li{ display:flex; align-items:center; gap:10px; padding:8px 6px; border-bottom:1px dashed #e0d6bd; }
.cat-list .grip{ cursor:grab; color:#bbae8d; }
.cat-list input{ flex:1; font-family:inherit; font-size:15px; border:1px solid #e0d6bd; border-radius:8px; padding:7px 10px; background:#fffef9; }
.cat-list .rm{ background:none; border:none; color:var(--red); font-size:18px; cursor:pointer; }

/* ---------- ラジオ・チェック ---------- */
.radio, .chk{ display:flex; align-items:center; gap:10px; font-size:15.5px; padding:9px 4px; cursor:pointer; }
.radio input, .chk input{ width:20px; height:20px; }

/* ---------- 処理中・トースト ---------- */
.busy{ position:fixed; inset:0; background:#fbf7eccc; display:flex; align-items:center; justify-content:center; z-index:60; }
.busy-card{ background:#fff; padding:26px 34px; border-radius:16px; box-shadow:0 8px 30px #0003; text-align:center; }
.spinner{ width:42px; height:42px; border:5px solid #e2d9c1; border-top-color:var(--green); border-radius:50%; margin:0 auto 14px; animation:spin 1s linear infinite; }
@keyframes spin{ to{ transform:rotate(360deg); } }
.busy-card p{ font-weight:700; color:var(--green-d); margin:0; }
.toast{ position:fixed; left:50%; bottom:26px; transform:translateX(-50%); background:var(--green-d); color:#fff;
  padding:13px 24px; border-radius:30px; font-size:15px; box-shadow:0 6px 20px #0004; opacity:0; transition:.3s; pointer-events:none; z-index:70; }
.toast.show{ opacity:1; }

/* =========================================================
   印刷（冊子）  ── 画面では #printArea は隠す
   ========================================================= */
#printArea{ display:none; }
@media print{
  body{ background:#fff; padding:0; }
  body > *{ display:none !important; }
  #printArea{ display:block !important; }

  @page{ size:A4; margin:14mm 12mm; }
  .p-cover{ text-align:center; padding-top:60mm; page-break-after:always; }
  .p-cover h1{ font-family:"Klee",serif; font-size:30pt; margin:0; }
  .p-cover p{ color:#555; }

  .p-index{ page-break-after:always; }
  .p-index h2{ font-family:"Klee",serif; font-size:16pt; border-bottom:2px solid #333; padding-bottom:4px; }
  .p-index ul{ list-style:none; padding:0; columns:2; column-gap:14mm; font-size:10.5pt; }
  .p-index li{ break-inside:avoid; padding:3px 0; border-bottom:1px dotted #bbb; }
  .p-index .pno{ font-weight:700; color:#000; margin-right:6px; }

  .p-note{ break-inside:avoid; border:1px solid #999; border-radius:5px; padding:8px 12px; margin-bottom:7mm; }
  .p-note.card-mode{ page-break-after:always; min-height:170mm; }
  .p-note .p-head{ display:flex; justify-content:space-between; align-items:flex-start; gap:10px;
    border-bottom:1.5px solid #333; padding-bottom:4px; margin-bottom:6px; }
  .p-note .p-no{ font-family:"Klee",serif; font-weight:700; font-size:15pt; white-space:nowrap; }
  .p-note .p-title{ font-family:"Klee",serif; font-size:14pt; font-weight:700; flex:1; }
  .p-note .p-cat{ font-size:9pt; border:1px solid #333; border-radius:10px; padding:0 8px; white-space:nowrap; }
  .p-note .p-qr{ width:22mm; height:22mm; }
  .p-note .p-qr img, .p-note .p-qr canvas, .p-note .p-qr table{ width:22mm!important; height:22mm!important; }
  .p-note .p-body{ font-size:11pt; white-space:pre-wrap; line-height:1.7; }
  .p-note .p-imgs{ margin-top:5px; display:flex; flex-wrap:wrap; gap:4mm; }
  .p-note .p-imgs img{ max-width:80mm; max-height:60mm; border:1px solid #ccc; }
  .p-note .p-tags{ margin-top:5px; font-size:9pt; color:#444; }
  .p-foot{ font-size:8pt; color:#888; text-align:center; }
}
