:root {
  color-scheme: light;
  --background: #f7faff;
  --surface: #ffffff;
  --surface-muted: #eef5fc;
  --text: #152235;
  --text-muted: #66758a;
  --border: #dce7f2;
  --blue: #1769aa;
  --blue-dark: #0e4f83;
  --blue-soft: #e2f0fc;
  --shadow: 0 18px 45px rgba(29, 77, 115, 0.1);
  --diagram-line: #718096;
  --diagram-eps-c: #218653;
  --diagram-eps-d: #7953a6;
  --diagram-c: #c2413b;
  --diagram-fr: #1769aa;
  --diagram-lcr: #b45309;
  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "SFMono-Regular", Consolas, monospace;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --background: #0d141c;
  --surface: #141e29;
  --surface-muted: #1a2a39;
  --text: #f1f6fb;
  --text-muted: #9eafc0;
  --border: #293b4c;
  --blue: #5aabeb;
  --blue-dark: #86c5f3;
  --blue-soft: #183950;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.25);
  --diagram-line: #aab9c8;
  --diagram-eps-c: #8fe3a0;
  --diagram-eps-d: #d3a1ff;
  --diagram-c: #ff8a80;
  --diagram-fr: #6fd6ff;
  --diagram-lcr: #f2a35c;
}

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

html {
  min-width: 320px;
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.6;
  transition: background-color 0.25s ease, color 0.25s ease;
}

button,
input {
  font: inherit;
}

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

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 3px;
}

header,
main {
  width: min(calc(100% - 40px), 1120px);
  margin-inline: auto;
}

header {
  padding-block: 32px 20px;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo {
  color: var(--text);
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.07em;
  text-decoration: none;
  transition: color 0.2s ease;
}

.logo span { color: var(--blue); }

.logo:hover { color: var(--blue); }

.theme-toggle {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 1.1rem;
  transition: border-color 0.2s ease, background-color 0.2s ease, transform 0.2s ease;
}

.theme-toggle:hover {
  border-color: var(--blue);
  background: var(--surface-muted);
  transform: rotate(12deg);
}

header h1 {
  margin: 0;
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  line-height: 1.15;
  letter-spacing: -0.05em;
}

header p {
  max-width: 68ch;
  margin: 12px 0 0;
  color: var(--text-muted);
}

main {
  display: grid;
  grid-template-columns: minmax(300px, 0.72fr) minmax(0, 1.6fr);
  align-items: start;
  gap: 20px;
  padding-bottom: 48px;
}

.panel {
  min-width: 0;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 650;
}

.field label .hint {
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 400;
}

.field input {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--background);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  transition: border-color 0.2s ease, background-color 0.25s ease, color 0.25s ease;
}

.field input:focus {
  border-color: var(--blue);
  outline: none;
}

.slider-control {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}

.slider-control input[type="range"] {
  flex: 1;
  width: auto;
  min-width: 0;
  padding: 0;
  accent-color: var(--blue);
  cursor: pointer;
}

.slider-control output {
  width: 5.5rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-align: right;
}

.add-point-button,
.remove-point-button {
  width: auto;
}

button:not(.theme-toggle) {
  min-height: 42px;
  padding: 9px 14px;
  border: 1px solid var(--blue);
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 650;
  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

button:not(.theme-toggle):hover {
  border-color: var(--blue-dark);
  background: var(--blue-dark);
}

button:not(.theme-toggle):focus-visible {
  outline-color: var(--blue);
}

.panel .add-point-button {
  margin: 0 0 12px;
  background: var(--surface);
  color: var(--blue);
}

.panel .add-point-button:hover {
  background: var(--blue-soft);
}

.strain-point-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.strain-point-row .field {
  flex: 1;
  min-width: 0;
}

.panel .remove-point-button {
  margin-bottom: 16px;
  border-color: var(--border);
  background: var(--surface);
  color: var(--text-muted);
}

.panel .remove-point-button:hover {
  border-color: var(--blue);
  background: var(--surface-muted);
  color: var(--text);
}

.results {
  margin: 18px 0;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.8;
}

.results span {
  color: var(--text-muted);
}

#error {
  min-height: 1.2em;
  margin-bottom: 8px;
  color: #b42318;
  font-size: 0.85rem;
}

:root[data-theme="dark"] #error {
  color: #ff9b92;
}

.download-note,
.citation {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.download-note {
  margin-top: 10px;
}

.diagram-panel {
  display: flex;
  flex-direction: column;
}

.diagram-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  font-weight: 650;
}

.diagram-hint {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 400;
}

.diagram-scroll {
  min-width: 0;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scrollbar-color: var(--border) transparent;
  scrollbar-width: thin;
}

svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.citation {
  margin-top: 12px;
  text-align: right;
}

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

.citation a:hover {
  text-decoration: underline;
}

@media (max-width: 820px) {
  main {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  header,
  main {
    width: min(calc(100% - 28px), 1120px);
  }

  header {
    padding-top: 22px;
  }

  .header-top {
    margin-bottom: 22px;
  }

  .panel {
    padding: 18px;
    border-radius: 12px;
  }

  .diagram-hint {
    font-size: 0.7rem;
    text-align: right;
  }

  .diagram-scroll svg {
    width: 500px;
    max-width: none;
  }
}

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