:root {
  --bg: #07090e;
  --panel: rgba(18, 23, 33, 0.82);
  --panel-solid: #111620;
  --panel-raised: #151c28;
  --line: rgba(255, 255, 255, 0.075);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #e9edf5;
  --muted: #929bad;
  --faint: #5c6578;
  --accent: #f0b45c;
  --accent-strong: #ffca7a;
  --accent-soft: rgba(240, 180, 92, 0.12);
  --teal: #79cbb9;
  --teal-soft: rgba(121, 203, 185, 0.12);
  --danger: #d98a8a;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Songti SC", "Noto Serif SC", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button,
input,
output {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.is-hidden {
  display: none !important;
}

.glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(120px);
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
}

.glow-a {
  width: 620px;
  height: 620px;
  top: -260px;
  left: -160px;
  background: radial-gradient(circle, rgba(240, 180, 92, 0.16), transparent 68%);
}

.glow-b {
  width: 700px;
  height: 700px;
  right: -280px;
  bottom: -320px;
  background: radial-gradient(circle, rgba(121, 203, 185, 0.12), transparent 68%);
}

.app {
  position: relative;
  z-index: 1;
  width: min(1220px, calc(100% - 48px));
  margin: 0 auto;
  padding-bottom: 36px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 0;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  font-family: var(--serif);
  font-size: 30px;
  line-height: 1;
  color: var(--accent);
  text-shadow: 0 0 28px rgba(240, 180, 92, 0.4);
}

.brand-name {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.brand-sub {
  padding-left: 12px;
  margin-left: 2px;
  border-left: 1px solid var(--line-strong);
  color: var(--faint);
  font-size: 12px;
  letter-spacing: 0.14em;
}

.tabbar {
  position: relative;
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.tab {
  position: relative;
  z-index: 1;
  padding: 8px 20px;
  background: transparent;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.02em;
  transition: color 0.25s ease;
}

.tab:hover {
  color: var(--text);
}

.tab.is-active {
  color: #1a1409;
}

.tab-glider {
  position: absolute;
  z-index: 0;
  top: 4px;
  left: 4px;
  height: calc(100% - 8px);
  width: 96px;
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  border-radius: 999px;
  box-shadow: 0 4px 18px rgba(240, 180, 92, 0.28);
  transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1), width 0.32s cubic-bezier(0.4, 0, 0.2, 1);
}

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
  padding: 46px 0 38px;
}

.kicker {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.28em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(30px, 4vw, 44px);
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: 0.01em;
}

.hero-sub {
  max-width: 540px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.hero-pi {
  flex: none;
  font-family: var(--serif);
  font-size: clamp(120px, 16vw, 200px);
  line-height: 0.8;
  color: transparent;
  background: linear-gradient(180deg, rgba(240, 180, 92, 0.18), rgba(240, 180, 92, 0.01));
  -webkit-background-clip: text;
  background-clip: text;
  user-select: none;
  padding-right: 12px;
}

.view {
  display: none;
  animation: rise 0.45s ease both;
}

.view.is-active {
  display: block;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.panel {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
}

.panel-label {
  margin: 0 0 14px;
  color: var(--faint);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.exact-grid {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.controls {
  padding: 24px;
}

.method-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 26px;
}

.method {
  display: block;
  width: 100%;
  padding: 13px 15px;
  text-align: left;
  background: rgba(255, 255, 255, 0.022);
  border: 1px solid var(--line);
  border-radius: 12px;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.method:hover {
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.04);
}

.method.is-active {
  border-color: rgba(240, 180, 92, 0.45);
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

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

.method-name {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.method-meta {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 10.5px;
}

.method.is-active .method-meta {
  color: rgba(240, 180, 92, 0.8);
}

.method-desc {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.method.is-active .method-desc {
  color: rgba(233, 237, 245, 0.75);
}

.field {
  margin-bottom: 18px;
}

.field-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}

.field-head label {
  color: var(--muted);
  font-size: 12.5px;
}

.field-head output {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 13px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  margin: 8px 0;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: var(--accent);
  border: 3px solid #1a1206;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(240, 180, 92, 0.55), 0 0 16px rgba(240, 180, 92, 0.35);
  transition: transform 0.15s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.12);
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--accent);
  border: 3px solid #1a1206;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(240, 180, 92, 0.55);
}

.scale {
  display: flex;
  justify-content: space-between;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: 1px solid transparent;
  border-radius: 11px;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  width: 100%;
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  color: #191204;
  box-shadow: 0 12px 30px rgba(240, 180, 92, 0.2);
}

.btn-primary:hover {
  box-shadow: 0 16px 36px rgba(240, 180, 92, 0.3);
}

.btn:disabled {
  cursor: wait;
  opacity: 0.7;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--line-strong);
  color: var(--muted);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.btn-small {
  padding: 7px 14px;
  border-radius: 9px;
  font-size: 12px;
}

.spinner {
  display: none;
  width: 13px;
  height: 13px;
  border: 2px solid rgba(25, 18, 4, 0.25);
  border-top-color: #191204;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.btn.is-busy .spinner {
  display: block;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.hint {
  margin: 14px 0 0;
  color: var(--faint);
  font-size: 11.5px;
  line-height: 1.65;
}

.result-column {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

.result {
  padding: 26px 28px 24px;
}

.result-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.result-title {
  min-width: 0;
}

.result .panel-label {
  margin-bottom: 8px;
}

.pi-value {
  font-family: var(--mono);
  font-size: clamp(22px, 2.8vw, 34px);
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: 0.02em;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  font-variant-numeric: tabular-nums;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 20px 0 22px;
}

.chip {
  min-width: 108px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.chips-3 .chip {
  flex: 1;
  min-width: 0;
}

.chip-label {
  display: block;
  color: var(--faint);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chip b {
  display: block;
  margin-top: 2px;
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 500;
  color: var(--accent-strong);
}

.digit-block {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.digit-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
  color: var(--faint);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.digit-head span:last-child {
  font-family: var(--mono);
  letter-spacing: 0;
  text-transform: none;
  color: var(--muted);
}

.digits {
  max-height: 252px;
  overflow-y: auto;
  padding-right: 10px;
  font-family: var(--mono);
  font-size: 14.5px;
  line-height: 2;
  letter-spacing: 0.12em;
  word-break: break-all;
}

.digits::-webkit-scrollbar {
  width: 6px;
}

.digits::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 99px;
}

.digits .int {
  color: var(--accent);
}

.digits .ok {
  color: var(--text);
}

.digits .bad {
  color: rgba(217, 138, 138, 0.62);
}

.digits-placeholder {
  color: var(--faint);
  font-family: var(--sans);
  letter-spacing: 0;
}

.lower-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: 20px;
}

.verify-panel,
.history-panel {
  padding: 22px 24px;
}

.verify-title {
  margin: 0 0 14px;
  font-family: var(--mono);
  font-size: 16px;
  color: var(--text);
}

.verify-track {
  height: 5px;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 999px;
  overflow: hidden;
}

.verify-track span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--accent));
  border-radius: 999px;
  transition: width 0.6s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.verify-note {
  margin: 11px 0 0;
  color: var(--faint);
  font-size: 11.5px;
}

.history {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.055);
  font-size: 12px;
}

.history li:last-child {
  border-bottom: 0;
}

.history .h-method {
  color: var(--muted);
}

.history .h-digits {
  font-family: var(--mono);
  color: var(--faint);
  font-size: 11px;
}

.history .h-time {
  margin-left: auto;
  font-family: var(--mono);
  color: var(--accent);
  font-size: 11px;
}

.history-empty {
  border-bottom: 0 !important;
  color: var(--faint);
  font-size: 12px;
}

.monte-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: 20px;
  align-items: start;
}

.canvas-panel {
  padding: 24px;
}

.canvas-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.canvas-head .panel-label {
  margin-bottom: 12px;
}

.canvas-note {
  margin: 0;
  color: var(--faint);
  font-size: 11.5px;
}

.canvas-wrap {
  position: relative;
  margin: 6px 0 16px;
  border-radius: 14px;
  overflow: hidden;
  background: radial-gradient(circle at 30% 25%, rgba(240, 180, 92, 0.05), transparent 60%), #0a0e15;
  border: 1px solid var(--line);
}

#monteCanvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
}

.axis-label {
  position: absolute;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 10px;
}

.axis-x {
  right: 8px;
  bottom: 6px;
}

.axis-y {
  left: 8px;
  top: 6px;
}

.canvas-legend {
  display: flex;
  align-items: center;
  gap: 18px;
  color: var(--muted);
  font-size: 11.5px;
}

.canvas-legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.dot-in {
  background: var(--accent);
  box-shadow: 0 0 10px rgba(240, 180, 92, 0.5);
}

.dot-out {
  background: #55617a;
}

.legend-formula {
  margin-left: auto;
  font-family: var(--mono);
  color: var(--faint);
  letter-spacing: 0.03em;
}

.monte-side {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.estimate-panel {
  padding: 24px 26px;
}

.monte-value {
  font-size: clamp(34px, 5vw, 52px);
  letter-spacing: 0.01em;
  color: var(--accent-strong);
}

.chart-panel {
  padding: 22px 24px 16px;
}

.chart-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.chart-head .panel-label {
  margin-bottom: 10px;
}

.chart-note {
  color: var(--faint);
  font-size: 10.5px;
}

#errorChart {
  display: block;
  width: 100%;
  height: auto;
}

.monte-controls {
  padding: 22px 24px;
}

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn-row .btn-primary {
  width: auto;
}

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 34px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 11px;
  letter-spacing: 0.04em;
}

.footer-ref {
  font-family: var(--mono);
}

@media (max-width: 980px) {
  .exact-grid,
  .monte-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .hero {
    padding-top: 34px;
  }

  .hero-pi {
    font-size: 110px;
  }

  .method-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .method-desc {
    display: none;
  }
}

@media (max-width: 720px) {
  .app {
    width: calc(100% - 28px);
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 14px;
  }

  .hero {
    padding: 28px 0 24px;
  }

  .hero-pi {
    display: none;
  }

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

  .method-list {
    grid-template-columns: 1fr;
  }

  .method-desc {
    display: block;
  }

  .lower-grid {
    grid-template-columns: 1fr;
  }

  .result {
    padding: 20px;
  }

  .pi-value {
    font-size: 21px;
  }

  .chips {
    gap: 8px;
  }

  .chip {
    flex: 1;
    min-width: 0;
  }

  .canvas-legend {
    flex-wrap: wrap;
    gap: 10px 16px;
  }

  .legend-formula {
    margin-left: 0;
    width: 100%;
  }

  .footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
