/* ============ Design tokens ============ */
:root {
  --bg: #0b1020;
  --bg-soft: #111730;
  --bg-card: #151d3a;
  --bg-card-2: #1a2342;
  --border: #26315c;
  --text: #e7ecff;
  --text-dim: #9aa6d4;
  --accent: #4f8bff;
  --accent-2: #37c8ab;

  --l7: #b15cff;
  --l6: #8f6dff;
  --l5: #5f8bff;
  --l4: #37c8ab;
  --l3: #39c56a;
  --l2: #ffb02e;
  --l1: #ff5f5f;

  --host: #1b3a6b;
  --switch: #6b4f1b;
  --router: #4b1b6b;

  --mono: "Cascadia Code", "Consolas", "SF Mono", monospace;
  --sans: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(79, 139, 255, 0.12), transparent 60%),
    radial-gradient(900px 500px at 10% 0%, rgba(55, 200, 171, 0.08), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============ Top nav ============ */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(11, 16, 32, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  flex-wrap: wrap;
}
.nav-brand {
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--text);
  margin-right: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.nav-brand .dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--l4), var(--l3), var(--l2), var(--l1));
  display: inline-block;
}
.nav-inner a:not(.nav-brand) {
  color: var(--text-dim);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 600;
}
.nav-inner a:not(.nav-brand):hover {
  color: var(--text);
  background: var(--bg-card);
  text-decoration: none;
}
.nav-inner a:not(.nav-brand).active {
  color: var(--text);
  background: var(--bg-card);
  box-shadow: inset 0 0 0 1px var(--border);
}

/* ============ Layout ============ */
.wrap { max-width: 1180px; margin: 0 auto; padding: 28px 20px 80px; }

.page-hero { margin-bottom: 28px; }
.page-hero h1 {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  letter-spacing: -0.5px;
  line-height: 1.15;
  margin-bottom: 10px;
}
.page-hero h1 .hl { color: var(--accent); }
.page-hero .sub {
  color: var(--text-dim);
  font-size: 1.05rem;
  max-width: 820px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

h2 { font-size: 1.45rem; margin: 34px 0 14px; letter-spacing: -0.3px; }
h3 { font-size: 1.1rem; margin: 20px 0 10px; }
p { margin-bottom: 12px; }
code, .mono { font-family: var(--mono); font-size: 0.9em; background: rgba(255,255,255,0.06); padding: 2px 6px; border-radius: 5px; }
pre {
  background: #0a0e1e;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 12px 0;
  font-family: var(--mono);
  font-size: 0.88rem;
  line-height: 1.5;
}
pre .dim { color: var(--text-dim); }

.muted { color: var(--text-dim); }

/* ============ Grids ============ */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; }

/* ============ Buttons ============ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--accent), #2f6fe0);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 0.98rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  box-shadow: 0 6px 18px rgba(79, 139, 255, 0.35);
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(79, 139, 255, 0.45); }
.btn.secondary {
  background: var(--bg-card-2);
  box-shadow: inset 0 0 0 1px var(--border);
  color: var(--text);
}
.btn.secondary:hover { box-shadow: inset 0 0 0 1px var(--accent), 0 8px 20px rgba(0,0,0,0.3); }
.btn.small { padding: 8px 14px; font-size: 0.88rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

/* ============ Step list / stepper ============ */
.step-grid { display: grid; grid-template-columns: 340px 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .step-grid { grid-template-columns: 1fr; } }

.step-list { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; max-height: 560px; overflow-y: auto; }
.step-list .step-item {
  display: flex;
  gap: 12px;
  padding: 10px;
  border-radius: 9px;
  cursor: pointer;
  align-items: flex-start;
  border-left: 3px solid transparent;
  transition: background 0.15s ease;
}
.step-list .step-item:hover { background: var(--bg-card-2); }
.step-list .step-item.active {
  background: var(--bg-card-2);
  border-left-color: var(--accent);
}
.step-list .step-item.done { border-left-color: var(--l3); }
.step-list .step-num {
  flex: 0 0 26px; height: 26px;
  border-radius: 50%;
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700; color: var(--text-dim);
}
.step-list .step-item.active .step-num { background: var(--accent); color: #fff; border-color: var(--accent); }
.step-list .step-item.done .step-num { background: var(--l3); color: #07160d; border-color: var(--l3); }
.step-list .step-title { font-weight: 700; font-size: 0.92rem; }
.step-list .step-tag {
  font-size: 0.7rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-dim); margin-top: 2px;
}

.player-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

/* ============ Network diagram ============ */
.diagram {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  position: relative;
  overflow: hidden;
  min-height: 460px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
}
.diagram svg { width: 100%; height: auto; display: block; }

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 10px;
  padding: 10px 14px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.legend .sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; vertical-align: -1px; margin-right: 5px; }

/* device node */
.device rect.host { fill: #16345f; stroke: #2f6fae; }
.device rect.switch { fill: #4a3515; stroke: #d19a2f; }
.device rect.router { fill: #3d1a5e; stroke: #a04fe0; }
.device-label { font-weight: 700; font-size: 20px; fill: #fff; }
.device-sub { font-size: 14px; fill: #b9c3e8; font-family: var(--mono); }

/* links */
.link { stroke: #33407a; stroke-width: 2.5; }
.link.lit { stroke: var(--l3); filter: drop-shadow(0 0 5px rgba(57,197,106,0.8)); }
.link.lit-b { stroke: var(--l4); filter: drop-shadow(0 0 5px rgba(55,200,171,0.8)); }

/* packet moving along links */
.packet { fill: #ffd24a; stroke: #a8780a; }
.packet.ping { fill: var(--l4); stroke: #0d7f68; }
@keyframes dashmove {
  to { stroke-dashoffset: -22; }
}
.link.dashed { stroke-dasharray: 6 6; animation: dashmove 0.6s linear infinite; }

/* OSI stack bars inside devices */
.osi-stack { font-size: 10px; }
.osi-stack rect.stack-l { fill: #0c1126; stroke: #26315c; stroke-width: 1; }
.osi-stack text.stack-t { fill: #cfd8ff; font-size: 9.5px; font-weight: 700; }
.osi-stack .on { opacity: 1; filter: drop-shadow(0 0 4px rgba(255,255,255,0.35)); }
.osi-stack .off { opacity: 0.22; }
.osi-stack .l7 { fill: var(--l7); } .osi-stack .l6 { fill: var(--l6); }
.osi-stack .l5 { fill: var(--l5); } .osi-stack .l4 { fill: var(--l4); }
.osi-stack .l3 { fill: var(--l3); } .osi-stack .l2 { fill: var(--l2); }
.osi-stack .l1 { fill: var(--l1); }

/* moving PDU capsule */
@keyframes capsulePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}
.pdu-capsule {
  animation: capsulePulse 1.2s ease-in-out infinite;
}
.pdu-capsule text { fill: #0c1126; font-weight: 800; font-size: 10px; }
.pdu-capsule rect { stroke: #fff; stroke-width: 1; }

/* ============ OSI model layers ============ */
.osi-table { display: flex; flex-direction: column; gap: 10px; }
.osi-row {
  display: grid;
  grid-template-columns: 74px 1fr 1fr 120px;
  gap: 12px;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left-width: 6px;
  border-radius: 10px;
  padding: 12px 16px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.osi-row:hover { transform: translateX(4px); box-shadow: var(--shadow); }
.osi-row.active { box-shadow: 0 0 0 1px var(--accent), var(--shadow); }
@media (max-width: 780px) { .osi-row { grid-template-columns: 60px 1fr; } .osi-row .osi-pdu { display: none; } }
.osi-row .osi-num {
  font-size: 1.6rem; font-weight: 800; text-align: center;
}
.osi-row .osi-name { font-weight: 800; font-size: 1.02rem; }
.osi-row .osi-sub { font-size: 0.85rem; color: var(--text-dim); }
.osi-row .osi-pdu {
  font-family: var(--mono); font-size: 0.82rem; font-weight: 700;
  text-align: center;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 6px;
}

.layer-detail {
  margin-top: 18px;
  padding: 22px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  border-top: 5px solid var(--accent);
}
.layer-detail .focus { font-size: 1.15rem; font-weight: 800; margin-bottom: 8px; }
.layer-detail ul { margin: 8px 0 8px 20px; }
.layer-detail li { margin-bottom: 6px; }
.layer-detail .examples { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.layer-detail .examples span {
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 12px; font-size: 0.82rem; font-family: var(--mono);
}

/* ============ PDU chip stack (encapsulation view) ============ */
.pdu-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.pdu-chip {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 700;
  border-radius: 8px;
  padding: 6px 14px;
  border: 1px solid rgba(255,255,255,0.25);
  color: #0b1020;
  white-space: nowrap;
}
.pdu-chip.bits { background: var(--l1); }
.pdu-chip.frame { background: var(--l2); }
.pdu-chip.packet { background: var(--l3); }
.pdu-chip.segment { background: var(--l4); }
.pdu-chip.data { background: var(--l7); color: #fff; }
.encap-flow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }

/* ============ Callouts ============ */
.callout {
  border-radius: 10px;
  padding: 14px 18px;
  margin: 14px 0;
  border: 1px solid var(--border);
  background: var(--bg-card);
}
.callout.info { border-left: 5px solid var(--accent); }
.callout.warn { border-left: 5px solid var(--l2); }
.callout.tip { border-left: 5px solid var(--l3); }
.callout .ct { font-weight: 800; text-transform: uppercase; font-size: 0.78rem; letter-spacing: 0.08em; color: var(--text-dim); margin-bottom: 4px; }

.cli-box {
  background: #0a0e1e;
  border: 1px solid var(--border);
  border-left: 5px solid var(--l4);
  border-radius: 10px;
  padding: 14px 16px;
  margin: 14px 0;
  font-family: var(--mono);
  font-size: 0.86rem;
}
.cli-box .prompt { color: var(--l4); }
.cli-box .out { color: var(--text-dim); }
.cli-box .title { font-family: var(--sans); font-weight: 800; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--l4); margin-bottom: 8px; }

/* ============ Glossary ============ */
.gloss { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.gloss .g-item { background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; }
.gloss .g-term { font-family: var(--mono); font-weight: 700; color: var(--accent); font-size: 0.9rem; }
.gloss .g-def { font-size: 0.88rem; color: var(--text-dim); margin-top: 4px; }

/* ============ Tables ============ */
.tbl { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.9rem; }
.tbl th, .tbl td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); }
.tbl th { color: var(--text-dim); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
.tbl td code { background: transparent; padding: 0; }

/* ============ Misc ============ */
.badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 20px;
  padding: 3px 10px;
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.badge.l7 { background: rgba(177,92,255,0.18); color: #d9a7ff; border-color: #7a2fb0; }
.badge.l6 { background: rgba(143,109,255,0.18); color: #c8b2ff; border-color: #6b45d0; }
.badge.l5 { background: rgba(95,139,255,0.18); color: #a9c2ff; border-color: #2f6fae; }
.badge.l4 { background: rgba(55,200,171,0.16); color: #7fe8d0; border-color: #14997e; }
.badge.l3 { background: rgba(57,197,106,0.16); color: #8cf0ae; border-color: #1f8f47; }
.badge.l2 { background: rgba(255,176,46,0.16); color: #ffd98a; border-color: #b07a12; }
.badge.l1 { background: rgba(255,95,95,0.16); color: #ffb0b0; border-color: #c02f2f; }

.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 60px;
  padding: 24px 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
}

::selection { background: rgba(79, 139, 255, 0.4); }

.pdu-view strong { color: var(--text); }
.pdu-view pre { margin: 10px 0 0; white-space: pre-wrap; }

.step-item .step-tag { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.diagram { background: #0d1226; }

.step-list.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 10px;
  max-height: none;
  overflow: visible;
  margin-top: 16px;
}
.step-list.grid .step-item { border: 1px solid var(--border); }

@media print {
  .site-nav, .player-bar, .step-list { display: none; }
  body { background: #fff; color: #111; }
}
