/* 見た目はレンダラーの責務。LLMはスタイルを書かない(書き換えてもデザインが崩れない)
   デザインの方針は docs/ui-design.md を参照 */

/* ---- デザイントークン ---- */
:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f2f4f7;
  --surface-hover: #eef0f4;
  --text: #0f172a;
  --text-2: #475467;
  --muted: #667085;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-text: #4338ca;
  --accent-soft: #eef2ff;
  --accent-ring: rgba(79, 70, 229, .22);
  --on-accent: #ffffff;
  --success: #067647;
  --success-soft: #ecfdf3;
  --success-border: #abefc6;
  --warn: #b54708;
  --warn-soft: #fffaeb;
  --warn-border: #fedf89;
  --danger: #d92d20;
  --danger-soft: #fef3f2;
  --danger-border: #fecdca;
  --callout: #fffaeb;
  --callout-border: #f79009;
  --note: #ecfdf3;
  --note-border: #17b26a;
  --mark-rewrite: var(--accent);
  --mark-note: #17b26a;
  --code-bg: #f8f9fb;

  --shadow-xs: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-sm: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-md: 0 4px 12px -2px rgba(16, 24, 40, .08), 0 2px 4px -2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 20px 32px -8px rgba(16, 24, 40, .14), 0 6px 10px -4px rgba(16, 24, 40, .06);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --topbar-h: 56px;
  --reading-w: 720px;
  --shelf-board: #e7dfd3;
  --shelf-edge: #d6cab8;
  --shelf-back: #f3efe8;
  --shelf-shadow: rgba(80, 60, 30, .18);
  --paper-edge: #efe9df;
  --paper-edge-2: #ddd5c8;
  --spine-text: rgba(255, 255, 255, .94);
  --ribbon: #c0392b;
  --book-h: 210px;
  --stack-w: 168px;
  --font-book: "Noto Serif JP", "Hiragino Mincho ProN", "Yu Mincho", serif;

  --font-ui: "Inter", "Noto Sans JP", "Hiragino Sans", "Hiragino Kaku Gothic ProN", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
/* ダーク: 明示指定か、システム設定に従うときだけ */
:root[data-theme="dark"] {
  --bg: #0b0d12;
  --surface: #12151c;
  --surface-2: #181c25;
  --surface-hover: #1d2230;
  --text: #e8eaf0;
  --text-2: #b4bac6;
  --muted: #8a92a3;
  --border: #252a36;
  --border-strong: #323949;
  --accent: #818cf8;
  --accent-hover: #a5b4fc;
  --accent-text: #a5b4fc;
  --accent-soft: rgba(129, 140, 248, .14);
  --accent-ring: rgba(129, 140, 248, .3);
  --on-accent: #0b0d12;
  --success: #47cd89;
  --success-soft: rgba(71, 205, 137, .12);
  --success-border: rgba(71, 205, 137, .35);
  --warn: #fdb022;
  --warn-soft: rgba(253, 176, 34, .1);
  --warn-border: rgba(253, 176, 34, .35);
  --danger: #f97066;
  --danger-soft: rgba(249, 112, 102, .1);
  --danger-border: rgba(249, 112, 102, .35);
  --callout: rgba(253, 176, 34, .08);
  --callout-border: #fdb022;
  --note: rgba(71, 205, 137, .08);
  --note-border: #47cd89;
  --mark-note: #47cd89;
  --code-bg: #0f1218;
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .5);
  --shadow-md: 0 6px 16px -4px rgba(0, 0, 0, .55);
  --shadow-lg: 0 24px 40px -8px rgba(0, 0, 0, .65);
  --shelf-board: #2a2620;
  --shelf-edge: #1f1c17;
  --shelf-back: #15171d;
  --shelf-shadow: rgba(0, 0, 0, .55);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #0b0d12;
    --surface: #12151c;
    --surface-2: #181c25;
    --surface-hover: #1d2230;
    --text: #e8eaf0;
    --text-2: #b4bac6;
    --muted: #8a92a3;
    --border: #252a36;
    --border-strong: #323949;
    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-text: #a5b4fc;
    --accent-soft: rgba(129, 140, 248, .14);
    --accent-ring: rgba(129, 140, 248, .3);
    --on-accent: #0b0d12;
    --success: #47cd89;
    --success-soft: rgba(71, 205, 137, .12);
    --success-border: rgba(71, 205, 137, .35);
    --warn: #fdb022;
    --warn-soft: rgba(253, 176, 34, .1);
    --warn-border: rgba(253, 176, 34, .35);
    --danger: #f97066;
    --danger-soft: rgba(249, 112, 102, .1);
    --danger-border: rgba(249, 112, 102, .35);
    --callout: rgba(253, 176, 34, .08);
    --callout-border: #fdb022;
    --note: rgba(71, 205, 137, .08);
    --note-border: #47cd89;
    --mark-note: #47cd89;
    --code-bg: #0f1218;
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, .5);
    --shadow-md: 0 6px 16px -4px rgba(0, 0, 0, .55);
    --shadow-lg: 0 24px 40px -8px rgba(0, 0, 0, .65);
    --shelf-board: #2a2620;
    --shelf-edge: #1f1c17;
    --shelf-back: #15171d;
    --shelf-shadow: rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}

/* ---- ベース ---- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { letter-spacing: -.01em; }
.muted { color: var(--muted); }
.icon {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
kbd {
  font: 500 11px/1 var(--font-ui);
  padding: 3px 5px; border-radius: 4px;
  border: 1px solid var(--border); border-bottom-width: 2px;
  background: var(--surface); color: var(--muted);
}

/* ---- ボタン ---- */
button { font: inherit; color: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px;
  font-size: 14px; font-weight: 500; white-space: nowrap;
  border-radius: 8px; border: 1px solid transparent;
  cursor: pointer; text-decoration: none !important;
  transition: background-color .15s, border-color .15s, box-shadow .15s, color .15s;
}
.btn .icon { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow-xs); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); box-shadow: var(--shadow-xs); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; gap: 6px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; padding: 0;
  border: 0; border-radius: 8px; background: transparent; color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }

/* ---- 入力 ---- */
textarea, input[type="text"], input[type="password"], input[type="search"], select {
  font: inherit; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  transition: border-color .15s, box-shadow .15s;
}
textarea:focus, input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); }
textarea { width: 100%; padding: 10px 12px; resize: vertical; line-height: 1.6; }
.field { display: grid; gap: 6px; font-size: 13px; font-weight: 500; color: var(--text-2); }
.field input { height: 40px; padding: 0 12px; font-size: 14px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px;
  font-size: 12px; font-weight: 500;
  border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-2);
  white-space: nowrap;
}
.chip:empty { display: none; }
.chip-action { cursor: pointer; height: auto; min-height: 32px; padding: 6px 12px; white-space: normal; text-align: left; font-size: 13px; background: var(--surface); }
.chip-action:hover { border-color: var(--accent); color: var(--accent-text); background: var(--accent-soft); }
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; line-height: 20px;
  background: var(--accent-soft); color: var(--accent-text);
}
.badge .icon { width: 13px; height: 13px; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-neutral { background: var(--surface-2); color: var(--text-2); }

.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 14px; border-radius: var(--radius);
  font-size: 14px; border: 1px solid;
}
.alert .icon { margin-top: 2px; }
.alert-error { background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger); }
.alert-warn { background: var(--warn-soft); border-color: var(--warn-border); color: var(--warn); }
.alert:empty { display: none; }

/* ---- アプリの骨格 ---- */
.app { display: flex; min-height: 100vh; min-height: 100dvh; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; font-size: 15px; text-decoration: none !important; }
.brand-mark {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, #6366f1, #4338ca); color: #fff;
  box-shadow: 0 2px 6px rgba(79, 70, 229, .35);
}
.brand-mark .icon { width: 17px; height: 17px; }
.search { position: relative; display: block; }
.search .icon { position: absolute; left: 10px; top: 50%; translate: 0 -50%; width: 16px; height: 16px; color: var(--muted); }
.search input { width: 100%; height: 36px; padding: 0 10px 0 34px; font-size: 13px; background: var(--surface-2); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.token-btn { position: relative; }
.token-btn .dot { position: absolute; right: 5px; top: 5px; width: 7px; height: 7px; box-shadow: 0 0 0 2px var(--bg); }
.dot.ok { background: var(--success); }
.theme-switch { display: grid; grid-template-columns: repeat(3, 30px); gap: 2px; padding: 3px; background: var(--surface-2); border-radius: 9px; }
.theme-switch button { display: grid; place-items: center; height: 28px; border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; }
.theme-switch button .icon { width: 15px; height: 15px; }
.theme-switch button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-xs); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  height: var(--topbar-h); padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.crumbs { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 14px; color: var(--muted); }
.crumbs a { color: var(--muted); white-space: nowrap; }
.crumbs a:hover { color: var(--text); text-decoration: none; }
.crumb-doc { color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumb-doc::before { content: "/"; color: var(--border-strong); margin-right: 8px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.model-select {
  position: relative; display: inline-flex; align-items: center;
  height: 36px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface); box-shadow: var(--shadow-xs);
  color: var(--text-2);
}
.model-select:hover { background: var(--surface-2); }
.model-select .icon { position: absolute; left: 10px; width: 16px; height: 16px; pointer-events: none; }
.model-select .chevron { left: auto; right: 8px; width: 14px; height: 14px; }
.model-select select {
  appearance: none; -webkit-appearance: none;
  height: 100%; padding: 0 28px 0 34px;
  border: 0; background: transparent; box-shadow: none;
  font-size: 14px; font-weight: 500; color: var(--text); cursor: pointer;
}
.model-select select:focus { box-shadow: none; }
.model-select:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); }
.scrim { position: fixed; inset: 0; z-index: 40; background: rgba(10, 13, 20, .45); backdrop-filter: blur(2px); animation: fade .2s; }
.scrim-top { z-index: 60; }

.page { width: 100%; max-width: 960px; margin: 0 auto; padding: 48px 32px 120px; }

/* ---- ホーム ---- */
.hero { max-width: 680px; margin: 8px auto 28px; text-align: center; }
.eyebrow {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 999px;
  font-size: 12.5px; font-weight: 500;
  color: var(--accent-text); background: var(--accent-soft);
}
.eyebrow .icon { width: 14px; height: 14px; }
.hero h1 { font-size: clamp(28px, 4vw, 38px); line-height: 1.25; margin: 16px 0 12px; font-weight: 700; letter-spacing: -.02em; }
.lead { margin: 0; font-size: 16px; color: var(--text-2); line-height: 1.8; }
.composer {
  max-width: 720px; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
  transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: var(--accent); box-shadow: var(--shadow-md), 0 0 0 4px var(--accent-ring); }
.composer textarea { border: 0; box-shadow: none !important; background: transparent; padding: 16px 18px 6px; font-size: 16px; resize: none; min-height: 96px; }
.composer-foot { display: flex; align-items: center; gap: 10px; padding: 10px 12px 12px 18px; }
.composer-foot .btn { margin-left: auto; }
.composer-hint { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; color: var(--muted); }
.composer-hint kbd:last-of-type { margin-right: 4px; }
.suggestions { max-width: 720px; margin: 14px auto 0; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

.progress-card {
  max-width: 720px; margin: 20px auto 0; padding: 18px 20px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
.progress-head { display: flex; gap: 14px; align-items: center; }
.progress-title { font-weight: 600; }
.progress-sub { font-size: 13px; color: var(--muted); }
.progress-bar { height: 4px; margin: 16px 0; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.progress-bar span { display: block; width: 35%; height: 100%; border-radius: 4px; background: var(--accent); animation: indeterminate 1.4s ease-in-out infinite; }
#new-doc-error { max-width: 720px; margin: 20px auto 0; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .8s linear infinite; flex: none; }
.skeleton { display: grid; gap: 10px; }
.skeleton span { display: block; height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-hover) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.6s infinite; }
.skeleton .sk-title { height: 30px; width: 60%; margin-bottom: 14px; }


/* ---- リーダー ---- */
.page-reader { max-width: calc(var(--reading-w) + 128px); padding: 40px 64px 160px; }
.hint {
  display: flex; gap: 10px; align-items: flex-start;
  margin-bottom: 28px; padding: 12px 8px 12px 14px;
  border-radius: var(--radius); font-size: 13.5px; color: var(--text-2);
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
}
.hint > .icon { color: var(--accent-text); margin-top: 2px; }
.hint span { flex: 1; }
.hint b { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--surface); border: 1px solid var(--border-strong); font-size: 11px; }
.hint .icon-btn { width: 26px; height: 26px; margin-top: -3px; }
.doc-header { margin-bottom: 28px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.doc-header h1 { font-size: clamp(26px, 3.4vw, 34px); line-height: 1.35; margin: 0 0 12px; font-weight: 700; letter-spacing: -.02em; }
.doc-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: 13px; color: var(--muted); }
.doc-meta > span { display: inline-flex; align-items: center; gap: 6px; }
.doc-meta .icon { width: 14px; height: 14px; }

/* ---- 文書 ---- */
.doc { font-size: 16.5px; line-height: 1.95; color: var(--text); }
.doc p { margin: 0 0 .9em; }
.doc ul, .doc ol { padding-left: 1.4em; margin: 0 0 .9em; }
.doc li + li { margin-top: .3em; }
.doc li::marker { color: var(--muted); }
.doc strong { font-weight: 700; }
.block { position: relative; margin: 0 -14px; padding: 4px 14px; border-radius: 10px; transition: background-color .15s; }
.block:hover { background: color-mix(in srgb, var(--accent-soft) 55%, transparent); }
.block.is-asking { background: var(--accent-soft); }
.block-body > :first-child { margin-top: 0; }
.block-body > :last-child { margin-bottom: 0; }
.block + .block { margin-top: 12px; }
.block-heading { margin-top: 36px !important; }
.block-heading .block-body { font-size: 1.4rem; font-weight: 700; margin: 0; line-height: 1.5; letter-spacing: -.01em; }
.block-callout .block-body {
  background: var(--callout);
  border-left: 3px solid var(--callout-border);
  padding: 14px 18px;
  border-radius: 0 10px 10px 0;
}
.block-note .block-body {
  background: var(--note);
  border-left: 3px solid var(--note-border);
  padding: 12px 16px;
  border-radius: 0 10px 10px 0;
  font-size: .94em;
}
.block-code pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  padding: 14px 16px; border-radius: 10px; overflow-x: auto;
  font-size: 13.5px; line-height: 1.7; margin: 0;
}
.block-table .block-body { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
.block-table table { border-collapse: collapse; width: 100%; font-size: .92em; line-height: 1.6; }
.block-table th, .block-table td { border-bottom: 1px solid var(--border); padding: 10px 14px; text-align: left; vertical-align: top; }
.block-table tr:last-child td { border-bottom: 0; }
.block-table th { background: var(--surface-2); font-weight: 600; font-size: .92em; color: var(--text-2); }
.block-figure figure, figure.block-body { margin: 0; text-align: center; }
.block-figure svg { max-width: 100%; height: auto; color: var(--text); }
.block-figure figcaption { color: var(--muted); font-size: .88em; margin-top: 6px; }
code { font-family: var(--font-mono); background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; font-size: .86em; }
pre code { border: 0; padding: 0; background: none; font-size: inherit; }
mark { background: color-mix(in srgb, var(--callout-border) 30%, transparent); color: inherit; border-radius: 3px; padding: 0 2px; }

/* 問いの入口と、AIが書き換えた印 */
.block-ask {
  position: absolute; right: -44px; top: 4px;
  display: grid; place-items: center;
  width: 30px; height: 30px; padding: 0;
  border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--accent-text); box-shadow: var(--shadow-sm);
  cursor: pointer; opacity: 0; transition: opacity .15s, background-color .15s;
}
.block-ask .icon { width: 16px; height: 16px; }
.block-ask:hover { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.block:hover .block-ask, .block-ask:focus-visible { opacity: 1; }
.origin-mark {
  position: absolute; left: -44px; top: 6px;
  display: grid; place-items: center;
  width: 26px; height: 26px; padding: 0;
  border-radius: 7px; border: 0; cursor: pointer;
  background: var(--accent-soft); color: var(--accent-text);
}
.origin-mark .icon { width: 14px; height: 14px; }
.origin-mark:hover { background: var(--accent); color: var(--on-accent); }
.block-note .origin-mark { background: var(--success-soft); color: var(--success); }
.block-note .origin-mark:hover { background: var(--mark-note); color: #fff; }
.block[data-origin]:not(.block-note)::before {
  content: ""; position: absolute; left: 0; top: 6px; bottom: 6px;
  width: 3px; border-radius: 3px; background: var(--mark-rewrite); opacity: .7;
}

.select-ask {
  position: absolute; z-index: 50;
  height: 32px; padding: 0 12px; font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: pop .12s ease-out;
}

.ask-panel, .result-card {
  margin: 14px 0 18px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  font-size: 15px; line-height: 1.7;
  animation: pop .15s ease-out;
}
.ask-panel { display: grid; gap: 10px; padding: 14px; }
.ask-panel:focus-within { border-color: var(--accent); }
.ask-panel-head { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.ask-panel-head .icon { width: 16px; height: 16px; color: var(--accent-text); }
.ask-panel textarea { font-size: 15px; }
.ask-quote { margin: 0; padding: 8px 12px; border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: 0 8px 8px 0; color: var(--text-2); font-size: 13.5px; max-height: 120px; overflow: auto; }
.ask-actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.ask-provider { margin-right: auto; }
.ask-status { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--text-2); padding: 2px 2px 0; }
.ask-status.is-error { color: var(--danger); }
.ask-status.is-error .typing { display: none; }
.typing { display: inline-flex; gap: 4px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: bounce 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }

.result-card { padding: 0; overflow: hidden; }
.result-head { display: flex; gap: 8px; align-items: center; padding: 10px 10px 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.result-head .muted { font-size: 12.5px; }
.result-close { margin-left: auto; width: 28px; height: 28px; }
.result-body { padding: 14px 16px 4px; display: grid; gap: 10px; }
.result-q { display: flex; gap: 10px; align-items: flex-start; font-weight: 600; margin: 0; }
.result-q::before { content: "Q"; flex: none; display: grid; place-items: center; width: 22px; height: 22px; margin-top: 2px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); font-size: 11px; font-weight: 700; color: var(--muted); }
.result-a { display: flex; gap: 10px; align-items: flex-start; margin: 0; white-space: pre-wrap; }
.result-a::before { content: "A"; flex: none; display: grid; place-items: center; width: 22px; height: 22px; margin-top: 2px; border-radius: 6px; background: var(--accent); font-size: 11px; font-weight: 700; color: var(--on-accent); }
.result-reason { display: flex; gap: 8px; align-items: flex-start; margin: 2px 0 0; padding: 8px 12px; border-radius: 8px; background: var(--surface-2); font-size: 13px; color: var(--text-2); }
.result-reason .icon { width: 15px; height: 15px; margin-top: 3px; color: var(--accent-text); }
.result-actions { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 16px 14px; }
.result-card.applied-note .result-a::before { background: var(--mark-note); color: #fff; }

/* ---- 表示の切り替え(縦に積む / 横にめくる) ---- */
.seg { display: inline-flex; gap: 2px; padding: 3px; height: 36px; background: var(--surface-2); border-radius: 9px; }
.seg button { display: grid; place-items: center; width: 32px; border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; }
.seg button .icon { width: 16px; height: 16px; }
.seg button:hover { color: var(--text); }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-xs); }

/* ---- ページ表示(教科書の紙面) ---- */
.page-reader.is-paged { max-width: 1320px; padding: 20px 32px 16px; }
.page-reader.is-paged .doc-header { display: none; }
.book { display: grid; grid-template-columns: minmax(0, 720px); justify-content: center; font-size: 16px; line-height: 1.9; }
.book.is-spread { grid-template-columns: repeat(2, minmax(0, 620px)); }
.book .block-body { font-family: "Noto Serif JP", "Hiragino Mincho ProN", "Yu Mincho", serif; }
.book .block-heading .block-body { font-family: var(--font-ui); }
.sheet {
  display: flex; flex-direction: column;
  height: max(420px, calc(100svh - var(--topbar-h) - 96px));
  padding: 22px 0 12px;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px;
  box-shadow: var(--shadow-md);
}
/* 見開き: のどに向かって少し影を落とす */
.book.is-spread .sheet:nth-child(odd) {
  border-radius: 6px 0 0 6px; border-right-color: transparent;
  background: linear-gradient(to left, rgba(16, 24, 40, .07), transparent 32px), var(--surface);
}
.book.is-spread .sheet:nth-child(even) {
  border-radius: 0 6px 6px 0; border-left-color: var(--border);
  background: linear-gradient(to right, rgba(16, 24, 40, .07), transparent 32px), var(--surface);
}
.sheet-head { padding: 0 52px 10px; font-size: 11.5px; color: var(--muted); font-family: var(--font-ui); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 52px; }
.sheet-body > :first-child { margin-top: 0 !important; }
.sheet-no { padding-top: 10px; text-align: center; font: 500 12px/1 var(--font-ui); color: var(--muted); font-variant-numeric: tabular-nums; }
.sheet-title { margin: 8px 0 24px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.sheet-title h1 { font-size: clamp(24px, 3vw, 30px); line-height: 1.35; margin: 0 0 10px; font-weight: 700; letter-spacing: -.02em; font-family: var(--font-ui); }
.sheet-title + .block { margin-top: 0; }
.sheet.turn-next { animation: turn-next .22s ease-out; }
.sheet.turn-prev { animation: turn-prev .22s ease-out; }
.book-nav { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 12px; }
.book-nav .icon-btn:disabled { opacity: .35; cursor: default; background: none; }
#page-no { min-width: 72px; text-align: center; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---- 履歴(右からのドロワー) ---- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 70;
  width: min(400px, 100%);
  display: flex; flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  animation: slide-in .22s ease-out;
}
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 18px 16px 14px 22px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin: 0 0 2px; font-size: 17px; }
.drawer-head p { margin: 0; font-size: 13px; }
.timeline { list-style: none; margin: 0; padding: 16px 22px 40px; overflow-y: auto; flex: 1; }
.timeline li { position: relative; display: grid; gap: 4px; padding: 0 0 22px 26px; }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 8px; bottom: -6px; width: 2px; background: var(--border); }
.timeline li:last-child::before { display: none; }
.timeline li::after { content: ""; position: absolute; left: 0; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--border-strong); }
.timeline li.is-current::after { border-color: var(--accent); background: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); }
.rev-title { display: flex; gap: 8px; align-items: baseline; font-size: 14px; }
.rev-no { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.rev-time { font-size: 12.5px; color: var(--muted); }
.timeline .btn, .timeline .badge { justify-self: start; margin-top: 4px; }

/* ---- モーダル ---- */
.modal {
  width: min(440px, calc(100% - 32px)); padding: 0;
  border: 1px solid var(--border); border-radius: 16px;
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-lg);
}
.modal::backdrop { background: rgba(10, 13, 20, .5); backdrop-filter: blur(2px); }
.modal[open] { animation: pop .18s ease-out; }
.modal form { display: grid; gap: 14px; padding: 24px; }
.modal h2 { margin: 0; font-size: 18px; }
.modal p { margin: -6px 0 0; font-size: 14px; }
.modal .alert { margin: 0; }
.modal-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: var(--accent-soft); color: var(--accent-text); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* ---- トースト ---- */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 90; display: grid; gap: 8px; max-width: min(380px, calc(100% - 40px)); }
.toast {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: 12px;
  background: var(--text); color: var(--bg);
  font-size: 14px; box-shadow: var(--shadow-lg);
  animation: toast-in .2s ease-out;
}
.toast .icon { margin-top: 1px; width: 17px; height: 17px; }
.toast-success .icon { color: #47cd89; }
.toast-error .icon { color: #f97066; }

/* ---- 本棚(ホーム) ---- */
.topbar .brand { flex: none; }
.theme-cycle { display: none; }
.shelf-head { display: flex; align-items: center; gap: 8px; max-width: none; margin: 48px 0 14px; }
.shelf-count { margin-right: auto; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.shelf-head .search { width: 220px; }
.bookcase {
  padding: 22px 18px 0;
  background: var(--shelf-back);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: inset 0 2px 10px var(--shelf-shadow);
  user-select: none; -webkit-user-select: none;
}
.shelf {
  position: relative;
  display: flex; align-items: flex-end;
  min-height: calc(var(--book-h) + 14px); padding: 0 10px;
  border-radius: 6px 6px 0 0;
  transition: background-color .15s;
}
/* 棚板 */
.shelf::after {
  content: ""; position: absolute; left: -18px; right: -18px; bottom: -14px; height: 14px;
  background: linear-gradient(var(--shelf-board), var(--shelf-edge));
  box-shadow: 0 6px 10px -4px var(--shelf-shadow);
}
.shelf + .shelf { margin-top: 40px; }
.bookcase > .shelf:last-child { margin-bottom: 14px; }
.shelf.is-target { background: color-mix(in srgb, var(--accent-soft) 70%, transparent); }
.stand { display: flex; align-items: flex-end; gap: 2px; min-height: var(--book-h); }
.bookend {
  flex: none; width: 10px; height: 92px; margin-left: 4px;
  border-radius: 2px 2px 0 0;
  background: linear-gradient(90deg, var(--border-strong), var(--surface-hover));
  box-shadow: 1px 0 2px var(--shelf-shadow);
}

/* 本の背。色は本ごとの --c、厚みは --w(ページ数) */
.shelf-book {
  --w: 40px; --c: #3b4a6b;
  position: relative; flex: none;
  width: var(--w); height: var(--book-h);
  display: flex; flex-direction: column; align-items: center;
  padding: 16px 0 10px;
  border-radius: 3px 3px 2px 2px;
  background:
    linear-gradient(90deg, rgba(0,0,0,.22), rgba(255,255,255,.10) 18%, rgba(255,255,255,0) 40%, rgba(0,0,0,.10) 85%, rgba(0,0,0,.25)),
    var(--c);
  color: var(--spine-text); text-decoration: none !important;
  box-shadow: 0 1px 0 rgba(255,255,255,.15) inset, 2px 0 3px -1px var(--shelf-shadow);
  transition: transform .18s ease, box-shadow .18s ease, opacity .2s;
  cursor: grab; touch-action: manipulation;
  -webkit-touch-callout: none;
}
.shelf-book::before, .shelf-book::after {
  content: ""; position: absolute; left: 0; right: 0; height: 3px;
  background: rgba(255, 255, 255, .28);
}
.shelf-book::before { top: 8px; }
.shelf-book::after { bottom: 26px; }
.book-title {
  flex: 1; min-height: 0; overflow: hidden;
  writing-mode: vertical-rl; text-orientation: mixed;
  font-family: var(--font-book); font-weight: 700; font-size: 13.5px;
  letter-spacing: .08em; line-height: 1.15;
  white-space: nowrap; text-overflow: ellipsis;
  text-shadow: 0 1px 1px rgba(0,0,0,.25);
}
.shelf-book.is-thin .book-title { font-size: 11.5px; letter-spacing: .04em; }
.book-pages { margin-top: 8px; font: 600 10px/1 var(--font-ui); opacity: .8; white-space: nowrap; }
.shelf-book.is-thin .book-pages { font-size: 8.5px; }
.stand .shelf-book:hover, .stand .shelf-book:focus-visible { transform: translateY(-10px); box-shadow: 0 10px 18px -6px var(--shelf-shadow); z-index: 2; }
.shelf-book:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.shelf-book.is-dim { opacity: .18; }
.shelf-book.is-pulling { transform: translateY(-36px) scale(1.04) !important; opacity: 0; transition: transform .35s ease, opacity .35s ease .15s; }

/* 表紙を見せて置いた本(面陳) */
.shelf-book.is-face {
  align-items: stretch; padding: 22px 18px 14px 24px;
  border-radius: 2px 4px 4px 2px;
  background:
    linear-gradient(90deg, rgba(0,0,0,.28), rgba(0,0,0,.05) 5%, rgba(255,255,255,.08) 7%, rgba(255,255,255,0) 30%, rgba(0,0,0,.12)),
    var(--c);
  box-shadow: 3px 0 0 -1px var(--paper-edge), 5px 1px 0 -2px var(--paper-edge-2), 6px 4px 12px -4px var(--shelf-shadow);
}
.shelf-book.is-face::before { top: 0; bottom: 0; left: 9px; right: auto; width: 2px; height: auto; background: rgba(0,0,0,.18); }
.shelf-book.is-face::after { top: 12px; bottom: 12px; left: 16px; right: 10px; height: auto; background: none; border: 1px solid rgba(255,255,255,.28); }
.cover-title {
  font-family: var(--font-book); font-weight: 700; font-size: 16px; line-height: 1.45; letter-spacing: .04em;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; overflow: hidden;
  text-shadow: 0 1px 1px rgba(0,0,0,.25);
}
.cover-rule { width: 28px; height: 2px; margin: 12px 0 0; background: rgba(255,255,255,.55); }
.cover-mark { flex: 1; min-height: 0; display: grid; place-items: center; opacity: .35; }
.cover-mark svg { width: 56px; height: 56px; fill: none; stroke: currentColor; stroke-width: 1.2; }
.shelf-book.is-face .book-pages { align-self: flex-start; margin: 0; }

/* しおり(最後に開いた本) */
.ribbon {
  position: absolute; top: -10px; right: 22%; width: 6px; height: 22px;
  background: var(--ribbon); clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 80%, 0 100%);
}
.shelf-book.is-face .ribbon { right: 18px; }

/* 寝かせた本(棚の右端に積む) */
.stack {
  position: absolute; right: 10px; bottom: 0;
  display: flex; flex-direction: column-reverse; align-items: flex-end;
  width: var(--stack-w);
}
.stack .shelf-book { width: var(--stack-w); height: max(var(--w), 18px); padding: 0 10px; flex-direction: row; }
.stack .shelf-book + .shelf-book { margin-bottom: 1px; }
.stack .shelf-book:nth-child(even) { translate: -6px 0; }
.stack .shelf-book .book-title { writing-mode: horizontal-tb; font-size: 12px; letter-spacing: .02em; }
.stack .shelf-book .book-pages { margin: 0 0 0 8px; }
.stack .shelf-book::before { top: 0; bottom: 0; left: 8px; right: auto; width: 3px; height: auto; }
.stack .shelf-book::after { top: 0; bottom: 0; right: 34px; left: auto; width: 3px; height: auto; }
.stack .shelf-book:hover, .stack .shelf-book:focus-visible { transform: translateX(-8px); }
.stack .ribbon { top: auto; bottom: -10px; right: 46px; }
.stack.is-target { min-height: 36px; border-radius: 4px; outline: 1.5px dashed var(--accent); outline-offset: 4px; background: var(--accent-soft); }

/* 生成中の本 */
.shelf-book.is-making {
  background: linear-gradient(180deg, var(--surface-2) 25%, var(--surface-hover) 50%, var(--surface-2) 75%);
  background-size: 100% 200%; animation: shimmer-v 1.6s infinite;
  border: 1px dashed var(--border-strong);
  color: var(--muted); justify-content: center; box-shadow: none; cursor: default;
}
.shelf-book.is-making::before, .shelf-book.is-making::after { display: none; }
.shelf-book.is-making .spinner { width: 16px; height: 16px; border-width: 2px; }

/* ドラッグ */
.shelf-book.is-placeholder { background: var(--accent-soft) !important; box-shadow: none; outline: 1.5px dashed var(--accent); outline-offset: -1.5px; }
.shelf-book.is-placeholder > *, .shelf-book.is-placeholder::before, .shelf-book.is-placeholder::after { visibility: hidden; }
.drag-ghost {
  position: fixed; z-index: 100; margin: 0; pointer-events: none;
  rotate: 4deg; scale: 1.04;
  box-shadow: 0 24px 40px -8px rgba(0,0,0,.45) !important;
  transition: none !important; translate: none !important;
}
.drag-ghost.over-trash { opacity: .45; rotate: -8deg; scale: .9; }
body.is-dragging, body.is-dragging * { cursor: grabbing !important; }
.trash {
  position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom, 0px)); z-index: 90; translate: -50% 140px;
  display: grid; place-items: center; width: 64px; height: 64px; border-radius: 50%;
  background: var(--surface); color: var(--danger); border: 1px solid var(--danger-border);
  box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none;
  transition: translate .2s ease, scale .15s, background-color .15s, opacity .2s;
}
.trash .icon { width: 24px; height: 24px; }
body.is-dragging .trash { translate: -50% 0; opacity: 1; }
.trash.is-hot { scale: 1.15; background: var(--danger); color: #fff; }

/* 札(ホバー)とメニュー */
.book-tip {
  position: fixed; z-index: 80; width: max-content; max-width: 260px;
  padding: 10px 12px; border-radius: var(--radius);
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  box-shadow: var(--shadow-lg); pointer-events: none;
}
.book-tip b { display: block; font-weight: 600; font-size: 14px; line-height: 1.45; }
.book-tip span { display: flex; gap: 6px; align-items: center; margin-top: 6px; font-size: 12px; color: var(--muted); }
.book-tip .icon { width: 13px; height: 13px; }
.book-tip span > svg:not(:first-child) { margin-left: 6px; }
.menu {
  position: fixed; z-index: 95; min-width: 190px; padding: 5px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); animation: fade .12s;
}
.menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 7px 10px; border: 0; border-radius: 6px; background: none;
  font-size: 13.5px; color: var(--text); text-align: left; cursor: pointer;
}
.menu button .icon { width: 16px; height: 16px; color: var(--muted); }
.menu button:hover, .menu button:focus-visible { background: var(--surface-hover); outline: none; }
.menu button[aria-checked="true"] { color: var(--accent-text); font-weight: 500; }
.menu button[aria-checked="true"] .icon { color: var(--accent-text); }
.menu button:disabled { opacity: .4; cursor: default; background: none; }
.menu .danger, .menu .danger .icon { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 5px 2px; }
.menu kbd { margin-left: auto; }
.toast { align-items: center; }
.toast span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast-action { height: 26px; margin-left: 4px; }

@media (max-width: 560px) {
  :root { --book-h: 176px; --stack-w: 128px; }
  .shelf-head { margin-top: 28px; }
  .shelf-head .search { width: auto; flex: 1; }
  .shelf-count { display: none; }
  .bookcase { padding: 18px 10px 0; margin: 0 -4px; }
  .shelf { padding: 0 4px; }
  .shelf::after { left: -10px; right: -10px; }
  .stack { right: 4px; }
  .book-title { font-size: 12px; }
  .shelf-book.is-face { padding: 16px 12px 16px 22px; }
  .cover-title { font-size: 13.5px; }
  .cover-mark svg { width: 40px; height: 40px; }
  .bookend { display: none; }
}

/* ---- アニメーション ---- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes indeterminate { 0% { transform: translateX(-100%); } 100% { transform: translateX(300%); } }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .4; } 40% { transform: translateY(-4px); opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(.98); } }
@keyframes fade { from { opacity: 0; } }
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }
@keyframes turn-next { from { opacity: 0; transform: translateX(18px); } }
@keyframes turn-prev { from { opacity: 0; transform: translateX(-18px); } }
@keyframes shimmer-v { from { background-position: 0 200%; } to { background-position: 0 -200%; } }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ---- レスポンシブ ---- */
@media (max-width: 1100px) {
  .page-reader { padding-left: 32px; padding-right: 56px; }
  .origin-mark { left: -30px; }
}
@media (max-width: 900px) {
  .topbar { padding: 0 12px; gap: 6px; }
  .page { padding: 28px 16px 120px; }
  .page-reader { padding: 24px 16px 160px; }
  .block { margin: 0 -10px; padding: 4px 44px 4px 10px; }
  .block-ask { right: 6px; opacity: .55; }
  .origin-mark { left: auto; right: 6px; top: 40px; }
  .block[data-origin]:not(.block-note)::before { left: 0; }
  .page-reader.is-paged { padding: 12px 10px; }
  .sheet { padding-top: 16px; }
  .sheet-head { padding: 0 14px 8px; }
  .sheet-body { padding: 4px 14px; }
}
@media (max-width: 560px) {
  .hide-sm { display: none !important; }
  .brand-name, .theme-switch { display: none; }
  .theme-cycle { display: inline-grid; }
  .composer-hint { display: none; }
  .composer-foot { padding-left: 12px; }
  .doc { font-size: 16px; }
  .toasts { right: 12px; left: 12px; bottom: 12px; max-width: none; }
  #history-btn { width: 36px; padding: 0; }
}

/* ---- 文章を減らしたレイアウト ---- */
.composer { margin-top: 8px; }
.composer-foot { justify-content: flex-end; }
.progress-head { margin-bottom: 16px; }
.ask-actions .ask-status { margin-right: auto; }
.ask-actions .btn-primary { width: 36px; padding: 0; }
.drawer-head { align-items: center; }
.modal-icon + h2 { margin-top: -4px; }
