:root {
  --bg: #eef3f9;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #dbe5ef;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --red: #ef4444;
  --red-dark: #dc2626;
  --green: #16a34a;
  --amber: #d97706;
  --shadow: 0 22px 60px rgba(15, 23, 42, 0.13);
  --soft-shadow: 0 12px 30px rgba(15, 23, 42, 0.10);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
}

body {
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.18), transparent 30rem),
    radial-gradient(circle at top right, rgba(239, 68, 68, 0.12), transparent 32rem),
    var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 25%) minmax(0, 1fr);
  width: 100%;
  height: 100vh;
  min-height: 620px;
}

.control-panel {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  padding: 22px;
  background: linear-gradient(180deg, rgba(248, 250, 252, 0.98), rgba(226, 232, 240, 0.88));
  border-right: 1px solid rgba(148, 163, 184, 0.35);
}

.stage-panel {
  min-width: 0;
  padding: 26px;
}

.simulator-block {
  height: calc(100vh - 52px);
  min-height: 620px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.brand-card,
.card,
.canvas-card,
.stage-header,
.theory-panel {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.28);
  box-shadow: var(--soft-shadow);
  backdrop-filter: blur(14px);
}

.brand-card {
  padding: 24px;
  border-radius: var(--radius-xl);
  margin-bottom: 18px;
}

.eyebrow {
  color: var(--blue);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  font-weight: 800;
}

h1,
h2,
h3,
h4 {
  color: var(--ink);
  line-height: 1.12;
  margin-top: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.4rem);
  margin-bottom: 12px;
}

h2 {
  font-size: clamp(1.7rem, 3vw, 2.6rem);
  margin-bottom: 0;
}

h3 {
  font-size: clamp(1.45rem, 2vw, 2rem);
  margin-bottom: 14px;
}

h4 {
  font-size: 1.05rem;
  margin-bottom: 10px;
}

p,
li,
td,
th {
  color: #334155;
  line-height: 1.7;
}

.brand-card p,
.card p {
  margin: 0;
}


.card {
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 16px;
}

.section-title {
  font-weight: 900;
  color: var(--ink);
  margin-bottom: 14px;
  letter-spacing: -0.02em;
}

.slider-group {
  margin: 16px 0;
}

.slider-header,
.metric-row,
.speed-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.slider-header label,
.speed-row span,
.metric-row span {
  font-weight: 750;
  color: #334155;
}

.slider-header label span {
  color: var(--blue);
}

output,
.metric-row strong {
  color: var(--ink);
  font-weight: 900;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--blue);
  margin-top: 10px;
}

.formula {
  margin: 8px 0 12px;
  padding: 9px 12px;
  border-radius: 12px;
  background: #f1f5f9;
  color: #475569;
  font-weight: 700;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.metric-grid div {
  padding: 12px;
  border-radius: 14px;
  background: #f8fafc;
  border: 1px solid var(--line);
  text-align: center;
}

.metric-grid span,
.metric-grid strong {
  display: block;
}

.metric-grid span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.metric-grid strong {
  margin-top: 3px;
  color: var(--ink);
}

.controls-card {
  display: grid;
  gap: 14px;
}

.play-button,
.small-button {
  border: 0;
  border-radius: 999px;
  font-weight: 900;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.play-button {
  min-height: 50px;
  color: white;
  background: linear-gradient(135deg, var(--blue), #38bdf8);
  box-shadow: 0 12px 22px rgba(37, 99, 235, 0.25);
}

.play-button.pause {
  background: linear-gradient(135deg, var(--red), #fb7185);
  box-shadow: 0 12px 22px rgba(239, 68, 68, 0.25);
}

.play-button:hover,
.small-button:hover {
  transform: translateY(-1px);
}

.branch-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.small-button {
  padding: 11px 10px;
  color: #475569;
  background: #e2e8f0;
}

.small-button.active {
  color: white;
  background: #0f172a;
}

.speed-row {
  display: grid;
  grid-template-columns: 1fr;
}

.stage-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 20px 24px;
  border-radius: var(--radius-xl);
}

.angle-readout {
  flex: 0 0 auto;
  padding: 12px 16px;
  border-radius: 999px;
  background: #0f172a;
  color: white;
  font-weight: 900;
  box-shadow: var(--soft-shadow);
}

.canvas-card {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  border-radius: var(--radius-xl);
  padding: 14px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

#mechanismSvg {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.svg-bg {
  fill: #f8fafc;
}

.grid-line {
  stroke: #dbe5ef;
  stroke-width: 1;
}

.pivot-support {
  fill: #e2e8f0;
  stroke: #64748b;
  stroke-width: 2.2;
}

.pivot-hatch {
  stroke: #94a3b8;
  stroke-width: 2;
}

.ground-link,
.input-link,
.output-link,
.floating-link {
  stroke-linecap: round;
  filter: url(#softShadow);
}

.ground-link {
  stroke: #334155;
  stroke-width: 11;
}

.input-link {
  stroke: var(--red);
  stroke-width: 10;
}

.output-link {
  stroke: var(--blue);
  stroke-width: 10;
}

.floating-link {
  stroke: #16a34a;
  stroke-width: 10;
}

.joint-outer {
  fill: white;
  stroke: #0f172a;
  stroke-width: 3;
  filter: url(#softShadow);
}

.joint-inner {
  fill: #0f172a;
}

.point-label,
.link-label,
.angle-label {
  font-weight: 900;
  paint-order: stroke;
  stroke: white;
  stroke-width: 5px;
  stroke-linejoin: round;
}

.point-label {
  fill: #0f172a;
  font-size: 22px;
}

.link-label {
  fill: #334155;
  font-size: 24px;
}

.angle-path-alpha,
.angle-path-beta {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 5 6;
}

.angle-path-alpha {
  stroke: var(--red);
  marker-end: url(#arrowRed);
}

.angle-path-beta {
  stroke: var(--blue);
  marker-end: url(#arrowBlue);
}

.angle-label {
  font-size: 15px;
}

.angle-label.alpha {
  fill: var(--red-dark);
}

.angle-label.beta {
  fill: var(--blue-dark);
}

.status-dock {
  position: absolute;
  left: 28px;
  right: 28px;
  bottom: 28px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.status-badge {
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 0.88rem;
  font-weight: 900;
  border: 1px solid transparent;
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.10);
}

.status-badge.neutral {
  color: #334155;
  background: rgba(248, 250, 252, 0.92);
  border-color: #cbd5e1;
}

.status-badge.ok {
  color: #14532d;
  background: rgba(220, 252, 231, 0.95);
  border-color: #86efac;
}

.status-badge.warn {
  color: #78350f;
  background: rgba(254, 243, 199, 0.95);
  border-color: #fbbf24;
}

.status-badge.bad {
  color: #7f1d1d;
  background: rgba(254, 226, 226, 0.95);
  border-color: #fca5a5;
}

.invalid-overlay {
  fill: rgba(255, 255, 255, 0.85);
  stroke: #fecaca;
  stroke-width: 2;
}

.invalid-text {
  text-anchor: middle;
  font-size: 30px;
  font-weight: 900;
  fill: #b91c1c;
}

.theory-panel {
  width: min(1180px, calc(100% - 52px));
  margin: 26px auto;
  padding: clamp(22px, 4vw, 48px);
  border-radius: var(--radius-xl);
}

.article-hero {
  padding: clamp(22px, 4vw, 42px);
  border-radius: var(--radius-xl);
  background: linear-gradient(135deg, #eff6ff, #f8fafc 45%, #ecfeff);
  border: 1px solid #dbeafe;
  margin-bottom: 22px;
}

.article-hero p {
  font-size: 1.08rem;
  max-width: 850px;
}

.badge-row,
.article-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.badge-row span,
.article-nav a {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-weight: 900;
}

.badge-row span {
  padding: 8px 12px;
  color: #1e3a8a;
  background: #dbeafe;
}

.article-nav {
  position: sticky;
  top: 16px;
  z-index: 5;
  padding: 12px;
  margin-bottom: 20px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(12px);
}

.article-nav a {
  padding: 9px 12px;
  color: #334155;
  background: #f1f5f9;
  font-size: 0.9rem;
}

.article-nav a:hover {
  background: #dbeafe;
  color: var(--blue-dark);
  text-decoration: none;
}

.doc-section {
  padding: 30px 0;
  border-top: 1px solid var(--line);
}

.doc-section:first-of-type {
  border-top: 0;
}

.doc-section > p,
.doc-section > ul,
.doc-section > ol {
  max-width: 980px;
}

.math-block {
  overflow-x: auto;
  margin: 16px 0;
  padding: 16px;
  border-radius: 18px;
  background: #f8fafc;
  border: 1px solid var(--line);
}

.responsive-table {
  width: 100%;
  overflow-x: auto;
  margin: 16px 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
}

th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: #f1f5f9;
  color: #0f172a;
  font-weight: 900;
}

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

pre {
  overflow-x: auto;
  padding: 18px;
  border-radius: 18px;
  background: #0f172a;
  color: #e2e8f0;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06);
}

code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

p code,
li code,
td code {
  padding: 0.18em 0.4em;
  border-radius: 7px;
  background: #e2e8f0;
  color: #0f172a;
}

.two-column-list {
  columns: 2 320px;
  column-gap: 32px;
}

.two-column-list li {
  break-inside: avoid;
  margin-bottom: 8px;
}

.learning-links-section > p {
  max-width: 820px;
}

.resource-link-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 18px;
}

.resource-link-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px;
  border-radius: 22px;
  background: linear-gradient(135deg, #eff6ff, #ffffff);
  border: 1px solid #dbeafe;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.08);
  color: #334155;
}

.resource-link-card:hover {
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: 0 16px 30px rgba(15, 23, 42, 0.12);
}

.resource-link-card strong {
  color: var(--ink);
  font-size: 1.1rem;
  line-height: 1.3;
}

.resource-link-card span:last-child {
  color: var(--muted);
  line-height: 1.55;
}

.resource-link-kicker {
  color: var(--blue-dark);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.footer-section {
  margin-bottom: 20px;
}

@media (max-width: 1040px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
  }

  .stage-panel {
    order: 1;
  }

  .control-panel {
    order: 2;
    position: relative;
    height: auto;
    border-right: 0;
    border-top: 1px solid rgba(148, 163, 184, 0.35);
    border-bottom: 1px solid rgba(148, 163, 184, 0.35);
  }

  .simulator-block {
    height: calc(100vh - 28px);
    min-height: 620px;
  }

  .canvas-card {
    min-height: 0;
  }

  .stage-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .angle-readout {
    width: 100%;
    text-align: center;
  }

  .article-nav {
    position: static;
    border-radius: 24px;
  }
}

@media (max-width: 640px) {
  .stage-panel,
  .control-panel {
    padding: 14px;
  }

  .simulator-block {
    height: calc(100vh - 28px);
    min-height: 520px;
  }

  .canvas-card {
    min-height: 0;
  }

  #mechanismSvg {
    min-height: 0;
  }

  .theory-panel {
    width: calc(100% - 28px);
    margin: 14px auto;
  }

  .resource-link-grid {
    grid-template-columns: 1fr;
  }

  .status-dock {
    position: static;
    margin-top: 12px;
  }

  .branch-toggle,
  .metric-grid {
    grid-template-columns: 1fr;
  }
}

.download-project-section {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0px 20px 24px;
  }

  .download-project-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 220px;
    padding: 16px 34px;
    border-radius: 999px;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    color: #ffffff;
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    text-decoration: none;
    box-shadow: 0 18px 35px rgba(37, 99, 235, 0.28);
    transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
  }

  .download-project-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 24px 45px rgba(37, 99, 235, 0.38);
    filter: brightness(1.05);
  }

  .download-project-button:active {
    transform: translateY(-1px);
    box-shadow: 0 14px 28px rgba(37, 99, 235, 0.28);
  }
