:root {
  --ink: #17211f;
  --muted: #5e6d68;
  --panel: #ffffff;
  --paper: #f4f1e8;
  --line: #d2d9d5;
  --accent: #087f8c;
  --accent-strong: #075f69;
  --gold: #d9a61b;
  --rose: #bd6a4d;
  --green: #637e48;
  --white: #edf1ee;
  --shadow: 0 20px 60px rgba(23, 33, 31, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #e9eeee;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(233, 238, 238, 0.92)),
    #e9eeee;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: 32px 16px 48px;
}

.tool {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(320px, 0.68fr);
  gap: 18px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.diagram-panel,
.control-panel,
.reference-panel {
  min-width: 0;
  padding: 22px;
}

.heading {
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 0.76rem;
  font-weight: 900;
  line-height: 1.1;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  color: var(--ink);
  line-height: 1;
}

h1 {
  font-size: clamp(2.1rem, 5vw, 4.6rem);
}

h2 {
  font-size: 1.45rem;
}

.control-row,
.karat-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.system-button,
.karat-button,
.download-button {
  min-height: 40px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 850;
}

.system-button:hover,
.karat-button:hover,
.download-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.system-button.is-active,
.karat-button.is-active {
  border-color: var(--accent);
  background: #e8f6f7;
  color: var(--accent-strong);
}

.download-button {
  margin-left: auto;
}

.plot-card {
  min-width: 0;
  margin-top: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(8, 127, 140, 0.09) 1px, transparent 1px),
    linear-gradient(0deg, rgba(8, 127, 140, 0.08) 1px, transparent 1px),
    #f8faf9;
  background-size: 24px 24px;
}

.ternary-plot {
  position: relative;
  width: 100%;
  min-width: 0;
  aspect-ratio: 760 / 640;
  min-height: 280px;
  overflow: hidden;
}

#alloy-canvas,
#alloy-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#alloy-overlay {
  overflow: hidden;
}

.triangle-border {
  fill: none;
  stroke: #101917;
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
}

.grid-line {
  stroke: rgba(23, 33, 31, 0.26);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.axis-label {
  fill: var(--ink);
  font-size: 27px;
  font-weight: 900;
  text-anchor: middle;
}

.axis-sub {
  fill: var(--muted);
  font-size: 16px;
  font-weight: 800;
  text-anchor: middle;
}

.tick-label {
  fill: rgba(23, 33, 31, 0.72);
  font-size: 12px;
  font-weight: 800;
  text-anchor: middle;
}

.region-label {
  fill: rgba(23, 33, 31, 0.86);
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.78);
  stroke-width: 4px;
  font-size: 18px;
  font-weight: 900;
  text-anchor: middle;
}

.karat-band {
  fill: rgba(8, 127, 140, 0.12);
  stroke: rgba(8, 127, 140, 0.42);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

.karat-arc-highlight {
  fill: none;
  stroke: rgba(8, 127, 140, 0.16);
  stroke-width: 20;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.karat-arc {
  fill: none;
  stroke: rgba(23, 33, 31, 0.58);
  stroke-width: 2.5;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.karat-arc.is-active {
  stroke: var(--ink);
  stroke-width: 4;
}

.karat-line {
  stroke: rgba(23, 33, 31, 0.42);
  stroke-width: 1;
  stroke-dasharray: 4 5;
  opacity: 0.28;
  vector-effect: non-scaling-stroke;
}

.karat-line.is-active {
  stroke: rgba(23, 33, 31, 0.56);
  stroke-width: 1.5;
  opacity: 0.42;
}

.karat-tag rect {
  fill: var(--ink);
  rx: 6;
}

.karat-tag text {
  fill: #ffffff;
  font-size: 13px;
  font-weight: 900;
  text-anchor: middle;
  dominant-baseline: middle;
}

.alloy-marker {
  fill: #ffffff;
  stroke: var(--ink);
  stroke-width: 4;
  vector-effect: non-scaling-stroke;
}

.alloy-marker-inner {
  fill: var(--accent);
}

.hover-marker {
  fill: #ffffff;
  stroke: var(--rose);
  stroke-width: 3;
  opacity: 0;
  vector-effect: non-scaling-stroke;
}

.hover-marker.is-visible {
  opacity: 1;
}

.stack {
  display: grid;
  gap: 18px;
}

.slider-field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 850;
}

.slider-field input {
  width: 100%;
  accent-color: var(--accent);
}

.composition-readout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.composition-readout div,
.result-card,
.hover-card,
.slice-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.composition-readout div {
  padding: 12px;
}

.composition-readout .density-cell {
  grid-column: 1 / -1;
}

.composition-readout span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 850;
}

.composition-readout strong {
  display: block;
  margin-top: 3px;
  color: var(--ink);
  font-size: 1.24rem;
  line-height: 1.1;
}

.composition-readout small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.result-card,
.hover-card {
  padding: 14px;
}

.result-card p,
.hover-card p,
.method-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.93rem;
  font-weight: 700;
  line-height: 1.45;
}

.hover-card p {
  margin-top: 0;
}

.reference-panel {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.slice-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.slice-card {
  padding: 12px;
}

.slice-card h3 {
  margin: 0;
  color: var(--ink);
  font-size: 1.05rem;
}

.slice-card dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  margin: 10px 0 0;
  font-size: 0.88rem;
}

.slice-card dt {
  color: var(--muted);
  font-weight: 800;
}

.slice-card dd {
  margin: 0;
  color: var(--ink);
  font-weight: 850;
  text-align: right;
}

.method-note {
  max-width: 78ch;
}

@media (max-width: 940px) {
  .tool {
    grid-template-columns: 1fr;
  }

  .slice-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 16px 10px 32px;
  }

  .diagram-panel,
  .control-panel,
  .reference-panel {
    padding: 14px;
  }

  .plot-card {
    padding: 8px;
  }

  .ternary-plot {
    min-height: 330px;
  }

  .system-button,
  .karat-button,
  .download-button {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 38px;
    padding: 8px 10px;
    font-size: 0.84rem;
  }

  .control-row {
    display: grid;
    grid-template-columns: 1fr;
  }

  .download-button {
    margin-left: 0;
  }

  .karat-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .axis-label {
    font-size: 22px;
  }

  .axis-sub,
  .tick-label {
    font-size: 11px;
  }

  .region-label {
    font-size: 13px;
  }

  .composition-readout,
  .slice-list {
    grid-template-columns: 1fr;
  }
}
