:root {
  --bg: #fdfdfb;
  --fg: #1f2328;
  --muted: #5d6670;
  --link: #0b57b0;
  --border: #d5d8dc;
  --code-bg: #f4f5f2;
  --ln: #6b737c;
  --target: #fff3b8;
  --focus: #c25e00;
  --chat-side-bg: #2f2340;
  --chat-side-fg: #e9e3f2;
  --chat-side-active: #1d64b8;
  --ticket-bg: #fffbe6;
  --st-new: #0b57b0;
  --st-progress: #9a5b00;
  --st-done: #1e7a3c;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17191c;
    --fg: #e6e8ea;
    --muted: #a3abb4;
    --link: #8ab8ff;
    --border: #3a3f45;
    --code-bg: #1f2226;
    --ln: #949ca5;
    --target: #4a4114;
    --focus: #ffb366;
  --chat-side-bg: #241b31;
  --chat-side-active: #1d64b8;
  --ticket-bg: #23221b;
  --st-new: #8ab8ff;
  --st-progress: #f0b45a;
  --st-done: #6fd08e;
  }
}
:root[data-theme="dark"] {
  --bg: #17191c;
  --fg: #e6e8ea;
  --muted: #a3abb4;
  --link: #8ab8ff;
  --border: #3a3f45;
  --code-bg: #1f2226;
  --ln: #949ca5;
  --target: #4a4114;
  --focus: #ffb366;
  --chat-side-bg: #241b31;
  --chat-side-active: #1d64b8;
  --ticket-bg: #23221b;
  --st-new: #8ab8ff;
  --st-progress: #f0b45a;
  --st-done: #6fd08e;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  line-height: 1.7;
}
a { color: var(--link); }
a:focus-visible, main:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
main:focus:not(:focus-visible) { outline: none; }

.skip {
  position: absolute; left: 8px; top: -100px;
  background: var(--bg); padding: 8px 12px; border: 2px solid var(--focus);
}
.skip:focus { top: 8px; }

.site-header, main, .site-footer {
  max-width: 60rem; margin: 0 auto; padding: 0 16px;
}
.site-header { border-bottom: 1px solid var(--border); }
.brand { margin: 0; padding: 12px 0; font-weight: 600; }
.brand a { color: inherit; text-decoration: none; }
.brand a:hover { text-decoration: underline; }
main { padding-top: 8px; padding-bottom: 32px; }
.site-footer {
  border-top: 1px solid var(--border);
  color: var(--muted); font-size: 0.875rem; padding-bottom: 24px;
}

h1 { font-size: 1.6rem; line-height: 1.3; margin: 0.6em 0 0.3em; overflow-wrap: anywhere; }
h2 { font-size: 1.15rem; margin: 1.6em 0 0.4em; overflow-wrap: anywhere; }

.meta, .muted { color: var(--muted); }

.breadcrumbs ol { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-wrap: wrap; }
.breadcrumbs li { overflow-wrap: anywhere; }
.breadcrumbs li + li::before { content: "›"; padding: 0 0.5em; color: var(--muted); }
.breadcrumbs [aria-current] { color: var(--fg); text-decoration: none; }

.file-list { padding-left: 1.4em; margin: 0.2em 0; }
.file-list li { overflow-wrap: anywhere; }

.file-nav ul { list-style: none; padding: 0; margin: 12px 0; display: flex; flex-wrap: wrap; gap: 4px 24px; }
.file-nav li { overflow-wrap: anywhere; }

.source {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 0;
  margin: 0;
  font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, "BIZ UDGothic", monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.source .line {
  display: block;
  padding: 0 12px 0 calc(var(--lnw, 4ch) + 28px);
  text-indent: calc(-1 * (var(--lnw, 4ch) + 16px));
}
.source .ln {
  display: inline-block;
  width: var(--lnw, 4ch);
  margin-right: 16px;
  text-align: right;
  text-indent: 0;
  color: var(--ln);
  user-select: none;
  -webkit-user-select: none;
}
.source .line:target { background: var(--target); }
.up { margin-top: 2em; }

/* サイト内ナビ */
.site-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0 24px; }
.sitenav ul, .portal-menu ul { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 4px 20px; }
.sitenav [aria-current] { font-weight: 600; }
.portal-menu {
  max-width: 60rem; margin: 0 auto; padding: 8px 16px;
  border-bottom: 1px solid var(--border); font-size: 0.95rem;
}
.portal-menu [aria-current] { color: var(--fg); font-weight: 600; text-decoration: none; }

/* 表 */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.95rem; }
caption { text-align: left; font-weight: 600; padding: 4px 0; }
th, td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
thead th { background: var(--code-bg); }
tbody th { font-weight: normal; white-space: nowrap; }
.log-table { font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, "BIZ UDGothic", monospace; font-size: 0.85rem; }
.log-table th, .log-table td { white-space: nowrap; }
/* パス・参照元・ブラウザだけ折り返す（短い列は1行に収め、はみ出す分は横にスクロール） */
.log-table td:nth-child(5), .log-table td:nth-child(9), .log-table td:nth-child(10) { white-space: normal; overflow-wrap: anywhere; min-width: 12em; }
.log-table td:nth-child(10) { min-width: 20em; }
.log-table tr:target { background: var(--target); }
.log-table.memo-ready .ln { cursor: pointer; }
.log-table.memo-ready .ln:hover { color: var(--link); text-decoration: underline; }

/* メール・日報 */
.post { border: 1px solid var(--border); border-radius: 6px; padding: 0 16px 12px; margin: 16px 0; }
.post h2 { margin-top: 0.8em; }
.post-headers { display: grid; grid-template-columns: max-content 1fr; gap: 0 12px; margin: 0 0 8px; color: var(--muted); font-size: 0.9rem; }
.post-headers dt { font-weight: 600; }
.post-headers dd { margin: 0; overflow-wrap: anywhere; }
.post-body { white-space: pre-wrap; overflow-wrap: anywhere; }

/* フォーム */
.form { margin: 16px 0; }
.field { margin-bottom: 12px; }
.field label { display: block; font-weight: 600; }
.field input {
  font: inherit; width: 100%; max-width: 24rem; padding: 8px 10px;
  color: var(--fg); background: var(--bg); border: 1px solid var(--muted); border-radius: 4px;
}
.field input[aria-invalid="true"] { border: 2px solid #c62828; }
.help { color: var(--muted); font-size: 0.9rem; margin: 4px 0 0; }
button {
  font: inherit; padding: 8px 20px; border-radius: 4px; cursor: pointer;
  color: #fff; background: #0b57b0; border: 1px solid #0b57b0;
}
input:focus-visible, button:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
#result { font-weight: 600; min-height: 1.7em; }
.notice { border-left: 4px solid var(--link); padding: 8px 12px; background: var(--code-bg); }
.menu-list li { margin: 4px 0; }

/* 報告書フォーム */
.question { border: 1px solid var(--border); border-radius: 6px; margin: 0 0 16px; padding: 8px 16px 12px; }
.question legend { font-weight: 600; padding: 0 4px; }
.choice { display: flex; align-items: flex-start; gap: 8px; margin: 6px 0; }
.choice input { margin-top: 0.45em; width: 1.1rem; height: 1.1rem; flex: none; }
.choice label { cursor: pointer; }
.step-title { margin: 16px 0 8px; }
.step-nav { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 16px; }
.confirm-list dt { font-weight: 600; margin-top: 12px; }
.confirm-list dd { margin: 4px 0 0 1.5em; }
.confirm-list dd ul { margin: 0; padding-left: 1.2em; }

/* 読み上げ専用 */
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* チャット */
.app-shell {
  display: grid; grid-template-columns: 11rem 1fr; margin-top: 12px;
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.app-sidebar { background: var(--chat-side-bg); color: var(--chat-side-fg); padding: 12px 0; }
.app-ws { font-weight: 700; margin: 0 0 8px; padding: 0 16px; }
.app-sidebar ul { list-style: none; margin: 0; padding: 0; }
.app-sidebar a { display: block; padding: 2px 16px; color: inherit; text-decoration: none; opacity: 0.85; }
.app-sidebar a:hover { text-decoration: underline; opacity: 1; }
.app-sidebar a[aria-current] { background: var(--chat-side-active); color: #fff; opacity: 1; font-weight: 600; }
.app-main { min-width: 0; padding: 0 0 12px; }
.app-header { padding: 8px 16px; border-bottom: 1px solid var(--border); }
.app-header h1 { font-size: 1.2rem; margin: 0.2em 0; }
.app-desc { margin: 0; color: var(--muted); font-size: 0.9rem; }
.day-sep {
  display: flex; align-items: center; gap: 12px; margin: 16px 16px 4px;
  font-size: 0.85rem; font-weight: 600; color: var(--muted);
}
.day-sep::before, .day-sep::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.messages { list-style: none; margin: 0; padding: 0; }
.msg { display: flex; gap: 10px; padding: 6px 16px; }
.msg:hover, .msg:target { background: var(--code-bg); }
.msg:target { box-shadow: inset 3px 0 0 var(--focus); }
.msg.compact { padding-top: 0; }
.avatar {
  flex: none; width: 36px; height: 36px; border-radius: 6px; margin-top: 4px;
  display: grid; place-items: center; color: #fff; font-weight: 700;
}
img.avatar { padding: 0; object-fit: cover; }
.avatar.retired { filter: grayscale(1); opacity: 0.6; }
.retired-badge { font-weight: normal; font-size: 0.8rem; color: var(--muted); }
.journal-item h3 { display: flex; align-items: center; gap: 8px; }
.journal-item h3 .avatar { width: 24px; height: 24px; margin: 0; font-size: 0.75rem; }
.mail-from .avatar { margin-top: 0; }
.av0 { background: #8e3b9e; } .av1 { background: #1e6b52; } .av2 { background: #b4451f; }
.av3 { background: #2459a8; } .av4 { background: #7a5c00; } .av5 { background: #a2264f; }
.msg-side { flex: none; width: 36px; font-size: 0.7rem; color: var(--muted); text-align: right; padding-top: 0.35em; visibility: hidden; }
.msg.compact:hover .msg-side, .msg.compact:focus-within .msg-side { visibility: visible; }
.msg-main { min-width: 0; flex: 1; }
.msg-head { font-size: 1rem; margin: 0; }
.msg-name { font-weight: 700; }
.msg-head time { font-weight: normal; font-size: 0.8rem; color: var(--muted); margin-left: 4px; }
.msg-body { margin: 0; overflow-wrap: anywhere; }
.reactions { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 0; padding: 0; }
.reactions li {
  border: 1px solid var(--border); border-radius: 999px; padding: 0 8px; font-size: 0.85rem;
  background: var(--bg);
}
.reactions .who { color: var(--muted); }
.thread { margin-top: 6px; border-left: 3px solid var(--border); padding-left: 4px; }
.thread-label { margin: 0; padding-left: 12px; font-size: 0.85rem; color: var(--link); font-weight: 600; }
.thread .msg { padding-left: 12px; }
.thread .msg-head { font-size: 0.95rem; }
.thread .avatar { width: 28px; height: 28px; font-size: 0.85rem; }
@media (max-width: 40rem) {
  .app-shell { grid-template-columns: 1fr; }
  .app-sidebar { padding: 8px 0; }
  .app-sidebar ul { display: flex; flex-wrap: wrap; }
}

/* チケット */
.badge {
  display: inline-block; padding: 0 8px; border-radius: 4px; font-size: 0.85rem; white-space: nowrap;
  border: 1px solid currentColor;
}
.st-new { color: var(--st-new); } .st-progress { color: var(--st-progress); }
.st-done { color: var(--st-done); } .st-rejected, .st-other { color: var(--muted); }
.ticket-list td:nth-child(5) { min-width: 12rem; }
.ticket-tracker { color: var(--muted); font-weight: normal; }
.ticket-box { background: var(--ticket-bg); border: 1px solid var(--border); border-radius: 6px; padding: 4px 16px 8px; margin: 12px 0; }
.ticket-box h2 { font-size: 1rem; margin: 0.8em 0 0.3em; }
.ticket-attrs { width: auto; }
.ticket-attrs th, .ticket-attrs td { border: none; padding: 2px 16px 2px 0; }
.ticket-attrs th { color: var(--muted); font-weight: 600; }
.journal { list-style: none; padding: 0; margin: 0; }
.journal-item { border-top: 1px solid var(--border); padding: 4px 0 8px; }
.journal-item h3 { font-size: 0.95rem; margin: 0.4em 0; }
.changes { margin: 0.2em 0; padding-left: 1.4em; font-size: 0.95rem; }
.note p { margin: 0.4em 0; }

/* メール */
.app-shell.mail .app-sidebar { background: var(--code-bg); color: var(--fg); border-right: 1px solid var(--border); }
.app-shell.mail .app-sidebar a[aria-current] { background: var(--chat-side-active); color: #fff; }
.app-ws { overflow-wrap: anywhere; font-size: 0.9rem; }
.unread-count { font-size: 0.85em; }
.mail-list { border: none; }
.mail-list th, .mail-list td { border: none; border-bottom: 1px solid var(--border); }
.mail-list thead th { background: transparent; color: var(--muted); font-size: 0.85rem; }
.mail-list tbody th { white-space: normal; }
.mail-list tr.unread th, .mail-list tr.unread td:nth-child(2) { font-weight: 700; }
.mail-list td:first-child { width: 4.5em; }
.mail-list td:last-child { white-space: nowrap; color: var(--muted); }
.mail-view { padding: 0 16px; }
.mail-from { display: flex; gap: 12px; align-items: flex-start; margin: 12px 0; }
.mail-from .post-headers { margin: 0; }
.mail-body { white-space: pre-wrap; overflow-wrap: anywhere; border-top: 1px solid var(--border); padding: 12px 0; }
.mail-attach h2, .mail-attach h4, .mail-view > h2 { font-size: 1rem; }
.journal .mail-attach { margin: 6px 0; }
.mail-attach ul { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.mail-attach li { border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px; font-size: 0.9rem; }
.mail-thread { padding-left: 1.4em; font-size: 0.95rem; }
.mail-thread [aria-current] { font-weight: 600; }
.app-shell.mail .app-main { padding-bottom: 8px; }

/* ボタン（控えめ） */
button.secondary {
  color: var(--link); background: transparent; border: 1px solid currentColor;
}
.sitenav .memo-open {
  font: inherit; font-size: 0.95rem; padding: 2px 12px; border-radius: 999px;
  color: var(--link); background: transparent; border: 1px solid currentColor;
}

/* メモに追加 */
button.memo-add {
  font-size: 0.8rem; padding: 1px 10px; margin-top: 4px; border-radius: 999px;
  color: var(--muted); background: transparent; border: 1px solid var(--border);
}
button.memo-add:hover { color: var(--link); border-color: currentColor; }
.line-memo { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin: 0 0 8px; font-size: 0.9rem; }
.line-memo label { font-weight: 600; }
.line-memo input {
  font: inherit; width: 6em; padding: 4px 6px;
  color: var(--fg); background: var(--bg); border: 1px solid var(--muted); border-radius: 4px;
}
.line-memo button { padding: 4px 12px; font-size: 0.9rem; }
.line-memo .help { margin: 0; }
.source.memo-ready .ln { cursor: pointer; }
.source.memo-ready .ln:hover { color: var(--link); text-decoration: underline; }

/* メモ帳ダイアログ */
.memo-dialog {
  width: min(40rem, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  color: var(--fg); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 16px;
}
.memo-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.memo-dialog h2 { margin-top: 0; }
.memo-dialog textarea {
  width: 100%; font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, "BIZ UDGothic", monospace;
  font-size: 0.9rem; line-height: 1.6; padding: 8px;
  color: var(--fg); background: var(--code-bg); border: 1px solid var(--muted); border-radius: 4px;
}
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 8px; }

/* 通知 */
.toast {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%);
  max-width: calc(100vw - 32px); padding: 8px 16px; border-radius: 6px;
  background: var(--fg); color: var(--bg); font-size: 0.9rem;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.toast.show { opacity: 1; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* 移動先の強調 */
tr:target > *, .journal-item:target, .post h2:target { background: var(--target); }

/* 検索 */
.results { padding-left: 1.6em; }
.results li { margin: 0 0 12px; }
.results a { font-weight: 600; overflow-wrap: anywhere; }
.snippet { margin: 2px 0 0; font-size: 0.9rem; color: var(--muted); overflow-wrap: anywhere; }
mark { background: var(--target); color: var(--fg); padding: 0 1px; }

/* ヒント */
.hint { border: 1px solid var(--border); border-radius: 6px; padding: 4px 12px; margin: 8px 0; }
.hint summary { cursor: pointer; font-weight: 600; }
.hint[open] summary { margin-bottom: 4px; }

/* Markdown のプレビューと Raw の切り替え */
.view-switch { display: flex; flex-wrap: wrap; gap: 0; margin: 12px 0 4px; }
.view-switch button {
  border-radius: 0; background: var(--bg); color: var(--fg); border: 1px solid var(--border);
  padding: 4px 14px; font-size: 0.95rem;
}
.view-switch button:first-child { border-radius: 6px 0 0 6px; }
.view-switch button:last-child { border-radius: 0 6px 6px 0; border-left: none; }
.view-switch button[aria-pressed="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); font-weight: 600; }
.md-preview { border: 1px solid var(--border); border-radius: 6px; padding: 4px 20px 12px; }
.md-preview h3 { font-size: 1.35rem; }
.md-preview h4 { font-size: 1.1rem; }
.md-preview code { background: var(--code-bg); padding: 0 4px; border-radius: 3px; }
.md-preview .md-code { background: var(--code-bg); padding: 10px 12px; overflow-x: auto; line-height: 1.4; }

/* 用語集 */
.glossary dt { font-weight: 700; font-size: 1.05rem; margin-top: 1.2em; padding-top: 0.6em; border-top: 1px solid var(--border); }
.glossary dd { margin: 0.3em 0 0; }
.glossary dd p { margin: 0.4em 0; }

/* 入口ページの副題（狭い画面では主題の下に回る） */
h1 .subtitle { display: inline-block; font-size: 1rem; font-weight: 600; color: var(--muted); }

/* 物語の中の抜粋（エンディングのチャット・資料） */
.story-chat, .story-doc { border: 1px solid var(--border); border-radius: 6px; padding: 0 16px 12px; margin: 16px 0; }
.story-chat-head, .story-doc > h2 { font-size: 1.05rem; margin: 0.8em 0 0.4em; }
.story-chat .msg { padding-left: 0; padding-right: 0; }
.story-doc .md-preview { border: 0; padding: 0; margin: 0; }
/* ログの表のページは列が多いので、本文を画面の幅いっぱいまで広げる */
main:has(.log-table) { max-width: none; }

/* おまけ（その後の #random）：チャンネル一覧のない1列のチャット */
.app-shell.solo { grid-template-columns: 1fr; }
.chat-archived { margin: 12px 16px 0; color: var(--muted); font-size: 0.875rem; text-align: center; }
