@charset "UTF-8";

/* ==================================================================
   Markdown Viewer — スタイルシート
   外部フォント・外部アセットは一切読み込まない（完全ローカル動作）
   ================================================================== */

/* ---------- デザイントークン ---------- */

:root {
  color-scheme: light dark;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
    "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", Meiryo, system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Roboto Mono", "Noto Sans Mono", "Courier New", monospace;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow-1: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 1px rgba(15, 23, 42, .04);
  --shadow-2: 0 10px 30px rgba(15, 23, 42, .12);
  --header-h: 52px;
  --dur: .18s;

  /* 明るいテーマ */
  --bg: #f4f5f7;
  --bg-elevated: #ffffff;
  --bg-sunken: #fafbfc;
  --bg-hover: rgba(15, 23, 42, .05);
  --bg-active: rgba(15, 23, 42, .09);
  --border: #e2e5ea;
  --border-strong: #cfd4dc;
  --text: #1f2430;
  --text-muted: #6b7280;
  --text-faint: #9aa1ac;
  --accent: #4f46e5;
  --accent-soft: rgba(79, 70, 229, .1);
  --accent-text: #ffffff;
  --code-bg: #f6f7f9;
  --code-border: #e6e8ec;
  --quote-bar: #d8dbe2;
  --mark-bg: #fff3b8;
  --mark-text: #4a3b00;
  --table-stripe: #fafbfc;

  /* シンタックスハイライト */
  --tok-com: #8a94a6;
  --tok-str: #0a7c56;
  --tok-num: #b4530a;
  --tok-kw: #8b2fa8;
  --tok-lit: #0b63b6;
  --tok-fn: #1a56c4;
  --tok-type: #0f7490;
  --tok-op: #5b6472;
  --tok-pun: #8a94a6;
  --tok-var: #b02a5b;
  --tok-attr: #8b5a00;
  --tok-tag: #1a56c4;
  --tok-sel: #8b2fa8;
  --tok-prop: #0b63b6;
  --tok-meta: #a1430a;
  --tok-ins: #0a7c56;
  --tok-del: #c0392b;

  /* GitLab のアラート（> [!note] など） */
  --alert-note: #2563eb;
  --alert-tip: #15803d;
  --alert-important: #7c3aed;
  --alert-warning: #b45309;
  --alert-caution: #b91c1c;

  /* 検索ハイライト / Vim */
  --hl-bg: rgba(250, 204, 21, .38);
  --hl-current-bg: rgba(249, 115, 22, .55);
  --vim-cursor: rgba(79, 70, 229, .45);
  --vim-insert: #0a7c56;
  --vim-visual: #b4530a;
}

/* システム設定がダークのとき（data-theme="light" で明示指定されていない場合） */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171c;
    --bg-elevated: #1c1f26;
    --bg-sunken: #191c22;
    --bg-hover: rgba(255, 255, 255, .06);
    --bg-active: rgba(255, 255, 255, .11);
    --border: #2b303a;
    --border-strong: #3a4150;
    --text: #e4e7ec;
    --text-muted: #9aa3b2;
    --text-faint: #6b7280;
    --accent: #8b87ff;
    --accent-soft: rgba(139, 135, 255, .14);
    --accent-text: #15171c;
    --code-bg: #15181e;
    --code-border: #2b303a;
    --quote-bar: #3a4150;
    --mark-bg: #5c4a00;
    --mark-text: #ffeaa0;
    --table-stripe: #1a1d24;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-2: 0 10px 30px rgba(0, 0, 0, .45);

    --tok-com: #6e7787;
    --tok-str: #8ddba4;
    --tok-num: #f0a66a;
    --tok-kw: #d79bf5;
    --tok-lit: #7fc5f5;
    --tok-fn: #8ab4ff;
    --tok-type: #6fd6d2;
    --tok-op: #a4adbb;
    --tok-pun: #78818f;
    --tok-var: #f29ab8;
    --tok-attr: #e8c07d;
    --tok-tag: #8ab4ff;
    --tok-sel: #d79bf5;
    --tok-prop: #7fc5f5;
    --tok-meta: #f0a66a;
    --tok-ins: #8ddba4;
    --tok-del: #f09a92;

    --alert-note: #6ea8ff;
    --alert-tip: #5fd08a;
    --alert-important: #b69cff;
    --alert-warning: #f0b35a;
    --alert-caution: #ff8a80;

    --hl-bg: rgba(250, 204, 21, .24);
    --hl-current-bg: rgba(249, 115, 22, .5);
    --vim-cursor: rgba(139, 135, 255, .55);
    --vim-insert: #8ddba4;
    --vim-visual: #f0a66a;
  }
}

/* テーマ手動切り替え（システム設定より優先） */
:root[data-theme="dark"] {
  --bg: #15171c;
  --bg-elevated: #1c1f26;
  --bg-sunken: #191c22;
  --bg-hover: rgba(255, 255, 255, .06);
  --bg-active: rgba(255, 255, 255, .11);
  --border: #2b303a;
  --border-strong: #3a4150;
  --text: #e4e7ec;
  --text-muted: #9aa3b2;
  --text-faint: #6b7280;
  --accent: #8b87ff;
  --accent-soft: rgba(139, 135, 255, .14);
  --accent-text: #15171c;
  --code-bg: #15181e;
  --code-border: #2b303a;
  --quote-bar: #3a4150;
  --mark-bg: #5c4a00;
  --mark-text: #ffeaa0;
  --table-stripe: #1a1d24;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-2: 0 10px 30px rgba(0, 0, 0, .45);

  --tok-com: #6e7787;
  --tok-str: #8ddba4;
  --tok-num: #f0a66a;
  --tok-kw: #d79bf5;
  --tok-lit: #7fc5f5;
  --tok-fn: #8ab4ff;
  --tok-type: #6fd6d2;
  --tok-op: #a4adbb;
  --tok-pun: #78818f;
  --tok-var: #f29ab8;
  --tok-attr: #e8c07d;
  --tok-tag: #8ab4ff;
  --tok-sel: #d79bf5;
  --tok-prop: #7fc5f5;
  --tok-meta: #f0a66a;
  --tok-ins: #8ddba4;
  --tok-del: #f09a92;

  --alert-note: #6ea8ff;
  --alert-tip: #5fd08a;
  --alert-important: #b69cff;
  --alert-warning: #f0b35a;
  --alert-caution: #ff8a80;

  --hl-bg: rgba(250, 204, 21, .24);
  --hl-current-bg: rgba(249, 115, 22, .5);
  --vim-cursor: rgba(139, 135, 255, .55);
  --vim-insert: #8ddba4;
  --vim-visual: #f0a66a;
}

/* ---------- リセット ---------- */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { font: inherit; color: inherit; }

:where(a):focus-visible,
:where(button):focus-visible,
:where(textarea):focus-visible,
:where(input):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ---------- アプリ全体 ---------- */

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ---------- ヘッダー ---------- */

.header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--header-h);
  padding: 0 14px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 650;
  letter-spacing: .01em;
  white-space: nowrap;
}

.brand__mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--accent);
  color: var(--accent-text);
  flex: 0 0 auto;
}

.brand__mark svg { width: 16px; height: 16px; }
.brand__name { font-size: 15px; }
.brand__version {
  margin-left: -4px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.header__spacer { flex: 1 1 auto; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--dur), color var(--dur), border-color var(--dur);
}

.btn:hover { background: var(--bg-hover); color: var(--text); }
.btn:active { background: var(--bg-active); }
.btn svg { width: 15px; height: 15px; flex: 0 0 auto; }
.btn--icon { padding: 0; width: 32px; justify-content: center; }

.btn[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}

.btn--ghost { border-color: transparent; background: transparent; }
.btn--ghost:hover { background: var(--bg-hover); }

.toolbar__sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 2px;
}

/* ---------- ツールバーのメニュー（ファイル / 表示） ---------- */

.menu-anchor { position: relative; display: inline-flex; }

.btn__caret { width: 12px !important; height: 12px !important; margin-left: -2px; opacity: .7; }
.btn[aria-expanded="true"] { background: var(--bg-active); color: var(--text); }

.menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 40;
  display: grid;
  gap: 1px;
  width: max-content;
  min-width: 280px;
  max-width: min(360px, calc(100vw - 20px));
  max-height: calc(100vh - var(--header-h) - 20px);
  overflow-y: auto;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-2);
}

.menu--right { left: auto; right: 0; }
.menu[hidden] { display: none; }

.menu__item {
  display: grid;
  grid-template-columns: 20px 1fr auto;
  align-items: center;
  column-gap: 10px;
  padding: 7px 10px 7px 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.menu__item:hover, .menu__item:focus-visible { background: var(--bg-hover); outline: none; }
.menu__item.is-danger .menu__title, .menu__item.is-danger .menu__icon { color: var(--tok-del); }

.menu__icon, .menu__check { display: grid; place-items: center; color: var(--text-muted); }
.menu__icon svg { width: 16px; height: 16px; }
.menu__check svg { width: 15px; height: 15px; color: var(--accent); visibility: hidden; }
.menu__item[aria-checked="true"] .menu__check svg { visibility: visible; }

.menu__title { font-size: 13px; font-weight: 550; }
.menu__desc { grid-column: 2 / 4; font-size: 11.5px; line-height: 1.45; color: var(--text-muted); }
.menu__kbd { grid-column: 3; grid-row: 1; font-size: 10.5px; }

.menu__sep { height: 1px; margin: 4px 6px; background: var(--border); }

.menu__group {
  padding: 6px 10px 2px 38px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--text-faint);
}

/* ---------- ドラッグ＆ドロップ ---------- */

.dropzone {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(2px);
  pointer-events: none;   /* drop イベントは window で受ける */
}

.dropzone[hidden] { display: none; }

.dropzone__box {
  display: grid;
  justify-items: center;
  gap: 6px;
  width: min(440px, 100%);
  padding: 36px 24px;
  border: 2px dashed var(--accent);
  border-radius: 16px;
  background: var(--bg-elevated);
  color: var(--text);
  text-align: center;
  box-shadow: var(--shadow-2);
}

.dropzone__box svg { width: 36px; height: 36px; color: var(--accent); }
.dropzone__box p { margin: 4px 0 0; font-size: 16px; font-weight: 650; }
.dropzone__box small { color: var(--text-muted); font-size: 12px; }

/* ---------- タブ（狭い画面用） ---------- */

.tabs {
  display: none;
  flex: 0 0 auto;      /* 縮めると文字が縦に折り返すので、溢れた分はツールバー側を横スクロールさせる */
  gap: 4px;
  padding: 3px;
  background: var(--bg-hover);
  border-radius: 8px;
}

.tab {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  padding: 5px 14px;
  border-radius: 6px;
  white-space: nowrap;
  cursor: pointer;
}

.tab[aria-selected="true"] {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-1);
}

/* ---------- 分割ペイン ---------- */

.workspace {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg-elevated);
}

.pane--editor {
  flex: 0 0 50%;
  position: relative;     /* 行移動ボックスの基準 */
  /* エディタの文字組み。行番号・計測用ミラーと共有する */
  /* 文字サイズ・行の高さは整数 px にする。小数だと行が 0.5px 単位でずれて描かれ、文字がにじんで見える */
  --ed-fs: 14px;
  --ed-lh: 24px;
  --ed-line: 24px;
  --ed-pad-top: 18px;
  --gutter-w: 46px;       /* 桁数に応じて JS が更新する */
}
.pane--preview { flex: 1 1 auto; background: var(--bg-sunken); }

.pane__head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 14px;
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
  background: inherit;
}

.pane__head-actions { margin-left: auto; display: flex; gap: 4px; }

/* 入力欄の見出しの表ボタン（table.js）。カーソルが表の中にある間だけ行・列の操作を出す */
.tabletools { align-items: center; gap: 1px; min-width: 0; margin-right: -8px; }
.tabletools [hidden] { display: none !important; }
.tabletools__label { margin-right: 4px; letter-spacing: 0; text-transform: none; color: var(--text-muted); }
.tabletools__btn {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.tabletools__btn svg { width: 16px; height: 16px; }
.tabletools__btn:hover { background: var(--bg-hover); color: var(--text); }
.tabletools__btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tabletools__btn[aria-pressed="true"] { background: var(--bg-active); color: var(--accent); }
.tabletools__insert { color: var(--text-faint); }
.tabletools__sep { flex: 0 0 auto; width: 1px; height: 16px; margin: 0 4px; background: var(--border); }

.pane__doc-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  color: var(--text-muted);
}

.pane__doc-name::before { content: "— "; color: var(--text-faint); }
.pane__doc-name[hidden] { display: none; }

.pane__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

/* スクロールバー */
.pane__body::-webkit-scrollbar { width: 11px; height: 11px; }
.pane__body::-webkit-scrollbar-track { background: transparent; }
.pane__body::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 99px;
  border: 3px solid transparent;
  background-clip: content-box;
}
.pane__body::-webkit-scrollbar-thumb:hover { background-color: var(--text-faint); background-clip: content-box; }

/* ---------- 目次（アウトライン） ---------- */

.pane__split {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  position: relative;
}

.pane__split > .pane__body { min-width: 0; }

.outline {
  flex: 0 0 clamp(180px, 30%, 260px);
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-left: 1px solid var(--border);
  background: var(--bg-elevated);
  font-size: 12.5px;
}

.outline[hidden] { display: none; }
.btn[hidden], .menu__item[hidden], .menu__kbd[hidden] { display: none; }

/* ファイル一覧（フォルダ / 複数ファイルを開いているとき）。目次と同じ見た目で、プレビューの左側に出す */
.outline--files { border-left: 0; border-right: 1px solid var(--border); }
.outline--files .outline__head { gap: 2px; }

.files__title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.outline__close:disabled { opacity: .35; cursor: default; background: transparent; }

.files__dir {
  padding: 7px 8px 2px calc(10px + var(--depth, 0) * 12px);
  color: var(--text-faint);
  font-size: .92em;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.files__item.is-active { font-weight: 600; }
.files__item.is-dirty::after { content: " ●"; color: var(--accent); font-size: .7em; vertical-align: middle; }

.outline__head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 36px;
  padding: 0 6px 0 14px;
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: .06em;
  color: var(--text-faint);
}

.outline__close {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
}

.outline__close:hover { background: var(--bg-hover); color: var(--text); }
.outline__close svg { width: 14px; height: 14px; }

.outline__list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  margin: 0;
  padding: 0 6px 16px;
  list-style: none;
}

.outline__item {
  display: block;
  width: 100%;
  padding: 4px 8px 4px calc(8px + var(--depth, 0) * 12px);
  border: 0;
  border-left: 2px solid transparent;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: transparent;
  color: var(--text-muted);
  font-size: inherit;
  line-height: 1.45;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.outline__item[data-depth="0"] { color: var(--text); font-weight: 600; }
.outline__item:hover { background: var(--bg-hover); color: var(--text); }
.outline__item.is-active {
  border-left-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.outline__empty {
  margin: 4px 14px;
  color: var(--text-faint);
  line-height: 1.6;
}

/* ---------- リサイザ ---------- */

.resizer {
  flex: 0 0 auto;
  width: 6px;
  cursor: col-resize;
  background: var(--border);
  border: 0;
  padding: 0;
  position: relative;
  transition: background var(--dur);
}

.resizer::after {
  content: "";
  position: absolute;
  inset: 0 -4px;
}

.resizer:hover,
.resizer.is-dragging { background: var(--accent); }

/* ---------- エディタ ---------- */

.pane__body--editor { position: relative; overflow-anchor: none; }

/*
  エディタ本体（editor.js が描く）。
  .ed-sizer が文書全体の高さを持ち、見えている行だけを .ed-lines に描く。
  選択範囲・検索ハイライトは .ed-marks（文字の背面）、キャレットは .ed-caret。
*/
.ed-sizer {
  position: relative;
  min-height: 100%;
  padding-bottom: 45vh;          /* 最後の行も画面の上の方までスクロールできるように */
  box-sizing: content-box;
  cursor: text;
  font-family: var(--font-mono);
  font-size: var(--ed-fs);
  line-height: var(--ed-lh);
  color: var(--text);
}

.ed-lines {
  position: absolute;
  z-index: 1;
  top: var(--ed-pad-top);
  left: calc(var(--gutter-w) + 14px);
  right: 20px;
  tab-size: 4;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
  /* will-change: transform は付けない（文字が別レイヤーで合成され、にじみやすくなる） */
}

.ed-line { min-height: var(--ed-line); }

/*
  入力欄の Markdown 色付け（mdsyntax.js）。
  行の高さ・折り返し位置が変わらないよう、文字の大きさは変えず、色・太さ・斜体だけで表す。
*/
.md-mark { color: var(--text-faint); }
.md-h { color: var(--tok-fn); font-weight: 700; }
.md-h .md-mark { color: color-mix(in srgb, var(--tok-fn) 55%, transparent); }
.md-strong { font-weight: 700; }
.md-em { font-style: italic; }
.md-del { text-decoration: line-through; color: var(--text-muted); }
.md-hl { background: var(--mark-bg); color: var(--mark-text); border-radius: 2px; }
.md-code {
  color: var(--tok-str);
  background: var(--code-bg);
  border-radius: 3px;
  box-shadow: 0 0 0 1px var(--code-border);
}
.md-code .md-mark { color: color-mix(in srgb, var(--tok-str) 55%, transparent); }
.md-link { color: var(--accent); }
.md-alt { color: var(--tok-type); }
.md-url, .md-ref, .md-title { color: var(--text-faint); }
.md-footnote { color: var(--tok-num); }
.md-list { color: var(--tok-num); font-weight: 700; }
.md-task { color: var(--tok-num); }
.md-task.is-done { color: var(--tok-ins); }
.md-task.is-na { color: var(--text-faint); }
.md-quote { color: var(--text-muted); }
.md-hr { color: var(--text-faint); }
.md-fm-mark { color: var(--text-faint); }
.md-fm-key { color: var(--tok-prop); }
.md-fm-value { color: var(--text-muted); }
.md-fence { color: var(--text-faint); }
.md-lang { color: var(--tok-meta); }
.md-codeblock { color: var(--text); }
.md-html, .md-comment { color: var(--tok-tag); }
.md-comment { color: var(--tok-com); font-style: italic; }
.ed-ime { text-decoration: underline; text-underline-offset: 3px; }

.ed-marks { position: absolute; z-index: 0; inset: 0; pointer-events: none; }
.ed-marks > div { position: absolute; border-radius: 2px; }
.ed-sel { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.ed-hl { background: var(--hl-bg); }
.ed-hl.is-current { background: var(--hl-current-bg); }

.ed-caret {
  position: absolute;
  z-index: 2;
  top: 0;
  left: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--accent);
  pointer-events: none;
}

.ed-caret.is-blink { animation: ed-blink 1.1s steps(1) infinite; }
@keyframes ed-blink { 50% { opacity: 0; } }

.ed-placeholder {
  position: absolute;
  top: var(--ed-pad-top);
  left: calc(var(--gutter-w) + 14px);
  right: 20px;
  color: var(--text-faint);
  pointer-events: none;
}

.ed-placeholder[hidden] { display: none; }

/* キーボード / IME 入力の受け口。キャレットの位置に置くが、見た目には出さない */
.ed-input {
  position: absolute;
  z-index: -1;
  top: 0;
  left: 0;
  width: 1px;
  padding: 0;
  margin: 0;
  border: 0;
  outline: none;
  resize: none;
  overflow: hidden;
  white-space: pre;
  font: inherit;
  color: transparent;
  background: transparent;
  caret-color: transparent;
  opacity: 0;
}

/* 右クリックメニューを出すときだけ、ポインタの下に広げる */
.ed-input.is-context { z-index: 10; width: 24px; height: 24px !important; }

/* 行番号（見えている行のぶんだけ描く） */
.gutter {
  position: absolute;
  z-index: 2;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--gutter-w);
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  line-height: var(--ed-line);
  text-align: right;
  color: var(--text-faint);
  background: var(--bg-sunken);
  border-right: 1px solid var(--border);
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
}

.gutter__rows { position: absolute; top: var(--ed-pad-top); left: 0; right: 0; }

.gutter__row {
  padding-right: 10px;
  overflow: hidden;
}

.gutter__row.is-current { color: var(--text); font-weight: 600; }
.gutter__row:hover { color: var(--text-muted); }

/* 行移動直後に移動先の行を一瞬だけ強調する */
.line-flash {
  position: absolute;
  z-index: 0;
  left: 0;
  right: 0;
  background: var(--accent-soft);
  pointer-events: none;
  animation: line-flash 1.4s ease-out forwards;
}

@keyframes line-flash {
  0%, 40% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---------- 行へ移動（Ctrl+G） ---------- */

.goto {
  position: absolute;
  z-index: 20;
  top: 44px;
  right: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px 7px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-2);
  font-size: 12.5px;
  color: var(--text-muted);
}

.goto[hidden] { display: none; }

.goto__label { font-weight: 600; white-space: nowrap; }

.goto__input {
  width: 9em;
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--bg-sunken);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  outline: none;
}

.goto__input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.goto__input.is-invalid { border-color: var(--tok-del); box-shadow: 0 0 0 3px rgba(192, 57, 43, .15); }

.goto__hint {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-faint);
  white-space: nowrap;
}

/* ---------- 検索と置換 ---------- */

.find {
  position: absolute;
  z-index: 21;
  top: 44px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(460px, calc(100% - 36px));
  padding: 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-2);
  font-size: 12.5px;
  color: var(--text-muted);
}

.find[hidden] { display: none; }

.find__row { display: flex; align-items: center; gap: 4px; min-width: 0; }

.find__input {
  flex: 1 1 auto;
  min-width: 0;
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--bg-sunken);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  outline: none;
}

.find__input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.find__input.is-invalid,
.find.has-none #findInput { border-color: var(--tok-del); box-shadow: 0 0 0 3px rgba(192, 57, 43, .15); }

.find__opts { display: inline-flex; gap: 2px; }

.find__opt,
.find__icon,
.find__btn {
  flex: 0 0 auto;
  height: 28px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.find__opt {
  min-width: 28px;
  padding: 0 4px;
  font-family: var(--font-mono);
  font-size: 12px;
}

.find__opt[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.find__icon { width: 28px; padding: 0; display: inline-grid; place-items: center; }
.find__icon svg { width: 15px; height: 15px; }

.find__btn {
  padding: 0 10px;
  border-color: var(--border-strong);
  background: var(--bg-elevated);
  font-size: 12.5px;
  white-space: nowrap;
}

.find__opt:hover, .find__icon:hover, .find__btn:hover { background: var(--bg-hover); color: var(--text); }
.find__opt[aria-pressed="true"]:hover { background: var(--accent-soft); color: var(--accent); }
.find__icon:disabled, .find__btn:disabled { opacity: .45; cursor: default; background: transparent; }

.find__count {
  flex: 0 0 auto;
  min-width: 4.5em;
  padding: 0 4px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--text-faint);
  white-space: nowrap;
}

.find.has-none .find__count { color: var(--tok-del); }

/* ---------- Vim モード ---------- */

/* ノーマル / ビジュアル中はブラウザのキャレットを隠し、ブロックカーソルを重ねる */
.pane--editor[data-vim="normal"] .ed-caret,
.pane--editor[data-vim="visual"] .ed-caret,
.pane--editor[data-vim="vline"] .ed-caret { display: none; }

.vim-cursor {
  position: absolute;
  z-index: 3;
  top: 0;
  left: 0;
  background: var(--vim-cursor);
  border-radius: 1px;
  pointer-events: none;
}

.vim-cursor[hidden] { display: none; }
.vim-cursor.is-blurred { background: transparent; box-shadow: inset 0 0 0 1px var(--vim-cursor); }

.vim-cmd {
  position: absolute;
  z-index: 21;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border-top: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  box-shadow: 0 -6px 18px rgba(15, 23, 42, .08);
  font-family: var(--font-mono);
  font-size: 13.5px;
}

.vim-cmd[hidden] { display: none; }
.vim-cmd__prefix { color: var(--accent); font-weight: 700; }

.vim-cmd__input {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  outline: none;
}

.vim-cmd__input:focus-visible { outline: none; }

.vim-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-family: var(--font-mono);
}

.vim-status[hidden] { display: none; }

.statusbar .vim-status__mode {
  padding: 1px 7px;
  border-radius: 4px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--accent);
  background: var(--accent-soft);
}

.statusbar .vim-status[data-mode="insert"] .vim-status__mode { color: var(--vim-insert); background: transparent; box-shadow: inset 0 0 0 1px var(--vim-insert); }
.statusbar .vim-status[data-mode="visual"] .vim-status__mode,
.statusbar .vim-status[data-mode="vline"] .vim-status__mode { color: var(--vim-visual); background: transparent; box-shadow: inset 0 0 0 1px var(--vim-visual); }

.vim-status__keys { color: var(--text); min-width: 1ch; }

.vim-status__msg {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 48vw;
  color: var(--text-muted);
}

.vim-status__msg.is-error { color: var(--tok-del); }

.vim-status.is-bell .vim-status__mode { animation: vim-bell .25s ease-out; }

@keyframes vim-bell {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-2px); }
  70% { transform: translateX(2px); }
}

/* ---------- ステータスバー ---------- */

.statusbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 28px;
  padding: 0 14px;
  font-size: 11.5px;
  color: var(--text-faint);
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
}

.statusbar__group { display: flex; gap: 14px; }
.statusbar__spacer { flex: 1 1 auto; }
.statusbar b { font-weight: 600; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.statusbar__note {
  flex: 0 0 auto;
  white-space: nowrap;
  font-weight: 600;
  color: var(--text-muted);
}

.statusbar__hint {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
/* 幅に余裕がないときは、優先度の低いヒントから隠して一行に収める */
@media (max-width: 1440px) {
  .statusbar__hint--extra { display: none; }
}

kbd {
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 1px 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--bg-sunken);
  color: var(--text-muted);
}

.statusbar__help {
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: inherit;
  white-space: nowrap;
  cursor: pointer;
}

.statusbar__help:hover { color: var(--text); }

/* ---------- 操作説明 ---------- */

.help {
  width: min(760px, calc(100vw - 32px));
  max-height: min(86vh, 900px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}

.help[open] { display: flex; flex-direction: column; }
.help::backdrop { background: rgba(15, 23, 42, .45); backdrop-filter: blur(2px); }

.help__head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 12px 22px;
  border-bottom: 1px solid var(--border);
}

.help__title { margin: 0; font-size: 16px; font-weight: 680; }
.help__version { margin-left: 6px; font-family: var(--font-mono); font-size: 12px; font-weight: 500; color: var(--text-faint); }

.help__close {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.help__close:hover { background: var(--bg-hover); color: var(--text); }
.help__close svg { width: 16px; height: 16px; }

.help__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 22px 22px;
  font-size: 13.5px;
  line-height: 1.65;
}

.help__lead { margin: 0 0 16px; color: var(--text-muted); }
.help__lead strong { color: var(--text); }
.help__lead a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

.help__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 4px 28px;
}

.help__sec { margin-bottom: 14px; }

.help__sec h3 {
  margin: 0 0 6px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--text-faint);
}

.help__sec p { margin: 0; }
.help__sec table { width: 100%; border-collapse: collapse; }

.help__sec th, .help__sec td {
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: baseline;
  font-weight: 400;
}

.help__sec tr:last-child th, .help__sec tr:last-child td { border-bottom: 0; }
.help__sec th { width: 1%; padding-right: 14px; white-space: nowrap; color: var(--text-faint); }
.help__sec kbd { font-size: 11px; }

.help__sec code {
  font-family: var(--font-mono);
  font-size: .88em;
  padding: .05em .35em;
  border-radius: 4px;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
}

.help__list { margin: 0; padding-left: 1.2em; }
.help__list li { margin: 2px 0; }
.help__syntax { display: flex; flex-wrap: wrap; gap: 6px; }
.help__note { margin-top: 8px !important; color: var(--text-muted); font-size: 12.5px; }

@media (max-width: 520px) {
  .help { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; border: 0; }
  .help__body { padding: 14px 16px 20px; }
  .help__grid { grid-template-columns: 1fr; }
}

/* ---------- トースト ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 54px;
  transform: translate(-50%, 12px);
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg-elevated);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-2);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur), transform var(--dur);
  z-index: 100;
}

.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ==================================================================
   プレビュー本文のタイポグラフィ
   ================================================================== */

/*
  本文幅は 2 モード（ツールバーの「幅」ボタンで切り替え）。
   既定             : ペインの幅いっぱい。仕切りを動かすと本文幅も一緒に変わる
   data-width=narrow: 可読行長を優先して上限を設け、中央寄せにする
*/
.preview {
  max-width: none;
  margin: 0;
  /* ペインを狭くしたときに左右の余白で潰れないよう、余白も可変にする */
  padding: 28px clamp(16px, 2.2vw, 32px) 45vh;
  font-size: 15.5px;
  line-height: 1.85;
  word-wrap: break-word;
}

body[data-width="narrow"] .preview {
  max-width: 50rem;   /* 全角 40 字前後 */
  margin: 0 auto;
}

.preview > *:first-child { margin-top: 0; }
.preview > *:last-child { margin-bottom: 0; }

.preview h1, .preview h2, .preview h3,
.preview h4, .preview h5, .preview h6 {
  margin: 1.9em 0 .7em;
  line-height: 1.4;
  font-weight: 680;
  letter-spacing: .005em;
  scroll-margin-top: 12px;
  position: relative;
}

.preview h1 { font-size: 1.85em; padding-bottom: .35em; border-bottom: 1px solid var(--border); }
.preview h2 { font-size: 1.45em; padding-bottom: .3em; border-bottom: 1px solid var(--border); }
.preview h3 { font-size: 1.2em; }
.preview h4 { font-size: 1.05em; }
.preview h5 { font-size: .95em; }
.preview h6 { font-size: .9em; color: var(--text-muted); }

.heading-anchor {
  position: absolute;
  left: -.85em;
  top: 0;
  width: .85em;
  text-align: center;
  color: var(--text-faint);
  text-decoration: none;
  opacity: 0;
  font-weight: 400;
  transition: opacity var(--dur);
}

.preview h1:hover .heading-anchor,
.preview h2:hover .heading-anchor,
.preview h3:hover .heading-anchor,
.preview h4:hover .heading-anchor,
.preview h5:hover .heading-anchor,
.preview h6:hover .heading-anchor { opacity: 1; }

.heading-anchor:hover { color: var(--accent); }

.preview p { margin: 0 0 1.05em; }

.preview a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--border-strong);
  border-bottom-color: color-mix(in srgb, var(--accent) 35%, transparent);
  transition: border-color var(--dur), background var(--dur);
}

.preview a:hover {
  border-bottom-color: var(--accent);
  background: var(--accent-soft);
}

.preview strong { font-weight: 700; }
.preview em { font-style: italic; }
.preview del { color: var(--text-muted); }

.preview mark {
  background: var(--mark-bg);
  color: var(--mark-text);
  padding: .1em .25em;
  border-radius: 3px;
}

.preview hr {
  height: 1px;
  border: 0;
  margin: 2.2em 0;
  background: var(--border);
}

/* --- リスト --- */

.preview ul, .preview ol { margin: 0 0 1.05em; padding-left: 1.6em; }
.preview li { margin: .3em 0; }
.preview li > ul, .preview li > ol { margin: .3em 0 .3em; }
.preview li::marker { color: var(--text-faint); }
.preview ol > li::marker { font-variant-numeric: tabular-nums; font-weight: 600; }

.preview li.task-list-item {
  list-style: none;
  margin-left: -1.6em;
  padding-left: 0;
}

.task-checkbox {
  appearance: none;
  -webkit-appearance: none;
  width: 1.05em;
  height: 1.05em;
  margin: 0 .5em 0 0;
  vertical-align: -.15em;
  border: 1.5px solid var(--border-strong);
  border-radius: 4px;
  background: var(--bg-elevated);
  flex: 0 0 auto;
}

.task-checkbox:checked {
  background: var(--accent);
  border-color: var(--accent);
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='white' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round' d='M3.5 8.4l3 3 6-6.5'/%3E%3C/svg%3E");
  background-size: 100% 100%;
}

.preview li.task-list-item:has(.task-checkbox:checked) {
  color: var(--text-muted);
}

/* 対象外のタスク（[~]。GitLab） */
.preview li.task-list-item--inapplicable {
  color: var(--text-muted);
  text-decoration: line-through;
}
.preview li.task-list-item--inapplicable > .task-checkbox {
  border-style: dashed;
  background: var(--bg-hover);
}

/* --- 引用 --- */

.preview blockquote {
  margin: 0 0 1.05em;
  padding: .1em 0 .1em 1.1em;
  border-left: 3px solid var(--quote-bar);
  color: var(--text-muted);
}

.preview blockquote > *:last-child { margin-bottom: 0; }
.preview blockquote blockquote { margin-top: .6em; }

/* --- GitLab の記法 --- */

/* アラート（> [!note] / >>> [!warning] など） */
.preview .markdown-alert {
  --alert: var(--alert-note);
  margin: 0 0 1.05em;
  padding: .55em 1em .6em;
  border-left: 3px solid var(--alert);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: color-mix(in srgb, var(--alert) 7%, transparent);
}
.preview .markdown-alert-tip { --alert: var(--alert-tip); }
.preview .markdown-alert-important { --alert: var(--alert-important); }
.preview .markdown-alert-warning { --alert: var(--alert-warning); }
.preview .markdown-alert-caution { --alert: var(--alert-caution); }
.preview .markdown-alert > *:last-child { margin-bottom: 0; }
.preview .markdown-alert-title {
  margin: 0 0 .3em;
  color: var(--alert);
  font-weight: 700;
}

/* インライン差分（{+ 追加 +} / [- 削除 -]） */
.preview .idiff {
  padding: .05em .2em;
  border-radius: 3px;
  color: inherit;
  text-decoration: none;
}
.preview .idiff--add { background: color-mix(in srgb, var(--tok-ins) 18%, transparent); }
.preview .idiff--del {
  background: color-mix(in srgb, var(--tok-del) 18%, transparent);
  text-decoration: line-through;
  text-decoration-color: var(--tok-del);
}

/* インラインコードの色見本（`#F00` など） */
.preview .color-chip {
  display: inline-block;
  width: .85em;
  height: .85em;
  margin-left: .35em;
  vertical-align: -.08em;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
}

/* 目次（[[_TOC_]] / [TOC]） */
.preview .toc {
  margin: 0 0 1.2em;
  padding: .6em 1em;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
}
.preview .toc ul { margin: 0; padding-left: 1.3em; }
.preview .toc li { margin: .15em 0; }
.preview .toc:empty { display: none; }

/* --- コード --- */

.preview .inline-code,
.statusbar code {
  font-family: var(--font-mono);
  font-size: .87em;
  padding: .15em .4em;
  border-radius: 5px;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  word-break: break-word;
}

.code-block {
  position: relative;
  margin: 0 0 1.2em;
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  background: var(--code-bg);
  overflow: hidden;
}

.code-block__lang {
  position: absolute;
  top: 0;
  right: 0;
  padding: 3px 10px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-faint);
  background: linear-gradient(to left, var(--code-bg) 72%, transparent);
  border-bottom-left-radius: 8px;
  pointer-events: none;
  user-select: none;
}

.code-block pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  line-height: 1.65;
}

.code-block code {
  font-family: var(--font-mono);
  font-size: 13px;
  tab-size: 4;
  white-space: pre;
}

.code-copy {
  position: absolute;
  top: 6px;
  right: 6px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--dur), color var(--dur);
}

.code-block:hover .code-copy,
.code-copy:focus-visible { opacity: 1; }
.code-copy:hover { color: var(--text); }
.code-copy svg { width: 14px; height: 14px; }
.code-block:hover .code-block__lang { opacity: 0; }

/* 図（```mermaid）。色はテーマの変数から作るので、明暗の切り替えに追従する */
:root {
  --mmd-fill: color-mix(in srgb, var(--accent) 9%, var(--bg-elevated));
  --mmd-stroke: color-mix(in srgb, var(--accent) 50%, var(--bg-elevated));
  --mmd-line: var(--text-muted);
  --mmd-note-fill: color-mix(in srgb, #facc15 20%, var(--bg-elevated));
  --mmd-note-stroke: color-mix(in srgb, #ca8a04 55%, var(--bg-elevated));
  --mmd-crit: #dc2626;
}

.diagram {
  margin: 0 0 1.2em;
  padding: 16px;
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  overflow-x: auto;
  text-align: center;
}
.diagram svg { max-width: 100%; height: auto; vertical-align: top; }

.mmd text { font-family: var(--font-sans); font-size: 14px; fill: var(--text); }
.mmd .mmd-title { font-size: 18px; font-weight: 600; }

.mmd-cluster { fill: var(--text); fill-opacity: .035; stroke: var(--text-faint); stroke-opacity: .7; }
.mmd .mmd-cluster-title { font-weight: 600; fill: var(--text-muted); stroke: var(--bg-elevated); stroke-width: 4px; stroke-linejoin: round; paint-order: stroke; }
.mmd-node { fill: var(--mmd-fill); stroke: var(--mmd-stroke); stroke-width: 1.3; }
.mmd-edge { fill: none; stroke: var(--mmd-line); stroke-width: 1.5; }
.mmd-edge--dotted { stroke-dasharray: 3 4; }
.mmd-edge--thick { stroke-width: 3; }
.mmd-arrow { fill: var(--mmd-line); }
.mmd-arrow-o { fill: var(--bg-elevated); stroke: var(--mmd-line); stroke-width: 1.5; }
.mmd-arrow-x { fill: none; stroke: var(--mmd-line); stroke-width: 2; }
.mmd-edge-label { fill: var(--bg-elevated); opacity: .9; }

.mmd-seq-actor { fill: var(--mmd-fill); stroke: var(--mmd-stroke); stroke-width: 1.3; }
.mmd-seq-figure { fill: none; stroke: var(--mmd-stroke); stroke-width: 1.6; }
.mmd-seq-life { stroke: var(--text-faint); stroke-dasharray: 3 3; }
.mmd-seq-msg { fill: none; stroke: var(--text); stroke-width: 1.4; }
.mmd-seq-msg--dotted { stroke-dasharray: 4 3; }
.mmd-seq-arrow { fill: var(--text); }
.mmd-seq-open,
.mmd-seq-cross { fill: none; stroke: var(--text); stroke-width: 1.6; }
.mmd-seq-act { fill: var(--bg-active); stroke: var(--text-faint); }
.mmd-seq-note { fill: var(--mmd-note-fill); stroke: var(--mmd-note-stroke); }
.mmd-seq-frame { fill: none; stroke: var(--text-faint); }
.mmd-seq-tag { fill: var(--mmd-fill); stroke: var(--text-faint); }
.mmd .mmd-seq-tag-text { font-size: 12px; font-weight: 600; }
.mmd-seq-sep { stroke: var(--text-faint); stroke-dasharray: 4 3; }
.mmd-seq-num { fill: var(--accent); }
.mmd .mmd-seq-num-text { font-size: 11px; fill: var(--accent-text); }
.mmd-seq-rect { opacity: .6; }
.mmd-seq-rect:not([fill]) { fill: var(--accent-soft); }   /* rect rgb(...) の色指定がないとき */

.mmd-gantt-sec--0 { fill: color-mix(in srgb, var(--accent) 5%, var(--bg-elevated)); }
.mmd-gantt-sec--1 { fill: var(--bg-elevated); }
.mmd .mmd-gantt-sec-text { font-size: 13px; font-weight: 600; }
.mmd-gantt-grid { stroke: var(--border); }
.mmd .mmd-gantt-tick { font-size: 11px; fill: var(--text-muted); }
.mmd-gantt-excl { fill: var(--text); opacity: .05; }
.mmd-gantt-today { stroke: var(--mmd-crit); stroke-width: 2; }
.mmd-gantt-task { fill: color-mix(in srgb, var(--accent) 75%, var(--bg-elevated)); stroke: var(--accent); }
.mmd-gantt-task--active { fill: color-mix(in srgb, var(--accent) 22%, var(--bg-elevated)); }
.mmd-gantt-task--done { fill: color-mix(in srgb, var(--text-faint) 40%, var(--bg-elevated)); stroke: var(--text-faint); }
.mmd-gantt-task--crit { fill: color-mix(in srgb, var(--mmd-crit) 40%, var(--bg-elevated)); stroke: var(--mmd-crit); }
.mmd .mmd-gantt-text { font-size: 12px; }
.mmd .mmd-gantt-text--in { fill: var(--accent-text); }
.mmd .mmd-gantt-text--done,
.mmd .mmd-gantt-text--active,
.mmd .mmd-gantt-text--crit { fill: var(--text); }

/* シンタックスハイライト配色 */
.tok-com  { color: var(--tok-com); font-style: italic; }
.tok-str  { color: var(--tok-str); }
.tok-num  { color: var(--tok-num); }
.tok-kw   { color: var(--tok-kw); font-weight: 600; }
.tok-lit  { color: var(--tok-lit); }
.tok-fn   { color: var(--tok-fn); }
.tok-type { color: var(--tok-type); }
.tok-op   { color: var(--tok-op); }
.tok-pun  { color: var(--tok-pun); }
.tok-var  { color: var(--tok-var); }
.tok-attr { color: var(--tok-attr); }
.tok-tag  { color: var(--tok-tag); }
.tok-sel  { color: var(--tok-sel); }
.tok-prop { color: var(--tok-prop); }
.tok-meta { color: var(--tok-meta); font-weight: 600; }
.tok-ins  { color: var(--tok-ins); }
.tok-del  { color: var(--tok-del); }

/* --- 表 --- */

.table-wrap {
  margin: 0 0 1.3em;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.preview table {
  width: 100%;
  border-collapse: collapse;
  font-size: .94em;
}

.preview th, .preview td {
  padding: 8px 13px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

/* 表の列揃え（| :-: | --: |）。markdown.js がセルに付けるクラス */
.preview th.align-left, .preview td.align-left { text-align: left; }
.preview th.align-center, .preview td.align-center { text-align: center; }
.preview th.align-right, .preview td.align-right { text-align: right; }

.preview th:last-child, .preview td:last-child { border-right: 0; }
.preview tbody tr:last-child td { border-bottom: 0; }

.preview thead th {
  background: var(--bg-hover);
  font-weight: 650;
  white-space: nowrap;
}

.preview tbody tr:nth-child(even) { background: var(--table-stripe); }

/* --- フロントマター（項目と値の表） --- */

.preview .frontmatter { font-size: .92em; }
.preview .frontmatter table { font-size: 1em; }

.preview .frontmatter th {
  width: 1%;
  background: var(--bg-hover);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: .92em;
  font-weight: 600;
  white-space: nowrap;
}

.preview .frontmatter td { white-space: pre-wrap; overflow-wrap: anywhere; }
.preview .frontmatter tbody tr:nth-child(even) { background: none; }

.preview .frontmatter__list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.preview .frontmatter__list li {
  margin: 0;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-hover);
  font-size: .92em;
}

.preview .frontmatter__raw {
  display: block;
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
  font-size: .92em;
  white-space: pre-wrap;
}

/* --- 画像 --- */

.preview img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
}

/* --- 脚注 --- */

.preview .footnote-ref { font-size: .72em; line-height: 0; vertical-align: super; }
.preview .footnote-ref a { padding: 0 .15em; border-bottom: 0; font-variant-numeric: tabular-nums; }

.preview .footnotes {
  margin-top: 2.6em;
  padding-top: 1.1em;
  border-top: 1px solid var(--border);
  font-size: .9em;
  color: var(--text-muted);
}

.preview .footnotes ol { margin-bottom: 0; }
.preview .footnotes li p { margin: 0 0 .4em; }
.preview .footnote-backref { border-bottom: 0; margin-left: .15em; font-family: var(--font-sans); }
.preview .footnote-backref sup { font-size: .7em; }

/* 脚注リンクで移動した先を一瞬だけ強調する */
.preview .is-target { animation: target-flash 1.6s ease-out; border-radius: 4px; }

@keyframes target-flash {
  0%, 30% { background: var(--hl-bg); }
  100% { background: transparent; }
}

/* --- 入力欄のカーソル位置に対応する要素 --- */

.preview .is-cursor {
  background-color: color-mix(in srgb, var(--accent) 9%, transparent);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 9%, transparent);
  border-radius: 3px;
}

/* 背景色を持つ要素は枠で示す */
.preview .code-block.is-cursor,
.preview .table-wrap.is-cursor {
  background-color: var(--code-bg);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent);
}
.preview .table-wrap.is-cursor { background-color: transparent; }
.preview tr.is-cursor { box-shadow: none; background: none; }
.preview tr.is-cursor > * { background-color: color-mix(in srgb, var(--accent) 12%, transparent); }

@media print {
  .preview .is-cursor { background: none !important; box-shadow: none !important; }
  .preview tr.is-cursor > * { background: none !important; }
}

/* --- 空状態 --- */

.preview-empty {
  display: grid;
  place-items: center;
  gap: 10px;
  min-height: 55vh;
  color: var(--text-faint);
  text-align: center;
}

.preview-empty svg { width: 40px; height: 40px; opacity: .5; }

/* ==================================================================
   リーディングモード（プレビューだけを大きく表示する）
   文字の倍率 --read-scale は app.js が <html> に設定する。印刷・HTML の書き出しには影響させない
   ================================================================== */

.readsize { display: inline-flex; align-items: center; flex: 0 0 auto; }
.readsize[hidden] { display: none; }
.readsize__value {
  min-width: 3.4em;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.readsize__s { font-size: 12px; font-weight: 600; }
.readsize__l { font-size: 18px; font-weight: 600; }
.readsize .btn:disabled { opacity: .35; cursor: default; background: transparent; }

/* ヘッダーが溢れる幅ではアイコンだけにする */
@media (max-width: 960px) {
  #btnReading .btn__label { display: none; }
  #btnReading { padding: 0; width: 32px; justify-content: center; }
}

@media screen {
  body[data-reading="on"] .pane--editor,
  body[data-reading="on"] .resizer,
  body[data-reading="on"] .pane__head,
  body[data-reading="on"] .statusbar,
  body[data-reading="on"] .tabs,
  body[data-reading="on"] #btnFind,
  body[data-reading="on"] .menu__editor { display: none; }

  body[data-reading="on"] .pane--preview { display: flex; background: var(--bg-elevated); }
  body[data-reading="on"] #previewScroll:focus { outline: none; }

  body[data-reading="on"] .preview {
    max-width: 52em;   /* 全角 50 字ほど。文字の倍率に合わせて広がる */
    margin: 0 auto;
    padding-top: 1.6em;
    font-size: calc(15.5px * var(--read-scale, 1.5));
    line-height: 1.75;
  }
  body[data-reading="on"] .code-block code { font-size: calc(13px * var(--read-scale, 1.5)); }
  body[data-reading="on"] .code-block__lang { font-size: calc(10.5px * var(--read-scale, 1.5)); }
  body[data-reading="on"] .preview th,
  body[data-reading="on"] .preview td { padding: .5em .85em; }
  body[data-reading="on"] .diagram svg { zoom: var(--read-scale, 1.5); }
}

/* ==================================================================
   レスポンシブ
   ================================================================== */

@media (max-width: 860px) {
  .header { gap: 8px; padding: 0 10px; }
  .tabs { display: flex; }
  .resizer { display: none; }

  .workspace { position: relative; }
  .pane--editor, .pane--preview {
    flex: 1 1 100% !important;   /* デスクトップ用に JS が付けるインラインの幅指定を打ち消す */
    width: 100%;
  }

  body[data-mobile-view="editor"] .pane--preview { display: none; }
  body[data-mobile-view="preview"] .pane--editor { display: none; }

  .pane__head { display: none; }
  .goto { top: 10px; right: 10px; left: 10px; }
  .find { top: 10px; right: 10px; left: 10px; width: auto; }
  .find__btn { padding: 0 8px; }
  .goto__input { flex: 1 1 auto; width: auto; min-width: 0; }
  .preview { padding: 20px 18px 40vh; font-size: 15px; }
  .toolbar .btn__label { display: none; }
  .toolbar .btn { padding: 0; width: 32px; justify-content: center; }
  .statusbar__hint, .statusbar__help { display: none; }
  /* 1 ペインずつの表示ではスクロール連動は意味がないので隠し、ボタンが溢れたら横スクロールさせる */
  #btnSync { display: none; }
  /* 狭い画面では目次をプレビューの上に重ねる */
  .outline {
    position: absolute;
    inset: 0 0 0 auto;
    width: min(320px, 86%);
    z-index: 5;
    box-shadow: var(--shadow-2);
    font-size: 14px;
  }
  .outline--files { inset: 0 auto 0 0; }
  .outline__item { padding-top: 7px; padding-bottom: 7px; }
  .toolbar { overflow-x: auto; scrollbar-width: none; }
  .toolbar::-webkit-scrollbar { display: none; }
  .menu { position: fixed; top: calc(var(--header-h) + 4px); left: 10px; right: 10px; width: auto; min-width: 0; max-width: none; }
  .menu--right { left: 10px; }
  .menu__kbd { display: none; }
}

@media (max-width: 640px) {
  .brand__name, .brand__version { display: none; }
}

@media (max-width: 520px) {
  .tab { padding: 5px 10px; }
  .toolbar { gap: 3px; }
  .toolbar__sep, .btn__caret { display: none; }
}

@media (max-width: 420px) {
  .brand { display: none; }
}

/* ==================================================================
   印刷（プレビューのみ出力）
   ================================================================== */

@media print {
  body { overflow: visible; background: #fff; }
  .header, .statusbar, .resizer, .pane--editor, .pane__head, .toast, .code-copy, .find, .vim-cmd, .outline { display: none !important; }
  .app, .workspace, .pane--preview, .pane__split, .pane__body { display: block; height: auto; overflow: visible; }
  .preview { max-width: none; padding: 0; color: #000; }
  .code-block, .diagram, .table-wrap { break-inside: avoid; }
  /* 見出しだけがページの末尾に残らないようにする */
  .preview h1, .preview h2, .preview h3, .preview h4, .preview h5, .preview h6 { break-after: avoid; }
  /* 印刷時は用紙の幅で「狭い画面」の指定（860px 以下）も効き、入力欄のタブを選んでいるとプレビューが隠れて白紙になる。
     どちらのタブでもプレビューを出す */
  body[data-mobile-view] .pane--preview { display: block !important; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
