/* ==========================================================================
   Editorial layout for the two template-derived CYS401 breakdowns
   (chapters 1 and 2). Restyles the existing class names — no markup churn.
   Per-page hue comes from --ch-h / --ch-h2 set inline on :root.
   Light and dark are both first-class here; nothing is derived.
   ========================================================================== */

:root {
  --ch-h: 212;
  /* chapter hue, overridden per page */
  --ch-h2: 190;
  /* secondary hue */

  --ink: #16202e;
  --ink-2: #4a5a70;
  --ink-3: #7b8a9e;
  --paper: #f2f5f9;
  --card: #ffffff;
  --card-2: #f7f9fc;
  --line: #dde5ef;
  --line-2: #eaf0f7;

  --accent: hsl(var(--ch-h) 72% 40%);
  --accent-2: hsl(var(--ch-h2) 70% 36%);
  --accent-ink: hsl(var(--ch-h) 78% 30%);
  --accent-wash: hsl(var(--ch-h) 72% 40% / 0.07);
  --accent-line: hsl(var(--ch-h) 72% 40% / 0.28);

  --ok: #0f7a52;
  --ok-wash: #0f7a5214;
  --warn: #9a6407;
  --warn-wash: #9a640714;
  --bad: #b3243f;
  --bad-wash: #b3243f14;

  --shadow:
    0 1px 2px hsl(var(--ch-h) 30% 20% / 0.05),
    0 12px 32px hsl(var(--ch-h) 30% 20% / 0.07);
  --r: 16px;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --serif: "Fraunces", "Iowan Old Style", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

html[data-theme="dark"] {
  --ink: #e7edf7;
  --ink-2: #9fb0c6;
  --ink-3: #71829a;
  --paper: #070b12;
  --card: #101825;
  --card-2: #0c131e;
  --line: #1f2c3f;
  --line-2: #17222f;

  --accent: hsl(var(--ch-h) 85% 66%);
  --accent-2: hsl(var(--ch-h2) 80% 62%);
  --accent-ink: hsl(var(--ch-h) 90% 76%);
  --accent-wash: hsl(var(--ch-h) 85% 66% / 0.11);
  --accent-line: hsl(var(--ch-h) 85% 66% / 0.32);

  --ok: #3fcf8e;
  --ok-wash: #3fcf8e1a;
  --warn: #e0a83c;
  --warn-wash: #e0a83c1a;
  --bad: #ff6b83;
  --bad-wash: #ff6b831a;

  --shadow: 0 1px 2px #0006, 0 16px 40px #00000059;
}

/* ---------------------------------------------------------------- base --- */
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
}

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 36px) 96px;
}

/* ---------------------------------------------------------------- hero --- */
.header {
  position: relative;
  margin: 0 0 14px;
  padding: clamp(44px, 8vw, 96px) clamp(20px, 4vw, 44px) clamp(36px, 5vw, 60px);
  background:
    radial-gradient(
      120% 140% at 100% 0%,
      hsl(var(--ch-h2) 70% 45% / 0.22),
      transparent 58%
    ),
    radial-gradient(
      100% 130% at 0% 10%,
      hsl(var(--ch-h) 78% 45% / 0.28),
      transparent 60%
    ),
    linear-gradient(160deg, hsl(var(--ch-h) 55% 16%), hsl(var(--ch-h) 62% 9%));
  color: #fff;
  border-radius: 0 0 26px 26px;
  overflow: hidden;
}

.header::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 3px;
  background: linear-gradient(
    90deg,
    hsl(var(--ch-h) 85% 62%),
    hsl(var(--ch-h2) 85% 58%),
    transparent
  );
}

.header h1 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(30px, 5.4vw, 54px);
  line-height: 1.04;
  letter-spacing: -0.025em;
  margin: 0 0 14px;
  max-width: 20ch;
}

.header p {
  margin: 0;
  max-width: 62ch;
  font-size: clamp(15px, 1.6vw, 17px);
  color: #ffffffcc;
}

.header .subtitle,
.header > p:first-of-type {
  color: #ffffffd9;
}

/* ------------------------------------------------------------- sections -- */
.section {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: clamp(22px, 3.4vw, 40px);
  margin: 22px 0 0;
  counter-increment: sec;
  position: relative;
}

.section > h2 {
  font-family: var(--serif);
  font-size: clamp(21px, 2.7vw, 29px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: 0 0 22px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 13px;
}

.section > h2::before {
  content: counter(sec, decimal-leading-zero);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: var(--accent-wash);
  border: 1px solid var(--accent-line);
  border-radius: 8px;
  padding: 5px 9px;
  flex: 0 0 auto;
}

body {
  counter-reset: sec;
}

.section h3 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--accent-ink);
  margin: 30px 0 12px;
}

.section h4,
.section h5 {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 8px;
}

.section p {
  margin: 0 0 14px;
  color: var(--ink-2);
}

.section > p:last-child {
  margin-bottom: 0;
}

.section strong {
  color: var(--ink);
  font-weight: 650;
}

.icon {
  font-size: 0.95em;
  filter: saturate(0.9);
}

ul,
ol {
  margin: 0 0 14px;
  padding-left: 20px;
  color: var(--ink-2);
}

li {
  margin-bottom: 7px;
}

li::marker {
  color: var(--accent);
}

/* ------------------------------------------------------------- toc ------- */
.table-of-contents {
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 24px clamp(20px, 3vw, 30px);
  margin-top: 22px;
}

.table-of-contents h2 {
  font-family: var(--serif);
  font-size: 20px;
  margin: 0 0 14px;
}

.table-of-contents ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}

.table-of-contents li {
  margin: 0;
}

.table-of-contents a {
  display: block;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  text-decoration: none;
  font-size: 14px;
  transition:
    border-color 0.18s,
    transform 0.18s,
    color 0.18s;
}

.table-of-contents a:hover {
  border-color: var(--accent-line);
  color: var(--accent-ink);
  transform: translateX(3px);
}

/* ------------------------------------------------------------- grids ---- */
.grid,
.components-grid,
.threat-grid,
.countermeasure-grid,
.cia-triad,
.dimensions {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  margin: 0 0 16px;
  align-items: stretch;
}

.card,
.component-card,
.cia-element,
.dimension,
.aaa-element,
.threat-item,
.countermeasure-item,
.lifecycle-column,
.security-layers {
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 18px 19px;
  position: relative;
  transition:
    border-color 0.18s ease,
    transform 0.18s ease,
    box-shadow 0.18s ease;
}

.card:hover,
.component-card:hover,
.cia-element:hover,
.dimension:hover,
.aaa-element:hover,
.threat-item:hover,
.countermeasure-item:hover {
  border-color: var(--accent-line);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.card h3,
.card h4,
.component-card h5,
.cia-element h4,
.dimension h5,
.aaa-element h4,
.threat-item h4,
.countermeasure-item h4 {
  color: var(--accent-ink);
  margin: 0 0 9px;
  font-size: 15.5px;
  font-weight: 700;
}

.card p,
.component-card p,
.cia-element p,
.dimension p,
.threat-item p,
.countermeasure-item p {
  color: var(--ink-2);
  font-size: 14.4px;
  margin: 0 0 8px;
}

.card ul,
.cia-element ul,
.dimension ul,
.aaa-element ul {
  font-size: 14.2px;
  margin-bottom: 0;
}

/* the CIA cards get a coloured spine so the triad reads as a set */
.cia-element {
  border-top: 3px solid var(--accent);
}

.cia-element:nth-child(2) {
  border-top-color: var(--accent-2);
}

.cia-element:nth-child(3) {
  border-top-color: var(--ok);
}

/* ---------------------------------------------------------- callouts ---- */
.tip-box,
.example-box,
.warning-box,
.danger-box,
.success-box,
.highlight-box {
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 12px;
  padding: 16px 18px;
  margin: 18px 0;
  background: var(--accent-wash);
}

.tip-box h4,
.example-box h4,
.warning-box h4,
.danger-box h4,
.success-box h4,
.highlight-box h4 {
  color: var(--accent-ink);
}

.tip-box p,
.example-box p,
.warning-box p,
.danger-box p,
.success-box p,
.highlight-box p {
  color: var(--ink);
  margin-bottom: 0;
}

.tip-box p + p,
.example-box p + p,
.highlight-box p + p {
  margin-top: 9px;
}

.warning-box {
  border-left-color: var(--warn);
  background: var(--warn-wash);
}

.warning-box h4 {
  color: var(--warn);
}

.danger-box {
  border-left-color: var(--bad);
  background: var(--bad-wash);
}

.danger-box h4 {
  color: var(--bad);
}

.success-box {
  border-left-color: var(--ok);
  background: var(--ok-wash);
}

.success-box h4 {
  color: var(--ok);
}

.tip-box {
  border-left-color: var(--warn);
  background: var(--warn-wash);
}

.tip-box h4 {
  color: var(--warn);
}

/* ------------------------------------------------------------ layers ---- */
.security-layers {
  padding: 6px 8px;
  background: transparent;
  border: none;
}

.layer-item {
  background: var(--card-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 11px;
  padding: 13px 16px;
  margin: 9px 0;
  font-size: 14.5px;
  color: var(--ink-2);
  transition:
    transform 0.18s ease,
    border-color 0.18s ease,
    background 0.18s ease;
}

.layer-item:hover {
  transform: translateX(5px);
  border-color: var(--accent-line);
  background: var(--accent-wash);
}

.layer-item strong {
  color: var(--accent-ink);
}

.layer-item:nth-child(even) {
  border-left-color: var(--accent-2);
}

/* --------------------------------------------------------- lifecycle ---- */
.lifecycle-column h4 {
  text-align: center;
  color: var(--accent-ink);
  margin-bottom: 14px;
}

.lifecycle-phase {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 11px 13px;
  margin: 9px 0;
  text-align: center;
  font-size: 14px;
  color: var(--ink-2);
  transition: all 0.18s ease;
}

.lifecycle-phase:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  transform: scale(1.02);
}

html[data-theme="dark"] .lifecycle-phase:hover {
  color: #08111c;
}

/* -------------------------------------------------------------- quiz ---- */
.quiz-question {
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 20px 22px;
  margin: 18px 0;
}

.quiz-question h4 {
  color: var(--ink);
  margin-bottom: 14px;
  font-size: 15.5px;
}

.quiz-options {
  list-style: none;
  padding: 0;
  margin: 0;
}

.quiz-options li {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 11px 14px;
  margin: 8px 0;
  font-size: 14.4px;
  color: var(--ink-2);
  transition: all 0.16s ease;
}

.quiz-options li:hover {
  border-color: var(--accent-line);
  color: var(--ink);
}

.quiz-options li.correct {
  background: var(--ok-wash);
  border-color: var(--ok);
  color: var(--ink);
  font-weight: 600;
}

.quiz-options li.correct::after {
  content: "  ✓";
  color: var(--ok);
  font-weight: 700;
}

/* ------------------------------------------------------------ badges ---- */
.badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid currentColor;
  margin-right: 6px;
  vertical-align: 1px;
}

.badge-primary {
  color: var(--accent);
  background: var(--accent-wash);
}

.badge-success {
  color: var(--ok);
  background: var(--ok-wash);
}

.badge-warning {
  color: var(--warn);
  background: var(--warn-wash);
}

.badge-danger {
  color: var(--bad);
  background: var(--bad-wash);
}

.highlight {
  background: linear-gradient(180deg, transparent 58%, var(--accent-wash) 58%);
  border-bottom: 1px solid var(--accent-line);
  color: var(--ink);
  padding: 0 3px;
  font-weight: 600;
  border-radius: 2px;
}

/* ------------------------------------------------------------- tables --- */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14.3px;
  margin: 0 0 14px;
}

th {
  text-align: left;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent-ink);
  background: var(--accent-wash);
  padding: 11px 13px;
  border-bottom: 1px solid var(--accent-line);
}

td {
  padding: 11px 13px;
  border-bottom: 1px solid var(--line-2);
  color: var(--ink-2);
}

tr:last-child td {
  border-bottom: none;
}

tbody tr:hover td {
  background: var(--card-2);
}

/* ------------------------------------------------------------- footer --- */
.footer {
  margin-top: 34px;
  padding: 26px;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  color: var(--ink-3);
  font-family: var(--mono);
  font-size: 12px;
}

.footer p {
  margin: 4px 0;
  color: inherit;
}

@media (max-width: 640px) {
  .section {
    padding: 20px 17px;
  }

  .grid,
  .components-grid,
  .threat-grid,
  .countermeasure-grid {
    grid-template-columns: 1fr;
  }
}

/* ================================================================ layout
   containers the two pages use to hold the card grids                     */
.cia-container,
.cube-dimensions,
.lifecycle-comparison,
.aaa-container {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  margin: 0 0 16px;
  align-items: stretch;
}

.lifecycle-comparison {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.mccumber-cube {
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 20px;
  margin: 0 0 16px;
}

/* the CIA trio is colour-coded by role, not by position */
.confidentiality {
  border-top: 3px solid var(--accent);
}

.integrity {
  border-top: 3px solid var(--accent-2);
}

.availability {
  border-top: 3px solid var(--ok);
}

.confidentiality h3,
.confidentiality h4 {
  color: var(--accent);
}

.integrity h3,
.integrity h4 {
  color: var(--accent-2);
}

.availability h3,
.availability h4 {
  color: var(--ok);
}

/* ============================================================ animation
   Everything below only engages once the script adds .has-reveal, so the
   page is fully readable if JavaScript never runs. breakdown.css already
   neutralises all of it under prefers-reduced-motion.                     */

@keyframes bd-rise {
  from {
    opacity: 0;
    transform: translateY(22px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes bd-fade {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes bd-spine {
  from {
    transform: scaleX(0);
  }

  to {
    transform: scaleX(1);
  }
}

@keyframes bd-pop {
  0% {
    transform: scale(0.86);
    opacity: 0;
  }

  60% {
    transform: scale(1.06);
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes bd-sheen {
  0% {
    background-position: -140% 0;
  }

  100% {
    background-position: 240% 0;
  }
}

@keyframes bd-float {
  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-7px);
  }
}

/* hero arrives on load */
.header h1 {
  animation: bd-rise 0.72s cubic-bezier(0.22, 0.68, 0.32, 1) both;
}

.header p {
  animation: bd-rise 0.72s cubic-bezier(0.22, 0.68, 0.32, 1) 0.12s both;
}

.header::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    105deg,
    transparent 30%,
    #ffffff1f 48%,
    transparent 62%
  );
  background-size: 220% 100%;
  animation: bd-sheen 7s ease-in-out 1.1s infinite;
  pointer-events: none;
}

/* sections and their cards rise as they enter the viewport */
html.has-reveal .section,
html.has-reveal .table-of-contents {
  opacity: 0;
}

html.has-reveal .section.in-view,
html.has-reveal .table-of-contents.in-view {
  animation: bd-rise 0.62s cubic-bezier(0.22, 0.68, 0.32, 1) both;
}

html.has-reveal .section.in-view .card,
html.has-reveal .section.in-view .component-card,
html.has-reveal .section.in-view .cia-element,
html.has-reveal .section.in-view .dimension,
html.has-reveal .section.in-view .aaa-element,
html.has-reveal .section.in-view .threat-item,
html.has-reveal .section.in-view .countermeasure-item,
html.has-reveal .section.in-view .layer-item,
html.has-reveal .section.in-view .lifecycle-phase {
  animation: bd-rise 0.5s cubic-bezier(0.22, 0.68, 0.32, 1) both;
  animation-delay: calc(var(--i, 0) * 55ms + 90ms);
}

html.has-reveal .section.in-view > h2::before {
  animation: bd-pop 0.5s cubic-bezier(0.3, 1.4, 0.5, 1) both;
}

html.has-reveal .section.in-view .cia-element,
html.has-reveal .section.in-view .confidentiality,
html.has-reveal .section.in-view .integrity,
html.has-reveal .section.in-view .availability {
  transform-origin: left center;
}

/* callouts fade in a beat after their section */
html.has-reveal .section.in-view .tip-box,
html.has-reveal .section.in-view .example-box,
html.has-reveal .section.in-view .warning-box,
html.has-reveal .section.in-view .danger-box,
html.has-reveal .section.in-view .success-box,
html.has-reveal .section.in-view .highlight-box {
  animation: bd-fade 0.7s ease 0.25s both;
}

/* interaction polish */
.card,
.component-card,
.cia-element,
.dimension,
.aaa-element,
.threat-item,
.countermeasure-item {
  transition:
    border-color 0.2s ease,
    transform 0.22s cubic-bezier(0.22, 0.68, 0.32, 1),
    box-shadow 0.22s ease,
    background 0.2s ease;
}

.section > h2::before {
  transition:
    transform 0.2s ease,
    background 0.2s ease;
}

.section:hover > h2::before {
  transform: rotate(-4deg) scale(1.06);
}

.badge {
  transition: transform 0.18s ease;
}

.badge:hover {
  transform: translateY(-1px) scale(1.04);
}

.quiz-options li {
  transition:
    transform 0.16s ease,
    border-color 0.16s ease,
    background 0.16s ease,
    color 0.16s ease;
}

.quiz-options li:hover {
  transform: translateX(4px);
}

.quiz-options li.correct::after {
  display: inline-block;
  animation: bd-pop 0.45s cubic-bezier(0.3, 1.4, 0.5, 1) both;
}

.table-of-contents a {
  transition:
    transform 0.18s ease,
    border-color 0.18s,
    color 0.18s,
    background 0.18s;
}

.table-of-contents a:hover {
  background: var(--accent-wash);
}

.icon {
  display: inline-block;
  transition: transform 0.25s cubic-bezier(0.3, 1.3, 0.5, 1);
}

.section:hover .icon {
  transform: scale(1.14) rotate(-6deg);
}

.footer {
  transition: border-color 0.2s ease;
}

.footer:hover {
  border-color: var(--accent-line);
}
