:root {
  --bg: #f3f7f7;
  --surface: #ffffff;
  --surface-soft: #f8fbfb;
  --text: #18383b;
  --muted: #70878a;
  --line: #dce7e8;
  --line-strong: #c9d9da;
  --teal: #0a9294;
  --teal-dark: #087477;
  --teal-soft: #e9f7f6;
  --blue: #176bc7;
  --danger: #b83d4c;
  --shadow: 0 9px 28px rgba(22, 55, 59, .065);
  --radius: 13px;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { touch-action: manipulation; }
.icon { width: 1em; height: 1em; display: inline-block; flex: 0 0 auto; }

.topbar {
  height: 68px;
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.97);
  backdrop-filter: blur(10px);
}
.topbar-inner {
  width: min(100% - 32px, 1380px);
  height: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 230px 1fr 230px;
  align-items: center;
  gap: 18px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; width: fit-content; }
.brand-mark {
  width: 36px; height: 36px; display: grid; place-items: center;
  border-radius: 11px; background: var(--teal); color: #fff; font-size: 20px;
}
.brand-text { display: grid; line-height: 1.02; }
.brand-text strong { font-size: 15px; letter-spacing: -.01em; }
.brand-text small { margin-top: 4px; color: var(--muted); font-size: 9px; font-weight: 850; letter-spacing: .12em; text-transform: uppercase; }
.page-name { justify-self: center; color: #35575a; font-size: 13px; font-weight: 800; letter-spacing: -.01em; }
.topbar-spacer { width: 1px; justify-self: end; }

.app-shell {
  width: min(100% - 32px, 1380px);
  margin: 18px auto 24px;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.sidebar, .workspace {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.sidebar {
  position: sticky;
  top: 86px;
  border-radius: var(--radius);
  overflow: hidden;
}
.sidebar-head {
  min-height: 76px;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: #fbfdfd;
}
.section-icon {
  width: 38px; height: 38px; display: grid; place-items: center;
  border-radius: 10px; background: var(--teal-soft); color: var(--teal-dark); font-size: 19px;
}
.kicker { display: block; margin-bottom: 3px; color: #8a9b9e; font-size: 9px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
h1, h2 { margin: 0; color: var(--text); letter-spacing: -.025em; }
h1 { font-size: 17px; }
h2 { font-size: 19px; }

.control-form { padding: 17px; }
.form-section { margin: 0 0 18px; padding: 0; border: 0; }
.form-section-title, .choice-section legend {
  width: 100%; margin: 0 0 8px; padding: 0; color: #60797d; font-size: 10px; font-weight: 850; letter-spacing: .025em;
}
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.field { display: grid; gap: 6px; min-width: 0; }
.field > span:first-child { color: #71878a; font-size: 10px; font-weight: 750; }
.input-unit {
  height: 42px; display: flex; align-items: center;
  border: 1px solid var(--line-strong); border-radius: 9px; background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input-unit:focus-within { border-color: #75bfc1; box-shadow: 0 0 0 3px rgba(10,146,148,.09); }
.input-unit input {
  min-width: 0; width: 100%; height: 100%; padding: 0 8px 0 11px;
  border: 0; outline: 0; background: transparent; color: var(--text); font-weight: 800; font-variant-numeric: tabular-nums;
}
.input-unit em { padding-right: 10px; color: #8da0a3; font-size: 10px; font-style: normal; font-weight: 800; }
.segmented { display: grid; gap: 6px; padding: 4px; border: 1px solid var(--line); border-radius: 10px; background: #f7f9f9; }
.segmented.two { grid-template-columns: 1fr 1fr; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  height: 34px; display: grid; place-items: center; border-radius: 7px;
  color: #6d8386; font-size: 11px; font-weight: 800; cursor: pointer;
}
.segmented input:checked + span { background: #fff; color: var(--teal-dark); box-shadow: 0 1px 4px rgba(25,64,68,.09); }
.segmented input:focus-visible + span { outline: 2px solid #71bdbf; outline-offset: 1px; }

.count-presets { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.count-pill {
  height: 42px; padding: 0; border: 1px solid var(--line-strong); border-radius: 9px;
  background: #fff; color: #557275; font-size: 13px; font-weight: 900; cursor: pointer;
}
.count-pill:hover { border-color: #9ec6c8; background: #fbfefe; }
.count-pill.is-active { color: var(--teal-dark); border-color: var(--teal); background: var(--teal-soft); }
.count-pill:focus-visible, .custom-count button:focus-visible, .action-button:focus-visible, .icon-button:focus-visible { outline: 3px solid rgba(10,146,148,.22); outline-offset: 2px; }
.custom-count {
  margin-top: 8px; min-height: 42px; display: grid; grid-template-columns: auto 64px 1fr; align-items: center; gap: 7px;
  padding: 5px 5px 5px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fafcfc;
}
.custom-count.is-active { border-color: #9bcacc; background: #f5fbfb; }
.custom-count label { color: #647d80; font-size: 10px; font-weight: 800; }
.custom-count input {
  width: 64px; height: 30px; padding: 0 8px; border: 1px solid var(--line-strong); border-radius: 7px;
  outline: 0; background: #fff; color: var(--text); text-align: center; font-weight: 850; font-variant-numeric: tabular-nums;
}
.custom-count input:focus { border-color: #75bfc1; box-shadow: 0 0 0 2px rgba(10,146,148,.08); }
.custom-count button {
  height: 30px; border: 0; border-radius: 7px; background: #edf5f5; color: var(--teal-dark); font-size: 10px; font-weight: 850; cursor: pointer;
}
.custom-count button:hover { background: #e4f2f2; }
.field-help { margin-top: 7px; color: #8a9c9f; font-size: 9px; line-height: 1.4; }
.action-button {
  width: 100%; height: 44px; display: flex; justify-content: center; align-items: center; gap: 8px;
  border: 0; border-radius: 9px; background: var(--teal); color: #fff; font-size: 11px; font-weight: 850; cursor: pointer;
  transition: background .15s ease, transform .15s ease;
}
.action-button:hover { background: var(--teal-dark); }
.action-button:active { transform: translateY(1px); }

.summary-card {
  margin: 0 17px 17px; min-height: 62px; padding: 10px 10px 10px 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border: 1px solid #cce4e4; border-radius: 10px; background: #f2faf9;
}
.summary-card > div { min-width: 0; display: grid; gap: 4px; }
.summary-card span { color: #71898b; font-size: 9px; font-weight: 750; }
.summary-card strong { color: #315d60; font-size: 10px; font-weight: 850; font-variant-numeric: tabular-nums; }
.summary-card b {
  width: 34px; height: 34px; display: grid; place-items: center; flex: 0 0 auto;
  border-radius: 50%; background: var(--teal); color: #fff; font-size: 13px;
}
.status-card { margin: 0 17px 17px; padding: 11px; display: flex; gap: 8px; border-radius: 9px; font-size: 10px; line-height: 1.45; }
.status-card.error { color: #8e3340; background: #fff4f5; border: 1px solid #f2ccd2; }

.workspace { min-width: 0; border-radius: var(--radius); overflow: hidden; }
.workspace-toolbar {
  min-height: 76px; padding: 15px 18px; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  border-bottom: 1px solid var(--line); background: #fff;
}
.math-chip, .angle-badge {
  display: inline-flex; align-items: center; white-space: nowrap; border: 1px solid #c9e0e1; background: #f5fbfb; color: #2d6f72; font-weight: 850; font-variant-numeric: tabular-nums;
}
.math-chip { min-height: 34px; padding: 0 11px; border-radius: 8px; font-size: 10px; }

.diagram-grid {
  padding: 18px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  align-items: start;
}
.diagram-grid.single { grid-template-columns: minmax(0, 680px); justify-content: center; }
.math-card { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 11px; background: #fff; }
.math-card-head {
  min-height: 48px; padding: 8px 10px 8px 12px; display: flex; justify-content: space-between; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--line); background: #fff;
}
.math-card-head > div:first-child { display: grid; gap: 2px; }
.math-card-head span { color: #829598; font-size: 8px; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; }
.math-card-head strong { color: #284d50; font-size: 11px; }
.card-actions { display: flex; align-items: center; gap: 6px; }
.angle-badge { min-height: 28px; padding: 0 8px; border-radius: 7px; font-size: 9px !important; letter-spacing: 0 !important; text-transform: none !important; }
.icon-button {
  width: 30px; height: 30px; display: grid; place-items: center; border: 0; border-radius: 8px;
  background: transparent; color: #648084; cursor: pointer; font-size: 15px;
}
.icon-button:hover { background: #f2f7f7; color: var(--teal-dark); }

.triangle-svg {
  display: block; width: 100%; height: auto; min-height: 300px;
  background-color: #fbfdfd;
  background-image:
    linear-gradient(#e9f0f1 1px, transparent 1px),
    linear-gradient(90deg, #e9f0f1 1px, transparent 1px);
  background-size: 22px 22px;
  touch-action: pan-y pinch-zoom;
  overscroll-behavior: auto;
  user-select: none;
}
.triangle-fill { fill: rgba(10,146,148,.085); }
.edge { fill: none; stroke-width: 3.2; stroke-linecap: round; }
.edge-a { stroke: #079093; }
.edge-b { stroke: #146cc8; }
.edge-c { stroke: #78969a; }
.angle-arc { fill: none; stroke: #63aeb0; stroke-width: 2; }
.angle-text, .side-label, .vertex-name { paint-order: stroke; stroke: #fbfdfd; stroke-width: 4px; stroke-linejoin: round; }
.angle-text { fill: #39777a; font-size: 12px; font-weight: 850; }
.side-label { fill: #1e658f; font-size: 11px; font-weight: 850; text-anchor: middle; }
.vertex-name { fill: #173e42; font-size: 12px; font-weight: 900; }
.vertex { vector-effect: non-scaling-stroke; }
.vertex.fixed { fill: #1c4d51; stroke: #1c4d51; }
.drag-hit { fill: transparent; stroke: transparent; pointer-events: all; cursor: grab; touch-action: none; }
.vertex.drag-handle { fill: #fff; stroke: var(--teal); stroke-width: 3; cursor: grab; pointer-events: none; }
.vertex.drag-handle:hover { fill: #f4ffff; }
.vertex.drag-handle:active { cursor: grabbing; }
.vertex.drag-handle:focus-visible { outline: none; filter: drop-shadow(0 0 4px rgba(10,146,148,.45)); }

.metric-row { display: grid; grid-template-columns: 1.45fr 1.75fr 1fr 1fr; border-top: 1px solid var(--line); }
.metric-row > div { min-width: 0; padding: 9px 10px; display: grid; gap: 3px; border-right: 1px solid var(--line); }
.metric-row > div:last-child { border-right: 0; }
.metric-row span { color: #839699; font-size: 8px; font-weight: 850; letter-spacing: .05em; text-transform: uppercase; }
.metric-row strong { overflow: hidden; text-overflow: ellipsis; color: #35585c; font-size: 9px; font-weight: 800; white-space: nowrap; font-variant-numeric: tabular-nums; }
.math-card.is-edited .math-card-head { background: #fbfefe; }
.math-card.is-edited .angle-badge { background: #fff8e9; border-color: #eadba8; color: #795f20; }

.canvas-note {
  margin: 0 18px 18px; min-height: 36px; padding: 8px 12px;
  display: flex; align-items: center; gap: 8px; border-radius: 8px; background: #f6f9f9; color: #6e8588; font-size: 9px;
}
.canvas-note .icon { color: var(--teal); font-size: 14px; }
.empty-state { min-height: 360px; padding: 40px 20px; display: grid; place-items: center; align-content: center; gap: 10px; text-align: center; color: #7e9295; }
.empty-state .icon { width: 32px; height: 32px; color: #a4b7b9; }
.empty-state strong { color: #3b5d60; font-size: 14px; }
.empty-state span { max-width: 420px; font-size: 11px; line-height: 1.5; }

#parameter, #hasil { scroll-margin-top: 82px; }
.mobile-nav { display: none; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

.footer { padding: 0 16px 24px; color: #819598; font-size: 9px; }
.footer-inner { width: min(100%, 1380px); margin: 0 auto; display: flex; align-items: center; justify-content: center; gap: 7px; text-align: center; line-height: 1.5; }
.footer-inner span { white-space: nowrap; }
.footer-separator { color: #b0bec0; }

.fatal-wrap { min-height: 100vh; padding: 24px; display: grid; place-items: center; background: var(--bg); }
.fatal-card { width: min(100%, 420px); padding: 28px; border: 1px solid var(--line); border-radius: 14px; background: #fff; box-shadow: var(--shadow); text-align: center; }
.fatal-icon { width: 44px; height: 44px; margin: 0 auto 12px; display: grid; place-items: center; border-radius: 12px; background: #fff1f3; color: var(--danger); font-size: 22px; }
.fatal-card h1 { margin-bottom: 8px; }
.fatal-card p { margin: 0 0 18px; color: var(--muted); font-size: 12px; line-height: 1.55; }
.fatal-link { display: inline-flex; height: 38px; padding: 0 14px; align-items: center; justify-content: center; border-radius: 8px; background: var(--teal); color: #fff; text-decoration: none; font-size: 11px; font-weight: 800; }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 290px minmax(0,1fr); }
  .diagram-grid { grid-template-columns: 1fr; }
  .diagram-grid.single { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  body { padding-bottom: calc(78px + env(safe-area-inset-bottom)); }
  .topbar-inner { grid-template-columns: 1fr auto; }
  .page-name { justify-self: end; }
  .topbar-spacer { display: none; }
  .app-shell { display: block; }
  .sidebar { position: static; margin-bottom: 14px; }
  .diagram-grid { padding: 12px; }
  .workspace-toolbar { min-height: 68px; }
  #parameter, #hasil { scroll-margin-top: 74px; }
  .mobile-nav {
    position: fixed;
    z-index: 40;
    left: 50%;
    bottom: calc(10px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    width: min(360px, calc(100% - 24px));
    min-height: 58px;
    padding: 5px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
    border: 1px solid rgba(197, 218, 220, .95);
    border-radius: 17px;
    background: rgba(255,255,255,.96);
    box-shadow: 0 12px 34px rgba(22,55,59,.16);
    backdrop-filter: blur(14px);
  }
  .mobile-nav-link {
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 12px;
    border: 0;
    background: transparent;
    color: #71878a;
    text-decoration: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 11px;
    font-weight: 850;
    transition: background .18s ease, color .18s ease, transform .18s ease;
  }
  .mobile-nav-link .icon { width: 18px; height: 18px; }
  .mobile-nav-link.is-active { color: var(--teal-dark); background: var(--teal-soft); }
  .mobile-nav-link:active { transform: scale(.98); }
  .footer { padding-bottom: 12px; }
  .footer-inner { flex-wrap: wrap; gap: 3px 6px; }
  .footer-separator { display: none; }
}
@media (max-width: 560px) {
  .topbar { height: 62px; }
  .topbar-inner { width: min(100% - 20px, 1380px); }
  .brand-text small { display: none; }
  .page-name { font-size: 11px; }
  .app-shell { width: min(100% - 20px, 1380px); margin-top: 10px; }
  .field-grid { grid-template-columns: 1fr 1fr; }
  .count-presets { gap: 5px; }
  .count-pill { height: 40px; }
  .custom-count { grid-template-columns: auto 62px 1fr; }
  .workspace-toolbar { align-items: flex-start; }
  .math-chip { display: none; }
  .diagram-grid { gap: 10px; }
  .triangle-svg { min-height: 250px; }
  .metric-row { grid-template-columns: 1fr 1fr; }
  .metric-row > div:nth-child(2) { border-right: 0; }
  .metric-row > div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .canvas-note { margin: 0 12px 12px; }
}
