/*
 * Web Security Patterns スタイル
 *
 * ダークトーン基調。アクセントは琥珀（--accent）を面・下線・バッジで使う。
 * カード左辺の色ボーダーは使わない方針。
 * 文字色はすべて背景に対しコントラスト比4.5:1以上（AA）を確保している。
 */
:root {
  --bg: #10151b;
  --bg-deep: #0b0f14;
  --surface: #171e26;
  --surface-2: #1d2631;
  --border: #2a3542;
  --border-strong: #405062;
  --text: #dde5ed;
  --text-sub: #9fb0c0;
  --accent: #e2a93b;
  --accent-strong: #f0bc5e;
  --on-accent: #1c1305;
  --danger-text: #ffb4a8;
  --danger-bg: rgba(224, 108, 94, 0.14);
  --danger-border: rgba(224, 108, 94, 0.45);
  --ok-text: #96dbb7;
  --ok-bg: rgba(88, 185, 138, 0.14);
  --ok-border: rgba(88, 185, 138, 0.45);
  --link: #85bce9;
  --mono: "SF Mono", "Menlo", "Consolas", "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic",
    "Noto Sans JP", sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.8;
}

a { color: var(--link); }
a:focus-visible,
button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

#app {
  display: flex;
  height: 100vh;
}

/* ---- サイドバー ---- */
#sidebar {
  width: 312px;
  flex-shrink: 0;
  background: var(--bg-deep);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

#sidebar-header {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
}

#site-kicker {
  margin: 0 0 2px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--accent);
}

#sidebar-header h1 {
  margin: 0 0 12px;
  font-size: 19px;
  line-height: 1.35;
}

#site-title-link {
  color: var(--text);
  text-decoration: none;
}
#site-title-link:hover { color: var(--accent-strong); }

#progress-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

#progress-bar {
  flex: 1;
  height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
}

#progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.3s;
}

#progress-label {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-sub);
  white-space: nowrap;
}

/* 検索欄 */
#toc-search-wrap {
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
}

#toc-search {
  width: 100%;
  padding: 7px 10px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}
#toc-search::placeholder { color: var(--text-sub); }
#toc-search:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.toc-empty {
  padding: 10px 18px;
  margin: 0;
  font-size: 12.5px;
  color: var(--text-sub);
}

#toc {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0 16px;
}

.toc-page {
  display: block;
  padding: 8px 18px;
  font-size: 13.5px;
  color: var(--text);
  text-decoration: none;
}
.toc-page:hover { background: var(--surface); }
.toc-page.active {
  background: var(--surface-2);
  color: var(--accent-strong);
}

.toc-cat { margin-top: 6px; }

.toc-cat summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 18px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-sub);
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.toc-cat summary::-webkit-details-marker { display: none; }
.toc-cat summary::before {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--text-sub);
  border-bottom: 1.5px solid var(--text-sub);
  transform: rotate(-45deg);
  transition: transform 0.15s;
  flex-shrink: 0;
}
.toc-cat[open] summary::before { transform: rotate(45deg); }
.toc-cat summary:hover { color: var(--text); }

.toc-cat-count {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-sub);
  background: var(--surface-2);
  border-radius: 9px;
  padding: 0 8px;
}

.toc-cat ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.toc-topic {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 18px 6px 28px;
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
  line-height: 1.5;
}
.toc-topic:hover { background: var(--surface); }
.toc-topic.active {
  background: var(--surface-2);
  color: var(--accent-strong);
}
.toc-topic.done .toc-title-text { color: var(--text-sub); }
.toc-topic.active .toc-title-text { color: inherit; }

.toc-no {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-sub);
  flex-shrink: 0;
}
.toc-topic.active .toc-no { color: var(--accent-strong); }

.toc-done-badge {
  margin-left: auto;
  flex-shrink: 0;
  font-size: 10.5px;
  color: var(--ok-text);
  background: var(--ok-bg);
  border: 1px solid var(--ok-border);
  border-radius: 3px;
  padding: 0 5px;
  line-height: 1.6;
}

#sidebar-footer {
  padding: 10px 18px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-sub);
}

/* ---- メイン ---- */
#main {
  flex: 1;
  overflow-y: auto;
  padding: 32px 40px 64px;
}

#topic-view, #page-view {
  max-width: 900px;
  margin: 0 auto;
}

h2 {
  margin: 6px 0 10px;
  font-size: 27px;
  line-height: 1.4;
  letter-spacing: 0.01em;
}
h2:focus { outline: none; }

.topic-lead {
  margin: 0 0 28px;
  color: var(--text-sub);
  font-size: 15px;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  font-size: 12.5px;
  color: var(--text-sub);
}

.cat-badge {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent-strong);
  background: rgba(226, 169, 59, 0.12);
  border: 1px solid rgba(226, 169, 59, 0.4);
  border-radius: 3px;
  padding: 1px 8px;
  line-height: 1.7;
}

.breadcrumb-pos { font-family: var(--mono); font-size: 11.5px; }

/* ---- セクション ---- */
.sec { margin: 36px 0; }

.sec-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  border-bottom: 2px solid var(--border-strong);
  padding-bottom: 6px;
  margin-bottom: 16px;
}

.sec-no {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--accent);
}

.sec-head h3 {
  margin: 0;
  font-size: 18px;
  line-height: 1.5;
}

.sec-body { font-size: 14.5px; }
.sec-body p { margin: 0 0 14px; }
.sec-body code {
  font-family: var(--mono);
  font-size: 0.92em;
  background: var(--surface-2);
  border-radius: 4px;
  padding: 1px 5px;
}
.sec-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 16px;
  font-size: 13.5px;
}
.sec-body th, .sec-body td {
  border: 1px solid var(--border);
  padding: 7px 10px;
  text-align: left;
  vertical-align: top;
}
.sec-body th { background: var(--surface); font-weight: 600; }

/* ---- 攻撃の仕組み ---- */
.attack-scenario { margin-bottom: 16px; }

.attack-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: none;
}

.attack-step {
  display: flex;
  gap: 14px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.attack-step + .attack-step { border-top: none; }
.attack-step:first-child { border-radius: 8px 8px 0 0; }
.attack-step:last-child { border-radius: 0 0 8px 8px; }
.attack-step:only-child { border-radius: 8px; }

.step-no {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--on-accent);
  background: var(--accent);
  border-radius: 4px;
  margin-top: 2px;
}

.step-title {
  display: block;
  font-weight: 600;
  margin-bottom: 2px;
}

.step-detail { color: var(--text-sub); font-size: 13.5px; }
.step-detail p { margin: 0 0 6px; }
.step-detail code { background: var(--bg-deep); }

.attack-note {
  margin-top: 16px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
}
.attack-note-label {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent-strong);
  margin-right: 8px;
}
.attack-note p:last-child { margin-bottom: 0; }

/* ---- コード比較 ---- */
.compare-block { margin-bottom: 28px; }
.compare-block:last-child { margin-bottom: 0; }

.compare-title {
  margin: 0 0 8px;
  font-size: 15.5px;
}

.compare-desc {
  margin-bottom: 10px;
  font-size: 13.5px;
  color: var(--text-sub);
}

.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  align-items: start;
}

.code-pane {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-deep);
}

.pane-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.pane-badge {
  font-size: 11px;
  font-weight: 700;
  border-radius: 3px;
  padding: 1px 7px;
  line-height: 1.7;
}
.badge-vuln {
  color: var(--danger-text);
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
}
.badge-fixed {
  color: var(--ok-text);
  background: var(--ok-bg);
  border: 1px solid var(--ok-border);
}

.pane-label { font-size: 12.5px; font-weight: 600; }

.pane-lang {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-sub);
}

.code-scroll { overflow-x: auto; }

.code-block {
  margin: 0;
  padding: 10px 0;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.65;
  min-width: max-content;
}

.ln { display: flex; }

.ln-no {
  flex-shrink: 0;
  width: 40px;
  padding-right: 12px;
  text-align: right;
  color: #5d6b7a;
  user-select: none;
}

.ln-code {
  white-space: pre;
  padding-right: 16px;
  color: #cfd8e2;
}

.ln-hl-vuln { background: var(--danger-bg); }
.ln-hl-vuln .ln-no { color: var(--danger-text); font-weight: 700; }
.ln-hl-fixed { background: var(--ok-bg); }
.ln-hl-fixed .ln-no { color: var(--ok-text); font-weight: 700; }

.pane-note {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  color: var(--text-sub);
}
.pane-note p { margin: 0 0 6px; }
.pane-note p:last-child { margin-bottom: 0; }
.pane-note code { background: var(--bg-deep); }

.pane-note-label {
  display: block;
  font-size: 11.5px;
  font-weight: 700;
  margin-bottom: 2px;
}
.pane-vuln .pane-note-label { color: var(--danger-text); }
.pane-fixed .pane-note-label { color: var(--ok-text); }

/* ---- クイズ ---- */
.quiz-score {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--text-sub);
}

.quiz-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.quiz-q {
  margin: 0 0 12px;
  font-weight: 600;
  font-size: 14.5px;
}

.quiz-qno {
  display: inline-block;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent-strong);
  margin-right: 10px;
}

.quiz-choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quiz-choice {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 12px;
  cursor: pointer;
}
.quiz-choice:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--bg-deep);
}
.quiz-choice:disabled { cursor: default; opacity: 0.9; }

.choice-key {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-sub);
  flex-shrink: 0;
}

.quiz-choice.is-answer {
  border-color: var(--ok-border);
  background: var(--ok-bg);
}
.quiz-choice.is-answer .choice-key { color: var(--ok-text); }
.quiz-choice.is-wrong {
  border-color: var(--danger-border);
  background: var(--danger-bg);
}
.quiz-choice.is-wrong .choice-key { color: var(--danger-text); }

.feedback-box {
  margin-top: 12px;
  border-radius: 6px;
  padding: 12px 14px;
  font-size: 13.5px;
}
.feedback-box:focus { outline: none; }
.feedback-ok { background: var(--ok-bg); border: 1px solid var(--ok-border); }
.feedback-ng { background: var(--danger-bg); border: 1px solid var(--danger-border); }

.feedback-verdict {
  margin: 0 0 6px;
  font-weight: 700;
}
.feedback-ok .feedback-verdict { color: var(--ok-text); }
.feedback-ng .feedback-verdict { color: var(--danger-text); }

.feedback-explain p { margin: 0 0 8px; }
.feedback-explain p:last-child { margin-bottom: 0; }

.quiz-retry {
  margin-top: 10px;
  font-family: inherit;
  font-size: 12.5px;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  padding: 4px 12px;
  cursor: pointer;
}
.quiz-retry:hover { border-color: var(--accent); color: var(--accent-strong); }

/* ---- チェックリスト ---- */
.checklist {
  list-style: none;
  margin: 0;
  padding: 0;
}

.checklist li {
  position: relative;
  padding: 9px 12px 9px 38px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13.5px;
}
.checklist li + li { border-top: none; }
.checklist li:first-child { border-radius: 8px 8px 0 0; }
.checklist li:last-child { border-radius: 0 0 8px 8px; }
.checklist li:only-child { border-radius: 8px; }

.checklist li::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 14px;
  width: 12px;
  height: 12px;
  border: 1.5px solid var(--accent);
  border-radius: 3px;
}

/* ---- 参考資料 ---- */
.ref-list {
  margin: 0;
  padding-left: 22px;
  font-size: 13.5px;
}
.ref-list li { margin-bottom: 6px; }
.ref-note { color: var(--text-sub); }

/* ---- トピック移動 ---- */
#topic-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 48px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

button {
  font-family: inherit;
}

#topic-nav button, .intro-actions button {
  font-size: 14px;
  padding: 9px 20px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
#topic-nav button:hover:not(:disabled),
.intro-actions button:hover { border-color: var(--accent); }
#topic-nav button:disabled { opacity: 0.4; cursor: default; }

#topic-nav button.primary, .intro-actions button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
}
#topic-nav button.primary:hover:not(:disabled),
.intro-actions button.primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

#done-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  color: var(--text-sub);
  cursor: pointer;
  user-select: none;
}
#done-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ---- ホーム（トピック一覧） ---- */
.home-kicker {
  margin: 0 0 2px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.home-lead {
  margin: 0 0 8px;
  max-width: 720px;
  color: var(--text-sub);
  font-size: 14.5px;
}

.home-intro-link { font-size: 13.5px; margin: 0 0 12px; }

.home-cat { margin-top: 36px; }

.home-cat-head {
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
  border-bottom: 2px solid var(--border-strong);
  padding-bottom: 6px;
  margin-bottom: 16px;
}
.home-cat-head h3 { margin: 0; font-size: 18px; }
.home-cat-desc {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-sub);
}

.topic-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.topic-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  color: var(--text);
  text-decoration: none;
}
.topic-card:hover {
  border-color: var(--accent);
  background: var(--surface-2);
}

.card-no {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
}

.card-title { font-weight: 600; font-size: 14.5px; line-height: 1.5; }
.card-summary { font-size: 12.5px; color: var(--text-sub); }

.card-done {
  align-self: flex-start;
  margin-top: 6px;
  font-size: 11px;
  color: var(--ok-text);
  background: var(--ok-bg);
  border: 1px solid var(--ok-border);
  border-radius: 3px;
  padding: 0 7px;
  line-height: 1.7;
}

.home-cat-empty { font-size: 13px; color: var(--text-sub); }

/* ---- はじめにページ ---- */
.intro-page { font-size: 14.5px; }
.intro-page h3 {
  margin: 32px 0 12px;
  font-size: 18px;
  border-bottom: 2px solid var(--border-strong);
  padding-bottom: 6px;
}
.intro-page h4 { margin: 20px 0 8px; font-size: 15px; }
.intro-page p { margin: 0 0 14px; }
.intro-page table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 16px;
  font-size: 13.5px;
}
.intro-page th, .intro-page td {
  border: 1px solid var(--border);
  padding: 7px 10px;
  text-align: left;
  vertical-align: top;
}
.intro-page th { background: var(--surface); font-weight: 600; }
.intro-page code {
  font-family: var(--mono);
  font-size: 0.92em;
  background: var(--surface-2);
  border-radius: 4px;
  padding: 1px 5px;
}
.intro-page ul { padding-left: 22px; }
.intro-page li { margin-bottom: 4px; }

.intro-actions { margin-top: 28px; }

/* ---- レスポンシブ ---- */
@media (max-width: 900px) {
  #app {
    flex-direction: column;
    height: auto;
  }
  #sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  #toc { max-height: 40vh; }
  #main {
    padding: 20px 16px 48px;
    overflow-y: visible;
  }
  .compare-grid { grid-template-columns: 1fr; }
  h2 { font-size: 22px; }
  #topic-nav { flex-wrap: wrap; }
}
