:root {
  --bg: #eef2f4;
  --panel: #ffffff;
  --ink: #13212a;
  --muted: #5d6a72;
  --line: #d7dee2;
  --grid: #e7ecef;
  --heat: #d95f24;
  --heat-soft: #fbe8df;
  --conductivity: #1976a3;
  --conductivity-soft: #e2f1f7;
  --boundary: #34454f;
  --analytical: #151b20;
  --numerical: #b94379;
  --focus: #006ea6;
  --shadow: 0 8px 28px rgba(30, 50, 60, 0.08);
}

* { box-sizing: border-box; }

html { color-scheme: light; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}

button, input { font: inherit; }

button:focus-visible, input:focus-visible {
  outline: 3px solid rgba(0, 110, 166, 0.25);
  outline-offset: 2px;
}

.app-shell {
  width: min(1520px, 100%);
  margin: 0 auto;
  padding: 22px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 22px;
  margin-bottom: 16px;
}

.eyebrow, .panel-kicker {
  margin: 0 0 6px;
  color: #53636d;
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.12em;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 7px; font-size: clamp(1.55rem, 2.3vw, 2.25rem); letter-spacing: -0.025em; }
h2 { margin-bottom: 0; font-size: 1.1rem; }

.subtitle {
  max-width: 820px;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.48;
}

.header-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.button {
  min-height: 38px;
  border: 1px solid #c7d0d5;
  border-radius: 7px;
  padding: 8px 12px;
  background: white;
  color: var(--ink);
  cursor: pointer;
  font-weight: 650;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}
.button:hover { background: #f5f8f9; border-color: #aebbc2; }
.button:active { transform: translateY(1px); }
.button.primary { border-color: #246782; background: #246782; color: white; }
.button.primary:hover { background: #1e5870; }
.file-button { position: relative; display: inline-flex; align-items: center; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.control-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(126px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f9fbfc;
}

.control-strip label, .layer-readout label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 650;
}

input[type="number"] {
  display: block;
  width: 100%;
  min-height: 36px;
  margin-top: 5px;
  border: 1px solid #cbd5da;
  border-radius: 6px;
  padding: 6px 9px;
  background: white;
  color: var(--ink);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.model-panel, .result-panel { padding: 16px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.compact { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 12px; font-size: 0.74rem; color: var(--muted); }
.compact span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.result-heading-tools { display: flex; flex-direction: column; align-items: flex-end; gap: 9px; }
.method-button { border-color: #82949e; background: #f5f8f9; font-size: 0.76rem; }
.swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.swatch.heat { background: var(--heat); }
.swatch.conductivity { background: var(--conductivity); }
.swatch.boundary { height: 2px; background: var(--boundary); }
.line-key { width: 19px; height: 0; display: inline-block; border-top: 3px solid; }
.line-key.analytical { border-color: var(--analytical); }
.line-key.numerical { border-color: var(--numerical); border-top-style: dashed; }

.chart-wrap {
  width: 100%;
  height: clamp(410px, 52vh, 640px);
  min-height: 410px;
  border: 1px solid #e1e6e9;
  border-radius: 8px;
  overflow: hidden;
  background: #fbfcfd;
}
.chart { display: block; width: 100%; height: 100%; touch-action: none; user-select: none; }

.editor-toolbar { display: flex; gap: 8px; margin-top: 11px; }
.layer-readout {
  display: grid;
  grid-template-columns: minmax(125px, 1fr) minmax(120px, 0.85fr) minmax(120px, 0.85fr);
  gap: 10px;
  align-items: end;
  margin-top: 10px;
  padding: 10px;
  border-radius: 8px;
  background: #f5f8f9;
}
.layer-readout > div { align-self: center; }
.layer-readout span { display: block; color: var(--muted); font-size: 0.72rem; }
.layer-readout strong { display: block; margin-top: 3px; font-size: 1rem; }
.interaction-note { margin: 10px 2px 0; color: var(--muted); font-size: 0.78rem; line-height: 1.45; }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 11px;
}
.metrics > div { min-width: 0; padding: 10px; border: 1px solid #dce3e7; border-radius: 7px; background: #f8fafb; }
.metrics span { display: block; min-height: 29px; color: var(--muted); font-size: 0.7rem; line-height: 1.3; }
.metrics strong { display: block; margin-top: 3px; font-size: 0.95rem; white-space: nowrap; }
.method-note { display: grid; grid-template-columns: 130px 1fr; gap: 10px; margin-top: 10px; padding: 10px; border-left: 3px solid #82949e; background: #f5f8f9; color: var(--muted); font-size: 0.77rem; line-height: 1.45; }
.method-note strong { color: var(--ink); }

.table-panel { margin-top: 14px; padding: 16px; }
.table-heading { align-items: end; }
.table-heading > p { margin: 0; color: var(--muted); font-size: 0.78rem; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.79rem; }
th, td { border-bottom: 1px solid #e1e6e9; padding: 8px 9px; text-align: right; white-space: nowrap; }
th { color: #4d5b63; background: #f6f8f9; font-size: 0.7rem; }
th:first-child, td:first-child { text-align: left; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f7fafb; }
tbody tr.selected { background: #e9f3f7; }
table input { width: 78px; min-height: 30px; border: 1px solid #ccd6db; border-radius: 5px; padding: 4px 6px; text-align: right; }

footer { padding: 14px 3px 0; color: var(--muted); font-size: 0.76rem; line-height: 1.5; }
footer p { margin-bottom: 0; }

.method-dialog {
  width: min(940px, calc(100vw - 28px));
  max-height: min(88vh, 920px);
  margin: auto;
  border: 1px solid #b8c4ca;
  border-radius: 12px;
  padding: 0;
  overflow: auto;
  background: white;
  color: var(--ink);
  box-shadow: 0 22px 70px rgba(20, 35, 43, 0.28);
}
.method-dialog::backdrop { background: rgba(20, 31, 38, 0.58); backdrop-filter: blur(2px); }
.dialog-shell { min-width: 0; }
.dialog-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 17px 19px 15px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.97);
}
.dialog-header h2 { font-size: 1.22rem; }
.dialog-close {
  flex: 0 0 auto;
  width: 37px;
  height: 37px;
  border: 1px solid #c5d0d5;
  border-radius: 50%;
  background: white;
  color: #34454f;
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
}
.dialog-close:hover { background: #eef3f5; }
.dialog-body { padding: 19px; overflow-x: hidden; }
.lead-note { margin-bottom: 16px; color: #43535c; line-height: 1.55; }
.method-section { margin-top: 19px; padding-top: 18px; border-top: 1px solid #dce3e7; }
.method-section:first-of-type { margin-top: 0; }
.method-section h3 { margin: 0 0 10px; font-size: 1rem; }
.method-section p { color: #495860; font-size: 0.88rem; line-height: 1.58; }
.notation-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 10px 0 13px; }
.notation-grid > div { padding: 10px 11px; border: 1px solid #dce3e7; border-radius: 7px; background: #f8fafb; }
.notation-grid strong, .notation-grid span { display: block; }
.notation-grid strong { margin-bottom: 4px; color: #52616a; font-size: 0.73rem; }
.notation-grid span { font-family: Georgia, "Times New Roman", serif; font-size: 0.98rem; }
.equation-card {
  position: relative;
  margin: 11px 0;
  padding: 13px 48px 13px 15px;
  border: 1px solid #d8e0e4;
  border-left: 4px solid #617985;
  border-radius: 7px;
  overflow-x: auto;
  background: #f8fafb;
}
.equation-card math {
  min-width: max-content;
  margin: 0 auto;
  color: #17242b;
  font-size: 1.12rem;
}
.equation-pair math + math { margin-top: 12px; }
.equation-number { position: absolute; top: 50%; right: 13px; transform: translateY(-50%); color: #66767f; font-size: 0.78rem; }
.inline-equation { white-space: nowrap; font-family: Georgia, "Times New Roman", serif; color: #17242b; }
.wide-equation math { font-size: 1rem; }
.method-summary ol { margin: 7px 0 14px; padding-left: 22px; color: #43535c; font-size: 0.87rem; line-height: 1.55; }
.method-summary li + li { margin-top: 6px; }
.complexity-note { padding: 11px 13px; border-radius: 7px; background: #eaf2f5; color: #35464f; font-size: 0.83rem; line-height: 1.5; }

.axis-text { fill: #53636d; font-size: 11px; }
.axis-label { fill: #34454f; font-size: 12px; font-weight: 650; }
.grid-line { stroke: var(--grid); stroke-width: 1; }
.plot-border { fill: none; stroke: #9eacb4; stroke-width: 1; }
.layer-band { cursor: pointer; }
.layer-band.selected { stroke: #16242c; stroke-width: 2; }
.property-handle { cursor: ew-resize; }
.boundary-hit { cursor: ns-resize; stroke: transparent; stroke-width: 15; }
.boundary-line { pointer-events: none; stroke: var(--boundary); stroke-width: 1.5; stroke-dasharray: 5 4; }
.drag-label { pointer-events: none; fill: white; font-size: 10px; font-weight: 700; text-anchor: middle; dominant-baseline: central; }
.layer-label { pointer-events: none; fill: #3f4d55; font-size: 10px; font-weight: 650; }
.profile-analytical { fill: none; stroke: var(--analytical); stroke-width: 3; }
.profile-numerical { fill: none; stroke: var(--numerical); stroke-width: 2.2; stroke-dasharray: 7 4; }
.depth-guide { stroke: #c7d1d6; stroke-width: 1; stroke-dasharray: 3 4; }

@media (max-width: 980px) {
  .app-shell { padding: 14px; }
  .app-header { display: block; }
  .header-actions { justify-content: flex-start; margin-top: 13px; }
  .control-strip { grid-template-columns: repeat(3, minmax(120px, 1fr)); }
  .workspace { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .model-panel, .result-panel { padding: 12px; }
  .chart-wrap { height: 470px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .method-note { grid-template-columns: 1fr; gap: 4px; }
  .result-heading-tools { align-items: flex-end; }
}

@media (max-width: 720px) {
  .workspace { grid-template-columns: 1fr; }
  .control-strip { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
  .chart-wrap { height: 500px; }
}

@media (max-width: 480px) {
  .app-shell { padding: 8px; }
  .control-strip, .layer-readout { grid-template-columns: 1fr; }
  .header-actions .button { flex: 1 1 44%; }
  .panel-heading { display: block; }
  .compact { justify-content: flex-start; margin-top: 8px; }
  .result-heading-tools { align-items: flex-start; margin-top: 10px; }
  .chart-wrap { height: 460px; min-height: 420px; }
  .method-dialog { width: calc(100vw - 12px); max-height: 94vh; }
  .dialog-header, .dialog-body { padding: 14px; }
  .notation-grid { grid-template-columns: 1fr; }
  .equation-card { padding-left: 10px; padding-right: 40px; }
  .equation-card math { font-size: 0.96rem; }
}
