/* =========================================================================
   Magic Shelf v2.0 — B「奇術書の書斎 / The Conjuror's Study」
   design-reference-b.html BOARD B のトークン・形の原則を適用。
   原則: 角丸全廃（例外: 蔵書印の円・操作系の2pxまで）／カード=二重枠の蔵書票
         ステータス=朱の蔵書印（円形・-12deg）／チップ=直角1px枠・選択は藍墨ベタ
   ========================================================================= */

:root {
  --ground: #F3EBDA;        /* 古紙 */
  --surface: #F9F4E6;       /* 本文紙（札） */
  --surface2: #EDE3CE;      /* 沈み */
  --ink: #22303B;           /* 藍墨 */
  --ink-soft: #5A6570;
  --line: #C9BFA6;          /* 淡罫 */
  --line-strong: #A99F86;   /* チップ枠 */
  --brass: #8E3B2C;         /* 弁柄（アクセント） */
  --brass-strong: #7A3325;
  --crimson: #B0402D;       /* 蔵書印の朱 */
  --play: #22303B;          /* 主ボタン=藍墨ベタ */
  --chip-ink: #F3EBDA;      /* ベタ地の上の文字 */
  --suit-ink: rgba(34, 48, 59, .30);
  --thumb1: #E9DDC2;        /* サムネ無し紋様地 video */
  --thumb2: #E4DAC6;        /* pdf */
  --thumb3: #ECE0C4;        /* link */
  --thumb4: #E6D9BD;        /* disc */
  --paper-rule: rgba(34, 48, 59, .035);
  --shadow: 0 1px 0 rgba(34, 48, 59, .12), 0 8px 22px rgba(34, 48, 59, .12);
}
@media (prefers-color-scheme: dark) {
  :root {
    /* 夜の書斎: ランプ色に沈めた紙 */
    --ground: #1F1A12;
    --surface: #2A2317;
    --surface2: #241E13;
    --ink: #EDE3CC;
    --ink-soft: #B5A88E;
    --line: #4A4130;
    --line-strong: #5F553F;
    --brass: #C4694F;
    --brass-strong: #D07A62;
    --crimson: #D96A52;
    --play: #EDE3CC;
    --chip-ink: #1F1A12;
    --suit-ink: rgba(237, 227, 204, .22);
    --thumb1: #332B1B;
    --thumb2: #302A1E;
    --thumb3: #362E1C;
    --thumb4: #2E2717;
    --paper-rule: rgba(237, 227, 204, .04);
    --shadow: 0 1px 0 rgba(0, 0, 0, .5), 0 10px 26px rgba(0, 0, 0, .45);
  }
}
:root[data-theme="light"] {
  --ground: #F3EBDA; --surface: #F9F4E6; --surface2: #EDE3CE; --ink: #22303B; --ink-soft: #5A6570;
  --line: #C9BFA6; --line-strong: #A99F86; --brass: #8E3B2C; --brass-strong: #7A3325;
  --crimson: #B0402D; --play: #22303B; --chip-ink: #F3EBDA;
  --suit-ink: rgba(34, 48, 59, .30);
  --thumb1: #E9DDC2; --thumb2: #E4DAC6; --thumb3: #ECE0C4; --thumb4: #E6D9BD;
  --paper-rule: rgba(34, 48, 59, .035);
  --shadow: 0 1px 0 rgba(34, 48, 59, .12), 0 8px 22px rgba(34, 48, 59, .12);
}
:root[data-theme="dark"] {
  --ground: #1F1A12; --surface: #2A2317; --surface2: #241E13; --ink: #EDE3CC; --ink-soft: #B5A88E;
  --line: #4A4130; --line-strong: #5F553F; --brass: #C4694F; --brass-strong: #D07A62;
  --crimson: #D96A52; --play: #EDE3CC; --chip-ink: #1F1A12;
  --suit-ink: rgba(237, 227, 204, .22);
  --thumb1: #332B1B; --thumb2: #302A1E; --thumb3: #362E1C; --thumb4: #2E2717;
  --paper-rule: rgba(237, 227, 204, .04);
  --shadow: 0 1px 0 rgba(0, 0, 0, .5), 0 10px 26px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--ground);
  color: var(--ink);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Noto Sans JP", system-ui, sans-serif;
  line-height: 1.7;
}
.serif { font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif; }
a { color: var(--brass-strong); }
button { font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ---------------------------------------------------------------------- */
/* Landing / auth (index.html)                                            */
/* ---------------------------------------------------------------------- */
.landing-wrap {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 20px 60px;
  gap: 32px;
  background:
    repeating-linear-gradient(0deg, transparent 0 26px, var(--paper-rule) 26px 27px),
    var(--ground);
}
.landing-hero { max-width: 500px; text-align: center; }
.landing-eyebrow {
  font-size: 12px; letter-spacing: .24em; color: var(--brass);
  text-transform: uppercase; margin-bottom: 10px;
}
.landing-hero h1 {
  font-size: clamp(24px, 5vw, 32px); font-weight: 600; text-wrap: balance; margin-bottom: 10px;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
}
.landing-hero p { color: var(--ink-soft); font-size: 14px; }

.auth-card {
  width: 100%; max-width: 380px;
  background: var(--surface); border: 1px solid var(--ink);
  outline: 1px solid var(--ink); outline-offset: 3px;
  border-radius: 0;
  box-shadow: var(--shadow); padding: 24px 24px 28px;
}
.auth-tabs { display: flex; gap: 4px; margin-bottom: 20px; background: var(--surface2); border-radius: 0; padding: 4px; }
.auth-tab {
  flex: 1; border: none; background: transparent; color: var(--ink-soft);
  padding: 8px 10px; border-radius: 0; font-size: 13.5px; font-weight: 700; cursor: pointer;
}
.auth-tab[aria-selected="true"] { background: var(--ink); color: var(--ground); }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form label { font-size: 12.5px; color: var(--ink-soft); display: flex; flex-direction: column; gap: 5px; }
.auth-form input {
  background: var(--surface2); border: 1px solid var(--line-strong); border-radius: 2px;
  padding: 10px 12px; font-size: 14px; color: var(--ink);
}
.auth-form input:focus-visible { outline: 2px solid var(--brass); outline-offset: 1px; }
.auth-submit {
  margin-top: 6px; background: var(--brass); color: var(--chip-ink); border: none; border-radius: 0;
  padding: 11px 16px; font-size: 14.5px; font-weight: 700; cursor: pointer;
}
.auth-submit:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.auth-submit:disabled { opacity: .6; cursor: default; }
.auth-error {
  font-size: 12.5px; color: var(--crimson); background: var(--surface2);
  border-left: 2px solid var(--crimson); border-radius: 0; padding: 8px 10px; display: none;
}
.auth-error.show { display: block; }
.auth-hint { font-size: 11.5px; color: var(--ink-soft); margin-top: 4px; }

/* ---------------------------------------------------------------------- */
/* App shell (shelf.html)                                                 */
/* ---------------------------------------------------------------------- */
.page { max-width: 1100px; margin: 0 auto; padding: 24px 16px 60px; }

.app {
  background: var(--surface2);
  border: 3px double var(--ink);
  border-radius: 0;
  box-shadow: var(--shadow); overflow: hidden;
}
.app-bar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 16px 22px; border-bottom: 1px solid var(--ink);
  background: var(--surface);
}
.logo { display: flex; align-items: baseline; gap: 10px; white-space: nowrap; }
.logo .mark { font-size: 20px; font-weight: 700; letter-spacing: .06em; }
.logo .mark .amp { color: var(--brass); }
.logo .tag { font-size: 11px; color: var(--ink-soft); letter-spacing: .2em; }

.search {
  flex: 1; min-width: 200px; display: flex; align-items: center; gap: 8px;
  background: var(--surface2); border: 1px solid var(--line-strong); border-radius: 2px; padding: 0 12px;
  color: var(--ink-soft); font-size: 13px;
}
.search svg { flex: none; }
.search input {
  flex: 1; border: none; background: transparent; padding: 9px 0; font-size: 13.5px; color: var(--ink);
}
.search input::placeholder { color: var(--ink-soft); }
.search input:focus { outline: none; }

.user { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink-soft); position: relative; }
.avatar {
  /* 円形は「蔵書印」の例外扱い: 持ち主の印 */
  width: 32px; height: 32px; border-radius: 50%;
  background: transparent; color: var(--crimson);
  border: 2px solid var(--crimson); transform: rotate(-12deg);
  display: grid; place-items: center; font-size: 13px; font-weight: 700; cursor: pointer;
  opacity: .9;
}
.user-menu {
  position: absolute; top: calc(100% + 8px); right: 0; background: var(--surface); border: 1px solid var(--ink);
  border-radius: 0; box-shadow: var(--shadow); padding: 6px; min-width: 160px; display: none; z-index: 20;
}
.user-menu.open { display: block; }
.user-menu button {
  width: 100%; text-align: left; background: none; border: none; padding: 8px 10px; border-radius: 0;
  font-size: 13px; color: var(--ink); cursor: pointer;
}
.user-menu button:hover { background: var(--surface2); }

.stats { display: flex; gap: 0; border-bottom: 1px solid var(--ink); overflow-x: auto; background: var(--surface); }
.stat { padding: 14px 22px; border-right: 1px solid var(--line); min-width: 120px; }
.stat b {
  display: block; font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.2;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif; letter-spacing: .04em;
}
.stat span { font-size: 11.5px; color: var(--ink-soft); letter-spacing: .1em; }
.stat.hl b { color: var(--brass-strong); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 16px 22px 4px; }
.toolbar .label { font-size: 11.5px; color: var(--ink-soft); letter-spacing: .2em; margin-right: 2px; }
.chip {
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  border-radius: 0; padding: 4px 14px; font-size: 12px; letter-spacing: .1em; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.chip:hover { border-color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--ground); border-color: var(--ink); }
.chip:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

.sort-wrap { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.sort-select {
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 0;
  padding: 4px 10px; font-size: 12.5px; color: var(--ink); cursor: pointer; font-family: inherit;
}
.sort-select:focus-visible { outline: 2px solid var(--brass); outline-offset: 1px; }

.quickadd {
  margin: 14px 22px 6px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  background: var(--surface); border: 1px dashed var(--brass); border-radius: 0; padding: 12px 14px;
}
.quickadd input {
  flex: 1; min-width: 220px; background: var(--surface2); border: 1px solid var(--line-strong); border-radius: 2px;
  padding: 9px 12px; font-size: 13.5px; color: var(--ink);
}
.quickadd input:focus-visible { outline: 2px solid var(--brass); outline-offset: 1px; }
.quickadd button {
  background: var(--brass); color: var(--chip-ink); border: none; border-radius: 0;
  padding: 9px 18px; font-size: 13.5px; font-weight: 700; cursor: pointer;
}
.quickadd button.memo-btn { background: var(--crimson); }
.quickadd button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.quickadd .hint { width: 100%; font-size: 11.5px; color: var(--ink-soft); }

.empty-state {
  margin: 18px 22px 26px; padding: 32px 20px; text-align: center; color: var(--ink-soft);
  border: 1px dashed var(--line-strong); border-radius: 0; font-size: 13.5px; display: none;
}
.empty-state.show { display: block; }

/* ---- カード = 蔵書票（Ex Libris） ---- */
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 22px; padding: 22px 26px 30px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--ink);
  outline: 1px solid var(--ink); outline-offset: 3px; /* 二重枠 */
  border-radius: 0; overflow: hidden;
  display: flex; flex-direction: column; transition: transform .15s, box-shadow .15s; cursor: pointer;
  text-align: left; font: inherit; color: inherit;
  touch-action: pan-y;
}
.card:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.card:focus-visible { box-shadow: 0 0 0 3px var(--brass); }
.card.dragging {
  opacity: .6; box-shadow: var(--shadow); cursor: grabbing;
  transition: none; transform: none; pointer-events: none;
}
.drag-placeholder {
  border: 1px dashed var(--brass);
  outline: 1px dashed var(--brass); outline-offset: 3px;
  border-radius: 0;
  background: var(--surface2); opacity: .6; min-height: 80px;
}
body.drag-active { user-select: none; -webkit-user-select: none; }
@media (prefers-reduced-motion: reduce) {
  .card, .card:hover { transition: none; transform: none; }
}
.thumb {
  aspect-ratio: 16/9; display: grid; place-items: center; position: relative;
  color: var(--suit-ink); font-size: 40px; background-size: cover; background-position: center;
  border-bottom: 1px solid var(--line);
}
.thumb .suit { filter: none; }
.thumb-img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; display: block;
  filter: sepia(.12);
}
/* サムネ無し: スート柄を藍墨の淡い紋様風に（紙のトーン違い） */
.t-video { background: var(--thumb1); }
.t-pdf { background: var(--thumb2); }
.t-link { background: var(--thumb3); }
.t-disc { background: var(--thumb4); }
.badge {
  position: absolute; top: 10px; left: 10px; font-size: 10px; font-weight: 700; letter-spacing: .14em;
  padding: 3px 9px; border-radius: 0; color: var(--chip-ink);
}
.b-ext { background: var(--ink); color: var(--ground); }
.b-file { background: var(--brass); }
.b-phys { background: #6B5B45; }

/* =========================================================================
   v4.7 C 札の種類を視覚的に区別（意匠シグネチャ）
   枠サイズは共通のまま、サムネ/枠の意匠だけを種類ごとに変える。
   バッジ・操作系は意匠より前面（z-index）に置く。
   ========================================================================= */
.badge, .thumb-actions, .keybadge, .local-stamp, .pdf-tag { z-index: 3; }

/* ② ローカル動画: フィルムの縁＋朱の「ローカル」印 */
.card.t-localv .thumb { background: linear-gradient(150deg, #26303a, #12181e); }
.card.t-localv .thumb::before,
.card.t-localv .thumb::after {
  content: ""; position: absolute; left: 0; right: 0; height: 11px; z-index: 1;
  background-color: #1b222a;
  background-image: repeating-linear-gradient(90deg, #0d1116 0 6px, transparent 6px 12px);
}
.card.t-localv .thumb::before { top: 0; }
.card.t-localv .thumb::after { bottom: 0; }
.card.t-localv .thumb .suit { color: rgba(255, 255, 255, .82); z-index: 2; }
.local-stamp {
  position: absolute; right: 8px; top: 8px; width: 33px; height: 33px; border-radius: 50%;
  border: 1.5px solid var(--crimson); color: var(--crimson);
  background: rgba(249, 244, 230, .86);
  display: grid; place-items: center; text-align: center; line-height: 1.05;
  font-size: 8.5px; font-weight: 700; letter-spacing: .02em; transform: rotate(-10deg);
}

/* ③ ローカルPDF/文書: 書類＋角折れの意匠 */
.card.t-pdf .thumb { background: var(--thumb2); }
.doc-motif {
  width: 56%; height: 76%; background: var(--surface); border: 1px solid var(--line-strong);
  position: relative; padding: 11px 9px; display: flex; flex-direction: column; gap: 5px;
  box-shadow: 2px 3px 0 rgba(34, 48, 59, .08);
}
.doc-motif::after {
  content: ""; position: absolute; top: 0; right: 0;
  border-width: 0 13px 13px 0; border-style: solid;
  border-color: var(--surface2) var(--surface2) transparent transparent;
  box-shadow: -1px 1px 0 var(--line-strong);
}
.doc-motif i { display: block; height: 2px; background: var(--line); border-radius: 1px; }
.doc-motif i:nth-child(1) { width: 70%; }
.doc-motif i:nth-child(2) { width: 90%; }
.doc-motif i:nth-child(3) { width: 58%; }
.doc-motif i:nth-child(4) { width: 82%; }
.pdf-tag {
  position: absolute; left: 9px; bottom: 9px; font-size: 9.5px; font-weight: 700; letter-spacing: .1em;
  color: var(--brass-strong); border: 1px solid var(--brass); padding: 1px 6px; background: var(--surface);
}

/* ④ 物理・本: 背表紙＋表紙・明朝題字 */
.card.t-book .thumb { background: linear-gradient(135deg, #c9b48b, #a68a5c); }
.book-spine {
  position: absolute; left: 0; top: 0; bottom: 0; width: 15px; z-index: 2;
  background: linear-gradient(90deg, #5b2a22, #7a3a2e 60%, #8e4636);
  border-right: 1px solid rgba(0, 0, 0, .28); box-shadow: inset -3px 0 5px rgba(0, 0, 0, .25);
}
.book-face-title {
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
  color: #3a2a18; font-size: 13px; letter-spacing: .06em; line-height: 1.5;
  text-align: center; padding: 0 14px 0 24px; text-shadow: 0 1px 0 rgba(255, 255, 255, .25);
}
.card.t-book .card-title { font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif; }

/* ⑤ 物理・DVD: ディスクの意匠 */
.card.t-dvd .thumb { background: var(--thumb4); }
.disc-motif {
  width: 66%; aspect-ratio: 1; border-radius: 50%; position: relative;
  background:
    radial-gradient(circle at 50% 50%, var(--surface2) 0 15%, transparent 15.5% 17%, #8891a0 17.5%),
    conic-gradient(from 0deg, #aeb7c4, #7c8593, #c3ccd8, #8891a0, #aeb7c4);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .25);
}
.disc-motif::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle, transparent 0 46%, rgba(255, 255, 255, .12) 47% 100%);
}
.disc-hole {
  position: absolute; top: 50%; left: 50%; width: 15%; aspect-ratio: 1; transform: translate(-50%, -50%);
  border-radius: 50%; background: var(--surface2); border: 1px solid var(--line-strong);
}
.keybadge {
  position: absolute; right: 10px; top: 10px; width: 26px; height: 26px; border-radius: 0;
  background: var(--surface); border: 1px solid var(--ink);
  display: grid; place-items: center; font-size: 13px;
}
.thumb-clickable { cursor: pointer; }
.thumb-actions {
  position: absolute; right: 10px; bottom: 10px;
  display: flex; gap: 6px; align-items: center;
}
.openbtn {
  background: var(--play); color: var(--chip-ink); border: none; border-radius: 0;
  padding: 5px 12px; font-size: 11.5px; font-weight: 700; cursor: pointer;
  letter-spacing: .08em; box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
}
.openbtn:hover { filter: brightness(1.1); }
.openbtn:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.dlbtn {
  background: var(--brass); color: var(--chip-ink); border: none; border-radius: 0;
  width: 27px; height: 27px; display: grid; place-items: center;
  font-size: 13px; font-weight: 700; cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
}
.dlbtn:hover { filter: brightness(1.1); }
.dlbtn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.copybtn {
  background: var(--ink); color: var(--ground); border: none; border-radius: 0;
  width: 27px; height: 27px; display: grid; place-items: center;
  font-size: 13px; cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
}
.copybtn:hover { filter: brightness(1.2); }
.copybtn:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

.ms-toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(8px);
  background: var(--ink); color: var(--ground);
  padding: 8px 18px; border-radius: 0; font-size: 13px; font-weight: 700; letter-spacing: .06em;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 300;
}
.ms-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card-title {
  font-size: 15px; font-weight: 600; line-height: 1.5;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
  border-bottom: 1.5px solid var(--ink); padding-bottom: 7px; position: relative; /* 二重罫（太） */
}
.card-title::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -4px;
  border-bottom: .5px solid var(--ink); /* 二重罫（細） */
}
.card-sub { font-size: 12px; color: var(--ink-soft); margin-top: 3px; }
.card-note {
  font-size: 12px; color: var(--ink-soft); background: transparent;
  border-left: 2px solid var(--line);
  padding: 2px 0 2px 11px; border-radius: 0; line-height: 1.9;
}
.card-foot { display: flex; justify-content: space-between; align-items: center; margin-top: auto; padding-top: 6px; gap: 6px; }
/* ---- ステータス = 朱の蔵書印（クリックで状態メニュー） ---- */
.status {
  width: 48px; height: 48px; border-radius: 50%;
  border: 2px solid var(--crimson); color: var(--crimson); background: transparent;
  display: grid; place-items: center; text-align: center;
  font-size: 9.5px; font-weight: 700; line-height: 1.25; letter-spacing: .05em;
  transform: rotate(-12deg); opacity: .85;
  padding: 2px; white-space: normal; word-break: break-all;
  flex: none;
  font-family: inherit; cursor: pointer;
}
.status:hover { opacity: 1; }
.status:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.s-rep, .s-prac, .s-new, .s-idea, .s-custom { background: transparent; color: var(--crimson); border-color: var(--crimson); }
.src { font-size: 11px; color: var(--ink-soft); letter-spacing: .04em; }
/* 派生タグ（著者/置き場所/仕入れ元）: クリックで絞り込み */
.card-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; padding-top: 8px; border-top: 1px dotted var(--line); }
.card-tag {
  font: inherit; font-size: 10.5px; line-height: 1.5; letter-spacing: .02em; cursor: pointer;
  padding: 1px 8px; border-radius: 0; border: 1px solid var(--line-strong);
  background: var(--surface2); color: var(--ink-soft);
}
.card-tag:hover { border-color: var(--ink); color: var(--ink); }
.card-tag.active { background: var(--ink); color: var(--ground); border-color: var(--ink); }
/* v4.7 B: 物理札の置き場所バッジ（例「書架 B-3」） */
.loc {
  font-size: 10px; font-weight: 700; letter-spacing: .04em;
  color: var(--chip-ink); background: var(--ink); padding: 2px 8px; white-space: nowrap;
}

/* 朱印クリックの状態メニュー */
.status-menu {
  position: fixed; z-index: 250; min-width: 140px;
  background: var(--surface); border: 1px solid var(--ink);
  outline: 1px solid var(--ink); outline-offset: 3px;
  box-shadow: var(--shadow); padding: 4px;
}
.status-menu-item {
  display: block; width: 100%; text-align: left;
  background: none; border: none; padding: 7px 10px;
  font-size: 13px; color: var(--ink); cursor: pointer; font-family: inherit;
}
.status-menu-item:hover { background: var(--surface2); }
.status-menu-item.current { color: var(--crimson); font-weight: 700; }
.status-menu-item.current::after { content: " ●"; font-size: 9px; }

/* 状態フィルタチップの入れ物（flexの中で並ぶように） */
.status-chips { display: contents; }
.status-manage-btn { font-weight: 700; }

/* 状態の管理モーダル */
.status-manage-list { list-style: none; margin-bottom: 14px; }
.status-manage-list li {
  display: flex; align-items: center; gap: 6px; padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.status-name-input {
  flex: 1; min-width: 0; background: var(--surface2); border: 1px solid var(--line-strong);
  border-radius: 2px; padding: 6px 9px; font-size: 13px; color: var(--ink);
}
.btn-mini { padding: 5px 9px; font-size: 12px; }
.status-add-row { display: flex; gap: 8px; }
.status-add-row input {
  flex: 1; background: var(--surface2); border: 1px solid var(--line-strong);
  border-radius: 2px; padding: 8px 10px; font-size: 13px; color: var(--ink);
}

/* サムネイル入力行（URL＋アップロード） */
.thumb-input-row { display: flex; gap: 8px; align-items: center; }
.thumb-input-row input[type="text"] { flex: 1; min-width: 0; }

/* 追加時: 印を捺すモーション（0.3秒） */
@keyframes ms-stamp-in {
  0% { transform: rotate(-12deg) scale(1.6); opacity: 0; }
  60% { transform: rotate(-12deg) scale(.94); opacity: 1; }
  100% { transform: rotate(-12deg) scale(1); opacity: .85; }
}
.card.just-added .status { animation: ms-stamp-in .3s ease-out both; }
@media (prefers-reduced-motion: reduce) {
  .card.just-added .status { animation: none; }
}

/* ⑥ メモ／アイデア: 罫線紙＋朱縁＋角折れの“書き付け”意匠（v4.7 C） */
.card.memo {
  position: relative;
  border-left: 4px solid var(--crimson);
  background:
    repeating-linear-gradient(0deg, transparent 0 25px, var(--paper-rule) 25px 26px),
    var(--surface);
}
.card.memo::after {
  content: ""; position: absolute; top: 0; right: 0; z-index: 2;
  border-width: 0 16px 16px 0; border-style: solid;
  border-color: var(--surface2) var(--surface2) transparent transparent;
  box-shadow: -1px 1px 0 var(--line-strong);
}
.card.memo .memo-head {
  display: flex; justify-content: space-between; align-items: center; margin: 12px 14px 0;
  border-bottom: 1.5px solid var(--ink); padding-bottom: 6px; position: relative; /* 二重罫 */
}
.card.memo .memo-head::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -4px;
  border-bottom: .5px solid var(--ink);
}
.card.memo .memo-label { font-size: 10.5px; font-weight: 700; letter-spacing: .2em; color: var(--crimson); }
.card.memo .memo-text {
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
  font-size: 14px; line-height: 1.9; padding: 10px 14px 0; flex: 1;
  display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden;
}
.card.memo .card-foot { padding: 10px 14px 14px; }

/* ---------------------------------------------------------------------- */
/* Modals（大きな蔵書票として）                                            */
/* ---------------------------------------------------------------------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(34, 48, 59, .5); display: none;
  align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 100;
}
.modal-overlay.open { display: flex; }
/* 氏名ダイアログは購入モーダルの上に重ねて出す（同一z-indexだと後ろに隠れて「無反応」に見えるため） */
#name-overlay { z-index: 110; }
.modal {
  width: 100%; max-width: 520px; background: var(--surface);
  border: 1px solid var(--ink); outline: 1px solid var(--ink); outline-offset: 3px;
  border-radius: 0; box-shadow: var(--shadow); padding: 22px 22px 24px;
}
.modal h2 {
  font-size: 17px; margin-bottom: 16px; font-weight: 600;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
  border-bottom: 1.5px solid var(--ink); padding-bottom: 7px; position: relative;
}
.modal h2::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -4px;
  border-bottom: .5px solid var(--ink);
}
.modal-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.modal-field label { font-size: 12px; color: var(--ink-soft); letter-spacing: .06em; }
.modal-field input, .modal-field select, .modal-field textarea {
  background: var(--surface2); border: 1px solid var(--line-strong); border-radius: 2px;
  padding: 9px 11px; font-size: 13.5px; color: var(--ink);
}
.modal-field textarea { resize: vertical; min-height: 64px; }
.modal-field input:focus-visible, .modal-field select:focus-visible, .modal-field textarea:focus-visible {
  outline: 2px solid var(--brass); outline-offset: 1px;
}
.modal-row { display: flex; gap: 10px; }
.modal-row .modal-field { flex: 1; }
.keymemo-toggle {
  background: none; border: 1px dashed var(--line-strong); border-radius: 0; padding: 8px 10px;
  font-size: 12.5px; color: var(--ink-soft); cursor: pointer; text-align: left;
}
.modal-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.modal-actions .left, .modal-actions .right { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  border: none; border-radius: 0; padding: 9px 16px; font-size: 13.5px; font-weight: 700; cursor: pointer;
  letter-spacing: .04em;
}
.btn-primary { background: var(--brass); color: var(--chip-ink); }
.btn-secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--ink); }
.btn-danger { background: var(--crimson); color: var(--chip-ink); }
.btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.btn:disabled { opacity: .6; cursor: default; }
.modal-error {
  font-size: 12.5px; color: var(--crimson); background: var(--surface2);
  border-left: 2px solid var(--crimson); border-radius: 0; padding: 8px 10px; margin-bottom: 12px; display: none;
}
.modal-error.show { display: block; }
/* アカウント設定: 成功メッセージ・区切り・小見出し */
.modal-ok {
  font-size: 12.5px; color: var(--play); background: var(--surface2);
  border-left: 2px solid var(--play); padding: 8px 10px; margin-bottom: 12px;
}
.modal-sep { border: none; border-top: 1px solid var(--line); margin: 20px 0 14px; }
.modal-subhead { font-size: 13px; font-weight: 700; letter-spacing: .04em; margin-bottom: 10px; color: var(--ink); }
/* 運用（店主）ダッシュボード */
.owner-list { max-height: 48vh; overflow-y: auto; margin-bottom: 14px; }
.owner-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.owner-info { font-size: 12.5px; color: var(--ink); flex: 1; min-width: 0; }
.owner-sub { font-size: 11px; color: var(--ink-soft); margin-top: 3px; word-break: break-all; }
.modal-close {
  float: right; background: none; border: none; color: var(--ink-soft); font-size: 18px; cursor: pointer;
  line-height: 1; padding: 2px 6px 6px;
  /* .modal h2 は position:relative（二重罫用）のため、staticなfloatの×より上に
     描画されクリックを奪う。×を positioned + z-index で最前面にする */
  position: relative; z-index: 2;
}
.modal-close:focus-visible { outline: 2px solid var(--brass); outline-offset: 1px; }

/* ---- まとめてインポート ---- */
.quickadd button.import-btn {
  background: var(--surface); color: var(--ink); border: 1px solid var(--ink); font-weight: 700;
}
.modal-wide { max-width: 640px; }
.import-help { font-size: 12.5px; color: var(--ink-soft); margin-bottom: 12px; }
.import-paste {
  min-height: 72px; border: 1px dashed var(--brass); border-radius: 0;
  background: var(--surface2); padding: 10px 12px; font-size: 13px; color: var(--ink);
  margin-bottom: 12px; overflow: hidden;
}
.import-paste:focus-visible { outline: 2px solid var(--brass); outline-offset: 1px; }
.import-paste:empty::before { content: attr(data-placeholder); color: var(--ink-soft); }
.import-result { font-size: 13px; color: var(--brass-strong); font-weight: 700; margin-bottom: 10px; display: none; }
.import-result.show { display: block; }
.import-subhead {
  font-size: 12px; letter-spacing: .2em; color: var(--ink-soft); margin: 10px 0 6px; font-weight: 700;
}
.import-list {
  list-style: none; max-height: 220px; overflow-y: auto;
  border: 1px solid var(--line-strong); border-radius: 0; background: var(--surface);
}
.import-list li {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px;
  border-bottom: 1px solid var(--line);
}
.import-list li:last-child { border-bottom: none; }
.import-list input[type="checkbox"] { flex: none; }
.import-title-input {
  flex: 1; min-width: 0; background: var(--surface2); border: 1px solid var(--line-strong); border-radius: 2px;
  padding: 5px 8px; font-size: 12.5px; color: var(--ink);
}
.import-title-input:focus-visible { outline: 2px solid var(--brass); outline-offset: 1px; }
.import-row-meta {
  flex: none; max-width: 40%; font-size: 11px; color: var(--ink-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.import-row-thumb {
  flex: none; width: 43px; height: 32px; object-fit: cover; border-radius: 0;
  border: 1px solid var(--line-strong); background: var(--surface2);
  filter: sepia(.12);
}
.import-source-row { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.import-pair-badge {
  flex: none; font-size: 10px; font-weight: 700; letter-spacing: .08em;
  background: var(--ink); color: var(--ground); border-radius: 0; padding: 2px 8px; white-space: nowrap;
}
.import-dl-note { font-size: 11.5px; color: var(--ink-soft); margin-top: 10px; }

/* ---- Murphy's（所持札） ---- */
.b-murphys { background: var(--brass); color: var(--chip-ink); letter-spacing: .18em; }
.playbtn {
  background: var(--crimson); color: var(--chip-ink); border: none; border-radius: 0;
  padding: 5px 12px; font-size: 11.5px; font-weight: 700; cursor: pointer;
  letter-spacing: .08em; box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
}
.playbtn:hover { filter: brightness(1.1); }
.playbtn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.player-video {
  width: 100%; aspect-ratio: 16/9; background: #000; display: block;
  border: 1px solid var(--ink);
}
.part-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.mdl-status { font-size: 13.5px; color: var(--ink); margin: 6px 0 4px; letter-spacing: .04em; }
.murphys-test-btn { font-size: 12px; }

/* ウィッシュ札: 半透明＋破線の二重枠（未所持の印） */
.card.wish {
  opacity: .78;
  border-style: dashed;
  outline-style: dashed;
}
.card.wish:hover { opacity: .95; }
.wish-get-btn {
  display: block; width: 100%;
  background: var(--brass); color: var(--chip-ink); border: none; border-radius: 0;
  padding: 8px 10px; font-size: 12.5px; font-weight: 700; cursor: pointer;
  letter-spacing: .08em; margin-top: 2px;
}
.wish-get-btn:hover { filter: brightness(1.1); }
.wish-get-btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* カタログセクション（検索時のみ・棚=ストア） */
.catalog-heading {
  margin: 8px 26px 0;
  font-size: 12px; letter-spacing: .2em; color: var(--brass); font-weight: 700;
  border-top: 1px solid var(--line); padding-top: 14px;
}
.catalog-more-row { display: flex; justify-content: center; padding: 8px 26px 20px; }

/* 検索ステータス（検索中… / 見つかりませんでした） */
.catalog-status { margin: 6px 26px 2px; font-size: 12.5px; color: var(--ink-soft); letter-spacing: .04em; }

/* スケルトン（書斎デザイン=直角・淡色） */
.catalog-skeleton { opacity: .7; pointer-events: none; }
.catalog-skeleton .thumb { background: var(--surface2); }
.catalog-skeleton .skeleton-line {
  height: 12px; margin: 9px 12px; background: var(--surface2); border-radius: 0;
}
.catalog-skeleton .skeleton-line.short { width: 55%; }
.catalog-skeleton .skeleton-box,
.catalog-skeleton .skeleton-line { position: relative; overflow: hidden; }
.catalog-skeleton .skeleton-box::after,
.catalog-skeleton .skeleton-line::after {
  content: ''; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(142, 59, 44, .10), transparent);
  animation: ms-shimmer 1.2s ease-in-out infinite;
}
@keyframes ms-shimmer { 100% { transform: translateX(100%); } }

/* How to リンク */
#howto-link {
  display: block; width: 100%; box-sizing: border-box; text-align: left;
  padding: 8px 10px; font-size: 13px; color: var(--ink); text-decoration: none;
  border-bottom: 1px solid var(--line);
}
#howto-link:hover { background: var(--surface2); }
.landing-howto { margin-top: 10px; }
.landing-howto a { font-size: 13px; color: var(--brass); text-decoration: none; }
.landing-howto a:hover { text-decoration: underline; }
.catalog-tile:hover { opacity: 1; }

/* カタログタイルの「＋ ウィッシュ」ボタン */
.catalog-wish-btn {
  border: 1px solid var(--brass); background: transparent; color: var(--brass);
  border-radius: 0; padding: 3px 8px; font-size: 11px; font-weight: 700; cursor: pointer;
  letter-spacing: .04em; white-space: nowrap;
}
.catalog-wish-btn:hover { background: var(--brass); color: var(--chip-ink); }
.catalog-wish-btn:disabled { border-color: var(--line-strong); color: var(--ink-soft); background: transparent; cursor: default; }
.catalog-wish-btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* カタログタイルの「買う」ボタン（弁柄ベタ＝主アクション） */
.catalog-buy-btn {
  border: 1px solid var(--brass); background: var(--brass); color: var(--chip-ink);
  border-radius: 0; padding: 3px 10px; font-size: 11px; font-weight: 700; cursor: pointer;
  letter-spacing: .04em; white-space: nowrap;
}
.catalog-buy-btn:hover { filter: brightness(1.1); }
.catalog-buy-btn:disabled { border-color: var(--line-strong); background: var(--surface2); color: var(--ink-soft); cursor: not-allowed; filter: none; }
.catalog-buy-btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* 購入モーダル: 保存カードの選択肢 */
#purchase-saved-list { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 10px; }
.saved-card-row { display: flex; gap: 8px; align-items: stretch; }
.saved-card-pick {
  flex: 1; border: 1px solid var(--brass); background: transparent; color: var(--ink);
  border-radius: 0; padding: 10px 12px; font-size: 13px; font-weight: 700; cursor: pointer; text-align: left;
}
.saved-card-pick:hover { background: var(--brass); color: var(--chip-ink); }
.saved-card-pick:disabled { border-color: var(--line-strong); color: var(--ink-soft); cursor: default; }
.saved-card-del {
  border: 1px solid var(--line-strong); background: transparent; color: var(--ink-soft);
  border-radius: 0; padding: 0 10px; font-size: 12px; cursor: pointer;
}
.saved-card-del:hover { color: var(--brass); border-color: var(--brass); }
.saved-card-other {
  border: none; background: transparent; color: var(--ink-soft); text-decoration: underline;
  font-size: 12.5px; cursor: pointer; padding: 4px 0; align-self: flex-start;
}
.saved-card-other:hover { color: var(--ink); }
.purchase-save-check {
  display: flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 12.5px; color: var(--ink-soft);
}

/* 統計「ウィッシュ N」をクリック可能に（他statと同じ見た目・buttonのUAスタイルをリセット） */
.stat-wish { font: inherit; cursor: pointer; text-align: left; background: var(--surface); border: none; border-right: 1px solid var(--line); color: inherit; }
.stat-wish:hover b { color: var(--brass); }
.stat-wish:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }
.catalog-desc {
  font-size: 11.5px; color: var(--ink-soft); line-height: 1.7;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

/* 販売価格（¥3桁区切り / 無料 / 価格未設定） */
.card-price {
  font-size: 13px; font-weight: 700; color: var(--brass);
  letter-spacing: .04em; margin: 4px 0 2px;
}

.wish-get-btn:disabled {
  background: var(--surface2); color: var(--ink-soft); cursor: not-allowed; filter: none;
}

/* 購入モーダル */
.purchase-item { font-size: 14px; color: var(--ink); margin: 4px 0 2px; font-weight: 600; }
.purchase-price { font-size: 20px; font-weight: 800; color: var(--brass); letter-spacing: .04em; margin: 0 0 10px; }
.purchase-card-label { display: block; font-size: 12px; color: var(--ink-soft); letter-spacing: .1em; margin-bottom: 6px; }
#purchase-card-container {
  border: 1px solid var(--line-strong); background: var(--surface); padding: 4px 8px; min-height: 44px;
}
.purchase-note { font-size: 12px; color: var(--ink-soft); line-height: 1.6; margin: 8px 0 0; }
#purchase-buy:disabled { background: var(--surface2); color: var(--ink-soft); cursor: not-allowed; }

@media (max-width: 640px) {
  .app-bar { padding: 12px 14px; }
  .stats { flex-wrap: wrap; }
  .stat { padding: 10px 14px; min-width: 90px; }
  .toolbar { padding: 12px 14px 4px; }
  .quickadd { margin: 12px 14px 6px; padding: 10px 12px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px; padding: 16px 16px 22px; }
  .status { width: 42px; height: 42px; font-size: 8.5px; }
}
