:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --warn: #d97706;
  --success-bg: #ecfdf5;
  --success-text: #065f46;
  --error-bg: #fef2f2;
  --error-text: #991b1b;
  --radius: 8px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 860px; margin: 0 auto; padding: 0 16px; }

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 56px; gap: 12px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px;
}
.brand { font-size: 1.2rem; font-weight: 700; color: var(--text); }
.brand:hover { text-decoration: none; }
.nav { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.username { color: var(--muted); }

main.container { padding-top: 24px; padding-bottom: 48px; }

.btn {
  display: inline-block; padding: 6px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  cursor: pointer; font-size: 0.95rem; line-height: 1.6;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-warn { color: var(--warn); border-color: var(--warn); }
.btn-block { width: 100%; }
.link-btn {
  background: none; border: none; color: var(--primary);
  cursor: pointer; padding: 0; font-size: inherit; font-family: inherit;
}
.link-btn:hover { text-decoration: underline; }
.inline-form { display: inline; }

.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; }
.flash-success { background: var(--success-bg); color: var(--success-text); }
.flash-error { background: var(--error-bg); color: var(--error-text); }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head h1 { margin: 0 0 8px; font-size: 1.4rem; }
.search-form { display: flex; gap: 8px; }
.search-form input[type="search"] {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius); min-width: 200px;
}

.tag-cloud { margin: 12px 0 20px; display: flex; flex-wrap: wrap; gap: 8px; }
.tag-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 2px 12px; font-size: 0.88rem; color: var(--text);
}
.tag-chip:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.tag-chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.tag-chip.small { padding: 0 10px; font-size: 0.8rem; }
.tag-chip.tag-clear { border-style: dashed; color: var(--muted); }
.tag-count { color: var(--muted); font-size: 0.8em; }
.tag-chip.active .tag-count { color: #dbeafe; }

.idea-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.idea-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; display: flex; align-items: center; gap: 14px;
}
.idea-card.is-hidden { opacity: 0.55; }
.idea-main { flex: 1; min-width: 0; }
.idea-title { font-weight: 600; font-size: 1.05rem; }
.idea-meta { color: var(--muted); font-size: 0.85rem; display: flex; gap: 12px; flex-wrap: wrap; margin-top: 2px; }
.idea-tags { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.idea-replies {
  flex-shrink: 0; min-width: 44px; text-align: center;
  background: var(--bg); border-radius: var(--radius);
  padding: 8px 6px; font-weight: 700; color: var(--muted);
}
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

.badge {
  background: var(--border); border-radius: 4px; padding: 0 6px; font-size: 0.78rem;
}
.badge-danger { background: var(--error-bg); color: var(--error-text); }
.badge-new { background: var(--primary); color: #fff; font-weight: 700; }
/* ヘッダーの件数バッジ (新着・未対応の通報) */
.nav-count {
  display: inline-block; min-width: 18px; padding: 0 5px;
  background: var(--danger); color: #fff; border-radius: 999px;
  font-size: 0.72rem; font-weight: 700; text-align: center; margin-left: 3px;
}

.pagination { display: flex; justify-content: center; gap: 16px; margin-top: 20px; color: var(--muted); }

.auth-box, .form-page {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; max-width: 480px; margin: 0 auto;
}
.form-page { max-width: 720px; }
.auth-box h1, .form-page h1 { margin-top: 0; font-size: 1.3rem; }
label { display: block; margin-bottom: 14px; font-size: 0.92rem; color: var(--muted); }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], textarea {
  display: block; width: 100%; margin-top: 4px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 1rem; font-family: inherit; color: var(--text); background: #fff;
}
textarea { resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.auth-alt { font-size: 0.9rem; margin-top: 14px; }
.note { color: var(--muted); font-size: 0.9rem; }

/* ハニーポット: botには見えるがユーザーには見えない */
.hp-field { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.idea-detail {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 24px;
}
.idea-detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.idea-detail-head h1 { margin: 0; font-size: 1.4rem; }
/* ボタンが増えたので折り返す。狭い画面では横に並びきらず、
   ページ全体が横スクロールしてしまうため。 */
.idea-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.md-body { margin-top: 12px; overflow-wrap: break-word; }
.md-body pre {
  background: #f3f4f6; padding: 12px; border-radius: var(--radius); overflow-x: auto;
}
.md-body code { background: #f3f4f6; padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }
.md-body pre code { padding: 0; }
.md-body blockquote {
  margin: 8px 0; padding: 4px 14px; border-left: 3px solid var(--border); color: var(--muted);
}
.md-body img { max-width: 100%; }

.report-box { margin-top: 14px; font-size: 0.85rem; color: var(--muted); }
.report-box summary { cursor: pointer; }
.report-box form { display: flex; gap: 8px; margin-top: 6px; align-items: center; }
.report-box input[type="text"] { margin: 0; flex: 1; }
.report-box.small { display: inline-block; margin: 0; }

/* --- アバター (画像は使わず絵文字と背景色で表す) --- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; color: #fff; flex-shrink: 0;
  line-height: 1; user-select: none;
}
.avatar-xs { width: 16px; height: 16px; font-size: 9px; }
.avatar-sm { width: 22px; height: 22px; font-size: 12px; }
.avatar-md { width: 28px; height: 28px; font-size: 15px; }
.avatar-lg { width: 56px; height: 56px; font-size: 30px; }
.avatar-with-name { display: inline-flex; align-items: center; gap: 6px; }

.settings-preview {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 20px;
}
.settings-preview-label { font-size: 0.82rem; color: var(--muted); }

.picker { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 18px; }
.picker legend { font-size: 0.9rem; color: var(--muted); padding: 0 4px; }
.picker .note { margin: 0 0 8px; }
.picker-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.picker-item { margin: 0; cursor: pointer; }
.picker-item input { position: absolute; opacity: 0; width: 0; height: 0; }
.picker-item > span {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 38px; height: 38px; font-size: 20px;
  border: 2px solid transparent; border-radius: var(--radius);
  background: var(--surface);
}
.picker-item:hover > span { background: var(--bg); }
.picker-item input:checked + span { border-color: var(--primary); background: #eff6ff; }
.picker-item input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
.picker-none > span { font-size: 0.78rem; color: var(--muted); padding: 0 8px; }
.picker-color { display: block; width: 26px; height: 26px; border-radius: 50%; }

/* 設定画面の「自分が立ち上げたアイディア」 */
.my-ideas { margin-top: 20px; }
.my-ideas h2 { font-size: 1.05rem; margin-top: 0; }
.my-idea-list { list-style: none; margin: 0; padding: 0; }
.my-idea-list li {
  padding: 8px 0; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap;
}
.my-idea-list li:last-child { border-bottom: none; }
.my-idea-list li.is-hidden { opacity: 0.6; }
.my-idea-meta { color: var(--muted); font-size: 0.82rem; flex-shrink: 0; }

/* --- 使い方のヘルプ --- */
.help-page { display: flex; flex-direction: column; gap: 24px; }
.help-lead { color: var(--muted); margin-top: 4px; }
.help-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 22px;
}
.help-card > h2 {
  margin-top: 0; font-size: 1.2rem;
  border-bottom: 2px solid var(--primary); padding-bottom: 8px;
}
.help-card h3 { font-size: 1rem; margin: 18px 0 6px; }
.help-card ul, .help-card ol { padding-left: 20px; line-height: 1.8; margin: 6px 0; }
.help-card p { margin: 6px 0; }
.help-note { color: var(--muted); font-size: 0.85rem; }

/* 操作ボタンの説明を、実物と同じ見た目で示す */
.help-key {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; padding: 1px 6px; margin: 0 2px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 4px;
  font-size: 0.85em; font-weight: 700;
}
.help-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 0.9rem; }
.help-table th, .help-table td {
  border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top;
}
.help-table th { background: var(--bg); white-space: nowrap; }
.help-table code { white-space: pre-wrap; }
.help-swatch {
  display: inline-block; width: 14px; height: 14px; border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.15); vertical-align: -2px; margin-right: 5px;
}
.help-scroll { overflow-x: auto; }

/* --- 折りたたみ --- */
.fold { margin-top: 28px; }
.fold-summary {
  display: flex; align-items: center; gap: 10px;
  cursor: pointer; list-style: none; padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.fold-summary::-webkit-details-marker { display: none; }
/* 開閉の向きを三角で示す */
.fold-summary::before {
  content: ''; flex-shrink: 0;
  border-left: 6px solid var(--muted);
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  transition: transform 0.15s;
}
.fold[open] > .fold-summary::before { transform: rotate(90deg); }
.fold-summary:hover { background: var(--surface); }
.fold-summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.fold-title { font-size: 1.1rem; font-weight: 700; }
.fold-hint { font-size: 0.78rem; color: var(--muted); margin-left: auto; }

/* 長い返信の途中切り */
.md-body.is-clamped {
  max-height: 320px; overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, #000 70%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 70%, transparent 100%);
}
.clamp-toggle { margin-top: 4px; font-size: 0.85rem; }

/* 返信の編集フォームとその場での削除確認 */
.post-edit-form { margin-top: 10px; }
.post-edit-form textarea { margin-bottom: 8px; }
.inline-confirm {
  display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap;
  margin-left: 8px; font-size: 0.85rem; color: var(--warn);
}
.link-btn.is-danger { color: var(--danger); font-weight: 700; }
.post-hidden { opacity: 0.7; }

/* アンカーで飛んできた投稿を一瞬目立たせる */
.is-highlighted { animation: flash 2s ease-out; }
@keyframes flash {
  from { background: #fef9c3; }
  to   { background: transparent; }
}

/* --- 付箋ボード --- */
.board-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 10px; }
.board-head h2 { font-size: 1.1rem; margin: 0; }
.board-status { font-size: 0.85rem; color: var(--muted); }
.board-status.is-error { color: var(--danger); }

.board {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  margin-top: 8px;
}
/* 高さは画面に追随させる。固定だと大きな画面でも小窓のままになり、
   余白があるのにスクロールを強いられる。 */
.board-scroll {
  overflow: auto; border-radius: var(--radius);
  height: clamp(360px, 62vh, 900px);
}
.board-canvas {
  position: relative; min-width: 100%; min-height: 100%;
  background-image: radial-gradient(circle, var(--border) 1px, transparent 1px);
  background-size: 24px 24px;
}

/* 画面が広いときは、本文用の列幅を越えてボードだけ横に広げる。
   ボードは文章と違って、幅があるほど見通しが良くなるため。 */
@media (min-width: 1000px) {
  .board-section {
    width: min(94vw, 1500px);
    margin-left: calc(50% - min(47vw, 750px));
  }
}

/* 「広げる」で画面いっぱいに使う */
.board.is-expanded {
  position: fixed; inset: 0; z-index: 200; margin: 0;
  border-radius: 0; display: flex; flex-direction: column;
}
.board.is-expanded .board-scroll { height: 100%; flex: 1; border-radius: 0; }
body.board-expanded { overflow: hidden; }
.board-expand-hint {
  position: fixed; top: 8px; right: 12px; z-index: 201;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 4px 10px; font-size: 0.82rem; color: var(--muted);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.board-lines { position: absolute; inset: 0; pointer-events: none; }
.board-lines .board-line { stroke: #94a3b8; stroke-width: 2; pointer-events: stroke; }
.board-lines .board-line:hover { stroke: var(--danger); stroke-width: 3; }
.board-lines .board-line-label { font-size: 11px; fill: var(--muted); }

.sticky {
  position: absolute; width: 180px; min-height: 110px;
  border-radius: 4px; padding: 8px 10px 22px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
  font-size: 0.88rem; line-height: 1.5;
  display: flex; flex-direction: column;
  overflow: hidden; word-break: break-word;
}
/* タッチ端末でドラッグがページスクロールに奪われないようにする。
   これが無いと指で付箋を動かせず、画面ごとスクロールしてしまう。 */
.can-edit .sticky { cursor: grab; touch-action: none; }
/* 入力欄の中では通常のタッチ操作(選択・スクロール)に戻す */
.sticky-form, .sticky-input, .sticky-reason, .confirm-pop, .palette { touch-action: auto; }
.sticky.is-dragging { cursor: grabbing; box-shadow: 0 6px 16px rgba(0, 0, 0, 0.28); z-index: 10; }
.sticky.is-link-source { outline: 3px solid var(--primary); outline-offset: 1px; }
.sticky-body { flex: 1; white-space: pre-wrap; }
.sticky-meta {
  position: absolute; left: 10px; bottom: 4px;
  font-size: 0.7rem; color: rgba(0, 0, 0, 0.45);
}
/* ツールは常に置いておく。以前は hover でのみ表示していたが、
   タッチ端末ではホバーが無く操作不能になるため。 */
.sticky-tools {
  position: absolute; top: 2px; right: 2px;
  display: flex; gap: 1px;
  opacity: 0.4; transition: opacity 0.15s;
}
.sticky:hover .sticky-tools,
.sticky:focus-within .sticky-tools { opacity: 1; }
/* ホバーできない端末では常にはっきり見せる */
@media (hover: none) {
  .sticky-tools { opacity: 1; }
}
.sticky-tools button {
  border: none; background: rgba(255, 255, 255, 0.85); cursor: pointer;
  font-size: 0.7rem; padding: 1px 4px; border-radius: 3px; line-height: 1.4;
  color: var(--text);
}
.sticky-tools button:hover { background: #fff; }
.sticky-tools button:focus-visible { outline: 2px solid var(--primary); }
/* 履歴があることを件数で示す */
.sticky-tools .has-history { background: rgba(37, 99, 235, 0.14); font-weight: 700; }

.sticky.is-deleted { opacity: 0.45; filter: grayscale(0.6); }
/* 実装対象の印。指示書に載る付箋が一目で分かるようにする */
.sticky.is-target { box-shadow: 0 0 0 3px var(--primary), 0 2px 6px rgba(0, 0, 0, 0.18); }
.sticky-tools button.is-on { background: var(--primary); color: #fff; font-weight: 700; }

/* 実装結果の記録 */
.impl-record {
  background: var(--success-bg); color: var(--success-text);
  border-radius: var(--radius); padding: 8px 12px; font-size: 0.88rem;
  margin-top: 12px; word-break: break-all;
}
.impl-form { margin-top: 12px; font-size: 0.88rem; }
.impl-form summary { cursor: pointer; color: var(--muted); }
.impl-form form { margin-top: 8px; }

/* 色の意味を示す凡例 */
.board-legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 8px 0 4px; font-size: 0.82rem; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-swatch {
  display: inline-block; width: 13px; height: 13px; border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.12);
}

/* 付箋内のインライン編集フォーム (prompt の置き換え) */
.sticky.is-editing { z-index: 30; width: 240px; min-height: 0; padding-bottom: 8px; }
.sticky-form { display: flex; flex-direction: column; gap: 6px; }
.sticky-input {
  width: 100%; margin: 0; font-size: 0.85rem; line-height: 1.5;
  border: 1px solid rgba(0, 0, 0, 0.18); border-radius: 4px; padding: 6px;
  resize: vertical; min-height: 68px; background: rgba(255, 255, 255, 0.9);
}
.sticky-reason {
  width: 100%; margin: 0; font-size: 0.8rem;
  border: 1px solid var(--warn); border-radius: 4px; padding: 5px 6px;
  background: rgba(255, 255, 255, 0.9);
}
.sticky-error { margin: 0; font-size: 0.78rem; color: var(--danger); }
.sticky-error:empty { display: none; }
.sticky-form-row { display: flex; gap: 6px; }
.sticky-form-row .btn { padding: 3px 10px; font-size: 0.82rem; }

/* 削除などの確認 */
.confirm-pop {
  position: absolute; top: 4px; left: 4px; right: 4px; z-index: 40;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
  padding: 10px; display: flex; flex-direction: column; gap: 6px;
}
/* 線の削除確認はボード上の任意の位置に置く */
.confirm-pop.is-floating { right: auto; width: 240px; transform: translate(-50%, -50%); }
.confirm-message { margin: 0; font-size: 0.82rem; }

/* 色の選択パレット */
.palette {
  position: absolute; top: 22px; right: 2px; z-index: 20;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  padding: 4px; display: flex; flex-direction: column; gap: 2px; min-width: 130px;
}
.palette .sticky-reason { margin-bottom: 2px; }
.palette-swatch {
  border: 1px solid rgba(0, 0, 0, 0.12); border-radius: 3px; cursor: pointer;
  font-size: 0.75rem; padding: 3px 6px; text-align: left; color: var(--text);
}
.palette-swatch.is-current { outline: 2px solid var(--primary); outline-offset: -1px; }

/* 履歴パネル */
.board-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 18px; margin: 10px 0;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-head h3 { margin: 0; font-size: 1rem; }
.panel-quote {
  background: var(--bg); border-left: 3px solid var(--border);
  padding: 6px 10px; margin: 8px 0; font-size: 0.88rem; white-space: pre-wrap;
}
.history { margin: 0; padding-left: 1.3em; font-size: 0.86rem; }
.history li { margin-bottom: 8px; }
.history-head { color: var(--text); }
.history-reason { color: var(--warn); }
.history-diff { color: var(--muted); word-break: break-word; }

.sticky-yellow { background: #fef9c3; }
.sticky-blue   { background: #dbeafe; }
.sticky-green  { background: #dcfce7; }
.sticky-pink   { background: #fce7f3; }
.sticky-gray   { background: #e5e7eb; }

.posts { margin-top: 28px; }
.posts h2 { font-size: 1.1rem; }
.post {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 18px; margin-bottom: 10px;
}
.post.is-hidden { opacity: 0.55; }
.post-meta { display: flex; gap: 12px; align-items: center; font-size: 0.88rem; color: var(--muted); flex-wrap: wrap; }
.post-meta strong { color: var(--text); }
.post-actions { margin-left: auto; display: flex; gap: 10px; align-items: center; }
.post .md-body { margin-top: 8px; }

.reply-form { margin-top: 24px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.reply-form h3 { margin-top: 0; font-size: 1rem; }
.reply-form textarea { margin-bottom: 10px; }

.admin-table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: 0.88rem; }
.admin-table th, .admin-table td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
.admin-table th { background: var(--bg); }
.admin-table .preview { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-table .actions { white-space: nowrap; }
.admin-table .actions form { margin-right: 4px; }

.site-footer {
  border-top: 1px solid var(--border); color: var(--muted);
  font-size: 0.85rem; padding: 16px 0; margin-top: 24px;
}
