:root {
  --bg: #F4F5FA;
  --surface: #FFFFFF;
  --ink: #1A1C2B;
  --ink-2: #4A4F63;
  --muted: #5A5F73;
  --border: #E2E4EE;
  --border-soft: #EDEEF4;
  --field-border: #D5D8E4;
  --accent: #5A45C8;
  --accent-ink: #3D2A9E;
  --accent-deep: #24186B;
  --accent-tint: #F1EEFC;
  --accent-ring: #C9C0F5;
  --chip-bg: #F0F1F6;
  --code-bg: #F7F7FB;
  --stage-bg: #FAFAFD;
  --error: #B42318;
  --outline: #2E2A4F;
  --font: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
}

button, input {
  font: inherit;
}

button:focus-visible, a:focus-visible {
  outline: 3px solid #8B7BE0;
  outline-offset: 2px;
}

.container {
  max-width: 1160px;
  margin: 0 auto;
  padding-inline: 24px;
}

/* Header & footer */

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  min-height: 60px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -0.01em;
}

.brand svg {
  color: var(--accent);
}

.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  padding-block: 20px;
  color: var(--muted);
  font-size: 14px;
}

/* Page */

.page {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding-top: 32px;
  padding-bottom: 56px;
}

.intro h1 {
  margin: 0 0 6px;
  font-size: 34px;
  line-height: 1.15;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0;
  font-size: 17px;
  color: var(--muted);
}

/* Shape picker */

.shape-picker {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 4px 2px 6px;
}

.shape-card {
  flex: 1 0 128px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 12px;
  border: 2px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}

.shape-card:hover {
  border-color: var(--accent-ring);
}

.shape-card[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-tint);
  color: var(--accent-deep);
}

/* Workspace */

.workspace {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  align-items: flex-start;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
}

.calculator {
  flex: 999 1 460px;
  min-width: 0;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.viewer {
  flex: 1 1 360px;
  min-width: 0;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.calc-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.calc-head h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 10px;
  background: var(--chip-bg);
}

.segmented button {
  min-height: 36px;
  padding: 6px 12px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

#unit-picker button[aria-pressed="true"] {
  background: var(--accent);
  color: #FFFFFF;
}

.view-toggle button {
  flex: 1;
}

.view-toggle button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(20, 20, 40, 0.12);
}

/* Inputs */

.fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 0;
}

.field-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
}

.field-row label {
  flex: 0 0 150px;
  font-size: 15px;
  font-weight: 600;
}

.input-wrap {
  flex: 1 1 200px;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 48px;
  padding: 0 14px;
  border: 1.5px solid var(--field-border);
  border-radius: 10px;
  background: var(--surface);
}

.input-wrap:focus-within {
  outline: 3px solid var(--accent-ring);
  outline-offset: 1px;
}

.input-wrap.has-error {
  border-color: var(--error);
}

.input-wrap input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  color: var(--ink);
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.input-unit {
  color: var(--muted);
  font-size: 15px;
  font-weight: 500;
}

.field-error {
  flex-basis: 100%;
  margin: 0;
  color: var(--error);
  font-size: 14px;
  font-weight: 500;
}

.divider {
  height: 1px;
  background: var(--border);
}

/* Results */

#results-filled {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.result-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.result-card {
  flex: 1 1 220px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 18px;
  border-radius: 14px;
  background: var(--accent-tint);
}

.result-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.result-label {
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.copy-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 4px 10px;
  border: 1px solid #D5D0F2;
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.result-value {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
}

.result-number {
  font-size: 32px;
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.result-unit {
  color: var(--ink-2);
  font-size: 18px;
  font-weight: 600;
}

.extras {
  margin: 0;
}

.extras div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--border-soft);
}

.extras dt {
  color: var(--muted);
}

.extras dd {
  margin: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.steps-toggle {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 14px 8px 10px;
  border: none;
  border-radius: 10px;
  background: var(--chip-bg);
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.steps-toggle svg {
  transition: transform 0.15s;
}

.steps-toggle[aria-expanded="true"] svg {
  transform: rotate(90deg);
}

.steps {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.step-group h3 {
  margin: 0 0 6px;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 700;
}

.step-lines {
  margin: 0;
  padding: 12px 16px;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  background: var(--code-bg);
  font-family: var(--mono);
  font-size: 14.5px;
  line-height: 1.8;
  white-space: pre;
  overflow-x: auto;
}

.empty-state {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 20px;
  border: 1.5px dashed #CDD0DD;
  border-radius: 14px;
}

.empty-state p {
  margin: 0;
  color: var(--ink-2);
  font-weight: 600;
}

.formulas {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 14.5px;
  white-space: pre-line;
}

/* 3D model / diagram */

.stage {
  height: 320px;
  overflow: hidden;
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  background: var(--stage-bg);
}

#p5-container,
#diagram-container {
  width: 100%;
  height: 100%;
}

#p5-container canvas {
  display: block;
  cursor: grab;
}

#diagram-container {
  display: flex;
  align-items: center;
  justify-content: center;
}

#diagram-container svg {
  width: 100%;
  max-width: 360px;
  height: 300px;
}

.stage-caption {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.dg-shape {
  fill: #FFFFFF;
  stroke: var(--outline);
  stroke-width: 2;
  stroke-linejoin: round;
}

.dg-edge {
  fill: none;
  stroke: var(--outline);
  stroke-width: 1.5;
}

.dg-hidden {
  fill: none;
  stroke: var(--outline);
  stroke-width: 1.5;
  stroke-dasharray: 5 5;
  opacity: 0.7;
}

.dg-dim {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.5;
}

.dg-dim-dash {
  stroke-width: 2;
  stroke-dasharray: 6 4;
}

.dg-dot {
  fill: var(--accent);
}

.dg-label {
  fill: var(--accent-ink);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
}

/* About */

.about {
  max-width: 760px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.about h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

#about-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.about p {
  margin: 0;
  color: #3A3E50;
  font-size: 16.5px;
  line-height: 1.65;
}

@media (max-width: 600px) {
  .container {
    padding-inline: 16px;
  }

  .intro h1 {
    font-size: 28px;
  }

  .calculator,
  .about {
    padding: 20px;
  }

  .field-row label {
    flex-basis: 100%;
  }
}
