:root {
  --paper: #f3f0e8;
  --paper-deep: #e8e3d7;
  --ink: #19251e;
  --muted: #68736c;
  --line: #cbc8bd;
  --white: #fffef9;
  --green: #1d5c42;
  --green-dark: #113f2d;
  --lime: #d9f24b;
  --orange: #ee6b3b;
  --shadow: 0 24px 70px rgba(29, 43, 34, 0.11);
  font-family: "Noto Sans SC", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 78% 13%, rgba(217, 242, 75, 0.22), transparent 23rem),
    linear-gradient(rgba(25, 37, 30, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(25, 37, 30, 0.025) 1px, transparent 1px),
    var(--paper);
  background-size: auto, 30px 30px, 30px 30px, auto;
}

button,
textarea {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

.page-shell {
  width: min(1380px, calc(100% - 56px));
  margin: 0 auto;
}

.site-header {
  height: 90px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  border-bottom: 1px solid rgba(25, 37, 30, 0.18);
}

.brand {
  width: fit-content;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  font-family: "Noto Serif SC", serif;
  font-weight: 700;
  font-size: 21px;
  text-decoration: none;
  letter-spacing: 0.06em;
}

.brand-mark {
  position: relative;
  width: 31px;
  height: 31px;
  display: inline-block;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
}

.brand-mark::after {
  content: "";
  position: absolute;
  top: 14px;
  left: 5px;
  width: 19px;
  height: 1px;
  background: var(--ink);
  transform: rotate(-22deg);
}

.brand-mark span {
  position: absolute;
  z-index: 1;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--ink);
}

.brand-mark span:nth-child(1) { left: 5px; top: 18px; }
.brand-mark span:nth-child(2) { left: 13px; top: 12px; background: var(--orange); }
.brand-mark span:nth-child(3) { right: 5px; top: 7px; }

.header-note {
  font: 500 10px/1 "DM Mono", monospace;
  letter-spacing: 0.24em;
  color: var(--muted);
}

.header-link {
  justify-self: end;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid var(--ink);
  padding-bottom: 4px;
}

.header-link span {
  display: inline-block;
  margin-left: 4px;
  color: var(--orange);
}

.hero {
  padding: 80px 0 58px;
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  align-items: end;
  gap: 80px;
}

.eyebrow,
.kicker {
  font: 500 11px/1 "DM Mono", monospace;
  letter-spacing: 0.17em;
  color: var(--green);
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 21px;
}

.eyebrow span {
  width: 34px;
  height: 2px;
  background: var(--orange);
}

.hero h1 {
  margin: 0;
  max-width: 820px;
  font-family: "Noto Serif SC", serif;
  font-weight: 700;
  font-size: clamp(52px, 6vw, 84px);
  line-height: 1.16;
  letter-spacing: -0.045em;
}

.hero h1 .accent {
  position: relative;
  color: var(--green);
  white-space: nowrap;
}

.hero h1 .accent::after {
  content: "";
  position: absolute;
  height: 9px;
  left: 0.06em;
  right: 0;
  bottom: 0.01em;
  z-index: -1;
  background: var(--lime);
  transform: rotate(-1.5deg);
  border-radius: 100%;
}

.hero > p {
  margin: 0 0 10px;
  max-width: 480px;
  color: #58635c;
  font-size: 16px;
  line-height: 2;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(330px, 0.78fr) minmax(520px, 1.22fr);
  align-items: start;
  border: 1px solid rgba(25, 37, 30, 0.22);
  border-radius: 4px;
  background: var(--white);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel {
  padding: 39px 42px;
}

.input-panel {
  height: 100%;
  background: #ece8dd;
  border-right: 1px solid rgba(25, 37, 30, 0.16);
}

.panel-heading {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 29px;
}

.panel-heading .kicker {
  margin: 0 0 7px;
  color: #7d847f;
}

.panel-heading h2 {
  margin: 0;
  font-family: "Noto Serif SC", serif;
  font-size: 23px;
  line-height: 1;
}

.step-number {
  width: 41px;
  height: 41px;
  display: grid;
  place-items: center;
  border: 1px solid #919790;
  border-radius: 50%;
  font: 500 11px/1 "DM Mono", monospace;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  margin-bottom: 26px;
  background: #dcd8cd;
  border-radius: 3px;
}

.mode-button {
  border: 0;
  border-radius: 2px;
  padding: 10px 12px;
  background: transparent;
  font-size: 13px;
  color: #747b76;
  cursor: pointer;
  transition: 160ms ease;
}

.mode-button.active {
  background: var(--white);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 5px rgba(25, 37, 30, 0.1);
}

.field-label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}

.field-label-row label {
  font-size: 13px;
  font-weight: 600;
}

.field-label-row span {
  font: 400 10px/1 "DM Mono", monospace;
  color: #79807b;
}

textarea {
  display: block;
  width: 100%;
  min-height: 172px;
  resize: vertical;
  padding: 18px;
  border: 1px solid #aaa99f;
  border-radius: 3px;
  outline: none;
  background: var(--white);
  color: var(--ink);
  font: 500 16px/1.8 "DM Mono", monospace;
  transition: border-color 150ms, box-shadow 150ms;
}

textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(29, 92, 66, 0.09);
}

textarea.invalid {
  border-color: #b8472c;
}

.input-hint,
.input-error {
  margin: 9px 0 0;
  color: #747b76;
  font-size: 11px;
  line-height: 1.6;
}

.input-error {
  display: none;
  color: #b8472c;
}

.input-error.visible {
  display: block;
}

.preset-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  margin: 24px 0 25px;
}

.preset-row > span {
  margin-right: 2px;
  color: #737a75;
  font-size: 11px;
}

.preset {
  padding: 5px 9px;
  border: 1px solid #c3c0b6;
  border-radius: 20px;
  background: transparent;
  color: #59615b;
  font-size: 11px;
  cursor: pointer;
}

.preset:hover {
  border-color: var(--green);
  color: var(--green);
}

.calculate-button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 18px 15px 21px;
  border: 0;
  border-radius: 3px;
  color: #fff;
  background: var(--green);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 9px 24px rgba(29, 92, 66, 0.2);
  transition: transform 150ms, background 150ms;
}

.calculate-button:hover {
  background: var(--green-dark);
  transform: translateY(-1px);
}

.button-arrow {
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--ink);
  background: var(--lime);
  font-size: 18px;
}

.result-heading {
  position: relative;
  margin-bottom: 24px;
}

.degree-badge {
  margin-left: auto;
  padding: 7px 11px;
  border: 1px solid #ccd1cb;
  border-radius: 20px;
  color: var(--green);
  background: #f5f7ee;
  font-size: 11px;
  font-weight: 600;
}

.formula-card {
  padding: 22px 23px 20px;
  margin-bottom: 19px;
  border-left: 3px solid var(--orange);
  background: #f2f0e9;
}

.formula-label,
.chart-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #7a817c;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.copy-button {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  color: #68716b;
  font-size: 11px;
  cursor: pointer;
}

.copy-icon {
  position: relative;
  width: 12px;
  height: 13px;
  display: inline-block;
  border: 1px solid currentColor;
  border-radius: 1px;
}

.copy-icon::before {
  content: "";
  position: absolute;
  width: 8px;
  height: 9px;
  top: -4px;
  left: -4px;
  border: 1px solid currentColor;
  border-radius: 1px;
  background: #f2f0e9;
}

.formula {
  min-height: 51px;
  display: flex;
  align-items: center;
  padding-top: 8px;
  overflow-x: auto;
  color: var(--green-dark);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(25px, 3.1vw, 39px);
  line-height: 1.3;
  white-space: nowrap;
}

.formula i,
.lagrange-formula i {
  font-family: Georgia, serif;
  font-style: italic;
}

.formula sup {
  margin-left: 1px;
  font-size: 0.55em;
}

.decimal-formula {
  display: none;
  margin: 6px 0 0;
  color: #858b87;
  font: 400 10px/1.5 "DM Mono", monospace;
}

.decimal-formula.visible {
  display: block;
}

.chart-card {
  border: 1px solid #deddd6;
  border-radius: 3px;
  overflow: hidden;
}

.chart-topline {
  padding: 13px 16px;
  border-bottom: 1px solid #e4e2dc;
}

.legend {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #8a908c;
  font-size: 9px;
  font-weight: 400;
  letter-spacing: 0;
}

.legend i {
  width: 16px;
  height: 2px;
  background: var(--orange);
}

.legend b {
  width: 6px;
  height: 6px;
  margin-left: 5px;
  border-radius: 50%;
  background: var(--green);
}

.chart-wrap {
  position: relative;
  width: 100%;
  height: 228px;
  background: #fff;
}

#plot {
  display: block;
  width: 100%;
  height: 100%;
}

.chart-tooltip {
  position: absolute;
  z-index: 2;
  display: none;
  pointer-events: none;
  padding: 6px 8px;
  border-radius: 2px;
  color: white;
  background: var(--ink);
  font: 400 10px/1.4 "DM Mono", monospace;
  white-space: nowrap;
  transform: translate(-50%, calc(-100% - 10px));
}

.result-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-top: 18px;
}

.text-button {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--green);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.text-button span {
  display: inline-block;
  margin-left: 4px;
  transition: transform 180ms;
}

.text-button[aria-expanded="true"] span {
  transform: rotate(45deg);
}

#verification-status {
  color: #778079;
  font-size: 10px;
}

#verification-status i {
  width: 17px;
  height: 17px;
  display: inline-grid;
  place-items: center;
  margin-right: 5px;
  border-radius: 50%;
  color: #fff;
  background: var(--green);
  font-style: normal;
}

.details {
  margin-top: 22px;
  padding-top: 22px;
  border-top: 1px solid #dddcd5;
}

.details[hidden] {
  display: none;
}

.detail-block + .detail-block {
  margin-top: 24px;
}

.detail-block h3 {
  margin: 0 0 12px;
  font-size: 12px;
}

.lagrange-formula {
  overflow-x: auto;
  padding: 15px;
  color: #374139;
  background: #f4f2ec;
  font: 400 14px/1.7 Georgia, serif;
  white-space: nowrap;
}

.fraction-inline {
  display: inline-flex;
  flex-direction: column;
  vertical-align: middle;
  align-items: center;
  margin: 0 4px;
  line-height: 1.2;
}

.fraction-inline span:first-child {
  padding: 0 3px 2px;
  border-bottom: 1px solid currentColor;
}

.fraction-inline span:last-child {
  padding-top: 2px;
}

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font: 400 11px/1.4 "DM Mono", monospace;
}

th,
td {
  padding: 8px 10px;
  border: 1px solid #deddd6;
  text-align: center;
  white-space: nowrap;
}

th {
  color: var(--green);
  background: #f4f2ec;
  font-weight: 500;
}

.explanation {
  display: grid;
  grid-template-columns: 0.7fr 1.3fr;
  gap: 80px;
  padding: 105px 3% 95px;
}

.explanation-title .kicker {
  margin: 0 0 17px;
}

.explanation-title h2 {
  margin: 0;
  font-family: "Noto Serif SC", serif;
  font-size: clamp(30px, 3vw, 43px);
}

.explanation-copy p {
  max-width: 700px;
  margin: 0;
  color: #5e6961;
  font-size: 15px;
  line-height: 2;
}

.principle-formula {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 32px;
  color: var(--green-dark);
  font: 400 clamp(20px, 2.4vw, 31px)/1.2 Georgia, serif;
}

.sum-symbol,
.product-symbol {
  font-size: 1.9em;
}

.product-group,
.fraction {
  display: flex;
  align-items: center;
}

.fraction {
  flex-direction: column;
  font-size: 0.62em;
}

.fraction i {
  width: 100%;
  height: 1px;
  margin: 3px 0;
  background: currentColor;
}

footer {
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid rgba(25, 37, 30, 0.18);
  color: #737b75;
  font-size: 11px;
}

@media (max-width: 900px) {
  .page-shell { width: min(100% - 30px, 720px); }
  .site-header { grid-template-columns: 1fr 1fr; }
  .header-note { display: none; }
  .hero { grid-template-columns: 1fr; gap: 28px; padding-top: 62px; }
  .hero > p { max-width: 620px; }
  .workspace { grid-template-columns: 1fr; }
  .input-panel { border-right: 0; border-bottom: 1px solid rgba(25, 37, 30, 0.16); }
  .explanation { grid-template-columns: 1fr; gap: 30px; padding-inline: 0; }
}

@media (max-width: 560px) {
  .page-shell { width: calc(100% - 20px); }
  .site-header { height: 72px; }
  .header-link { font-size: 11px; }
  .hero { padding: 52px 6px 40px; }
  .hero h1 { font-size: clamp(42px, 13vw, 62px); }
  .hero > p { font-size: 14px; }
  .panel { padding: 30px 21px; }
  .result-heading { align-items: flex-start; }
  .degree-badge { position: absolute; right: 0; top: 7px; }
  .formula-card { padding-inline: 16px; }
  .chart-wrap { height: 205px; }
  .result-actions { align-items: flex-start; }
  .explanation { padding: 72px 7px; }
  footer { padding-inline: 5px; }
  footer span:last-child { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; }
}
