/* Shared textbook & interactive Observable JS styles */

:root {
  --color-primary: #1d4ed8;
  --color-primary-accent: #2563eb;
  --color-primary-soft: #eff6ff;
  --color-primary-border: #bfdbfe;
  --color-positive: #0f766e;
  --color-negative: #d97706;
  --color-negative-dark: #b45309;
  --color-slate-dark: #0f172a;
  --color-slate-body: #1e293b;
  --color-slate-label: #334155;
  --color-slate-muted: #475569;
  --color-slate-dim: #64748b;
  --color-border: #cbd5e1;
  --color-border-soft: #e2e8f0;
  --color-surface: #ffffff;
  --color-surface-soft: #f8fafc;
  --color-surface-tint: #f1f5f9;
}

body,
button,
select,
input,
table {
  font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--color-slate-body);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  margin: 14px 0 18px 0;
}

.kpi-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border-soft);
  border-left: 4px solid var(--color-primary);
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.kpi-card--primary {
  border-left-color: var(--color-primary);
}

.kpi-card--warn {
  border-left-color: var(--color-negative);
}

.kpi-card--slate {
  border-left-color: var(--color-slate-muted);
}

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

.lab-empty-box {
  margin: 6px 0;
}

.residual-colorbar-wrap {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: var(--color-slate-muted);
  max-width: 460px;
  margin: 0 auto 10px auto;
}

.residual-colorbar-bar {
  display: inline-block;
  width: 160px;
  height: 10px;
  border-radius: 4px;
  border: 1px solid var(--color-border);
  background: linear-gradient(90deg, var(--color-negative) 0%, var(--color-surface) 50%, var(--color-primary) 100%);
}

.kpi-title {
  font-size: 0.78rem;
  color: #64748b;
  font-weight: 600;
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: #0f172a;
}

.kpi-sub {
  font-size: 0.78rem;
  color: #475569;
  margin-top: 3px;
}

.ex-2x2-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 10px 0 16px 0;
}

.oe-split-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
  margin: 10px 0 14px 0;
}

.ex-2x2-card {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.ex-2x2-hdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  gap: 6px;
}

.ex-2x2-title {
  font-weight: 700;
  font-size: 0.9rem;
  color: #0f172a;
}

.ex-2x2-badge {
  background: #e2e8f0;
  color: #334155;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.ex-2x2-tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.ex-2x2-tbl th,
.ex-2x2-tbl td {
  border: 1px solid #cbd5e1;
  padding: 4px 6px;
  text-align: center;
}

.ex-2x2-tbl th {
  background: #f8fafc;
  font-weight: 700;
}

.edu-table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0 16px 0;
  background: #ffffff;
  font-size: 0.85rem;
}

.edu-table th,
.edu-table td {
  border: 1px solid #cbd5e1;
  padding: 7px 9px;
  text-align: left;
}

.edu-table th {
  background: #f1f5f9;
  font-weight: 700;
}

.section-block {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 14px 16px;
  margin: 14px 0;
}

.lab-box {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-left: 4px solid #0f766e;
  border-radius: 8px;
  padding: 14px 16px;
  margin: 14px 0;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 12px 0;
}

.preset-btn {
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #1e293b;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.preset-btn:hover {
  background: #eff6ff;
  border-color: #2563eb;
  color: #1d4ed8;
}

.preset-btn.active {
  background: #1d4ed8;
  border-color: #1d4ed8;
  color: #ffffff;
}

.math-map-wrap {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 14px;
  margin: 10px 0 18px 0;
  overflow-x: auto;
}

.landing-intro {
  font-size: 1.02rem;
  line-height: 1.75;
  color: #334155;
  padding-bottom: 14px;
  margin-bottom: 20px;
  border-bottom: 1px solid #e2e8f0;
}

.landing-intro p:last-child {
  margin-bottom: 0;
}

.doc-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
  margin: 16px 0 24px 0;
}

.doc-card {
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-top: 4px solid #1d4ed8;
  border-radius: 8px;
  padding: 18px 20px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.doc-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
  border-color: #cbd5e1;
}

.doc-card h3 {
  margin-top: 4px;
  margin-bottom: 10px;
  font-size: 1.12rem;
  line-height: 1.4;
}

.doc-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.doc-card-tag {
  display: inline-block;
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #dbeafe;
  font-size: 0.74rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}

.doc-card-cta {
  display: inline-block;
  margin-top: auto;
  padding-top: 6px;
  font-weight: 600;
  font-size: 0.92rem;
  text-decoration: none;
}

.doc-card-cta:hover {
  text-decoration: underline;
}

/* Observable JS Inputs & Plot containers */
.observablehq form {
  margin: 6px 0;
}

.observablehq--inspect {
  font-size: 0.85rem;
}

.ojs-table-wrap {
  max-height: 460px;
  overflow: auto;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #ffffff;
  margin: 8px 0 14px 0;
}

.ojs-plot-wrap {
  margin: 10px 0 14px 0;
  overflow-x: auto;
}

.ojs-plot-wrap svg {
  max-width: 100%;
  height: auto;
}

.ojs-plot-wrap figure > h2 {
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--color-slate-dark);
  border-bottom: none;
  margin: 0 0 6px 0;
  padding-bottom: 0;
}

.ojs-plot-wrap figure > h3 {
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--color-slate-muted);
  margin: 0 0 6px 0;
}

.calc-heatmap-wrap svg {
  width: 100%;
  height: auto;
  display: block;
}

.calc-toggle-bar {
  width: 100%;
  margin: 8px 0 12px 0;
  padding: 10px 14px;
  background: var(--color-surface-soft);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-sizing: border-box;
}

.calc-toggle-bar label {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--color-slate-dark);
  cursor: pointer;
}

/* Longtail controls & calculator layout */
.longtail-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 10px 0 14px 0;
}

.ctrl-row {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
}

.ctrl-label {
  white-space: nowrap;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--color-slate-label);
  min-width: 195px;
  margin: 0;
}

.ctrl-range-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
}

.ctrl-num {
  width: 82px;
  flex-shrink: 0;
  padding: 5px 8px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 0.9rem;
}

.ctrl-range {
  flex: 1 1 auto;
  width: 100%;
}

.ctrl-text {
  flex: 1 1 auto;
  width: 100%;
  box-sizing: border-box;
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 0.9rem;
  background: var(--color-surface);
}

@media (max-width: 640px) {
  .ctrl-row {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }
  .ctrl-label {
    min-width: 0;
  }
}

.inline-summary-box {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-left: 4px solid #2563eb;
  border-radius: 6px;
  padding: 10px 14px;
  margin: 10px 0 14px 0;
  font-size: 0.92rem;
  line-height: 1.6;
}

.calc-layout {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.calc-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 10px 14px;
  align-items: end;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 12px 14px;
}

@media (max-width: 760px) {
  .calc-controls {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
  }
}

@media (max-width: 480px) {
  .calc-controls {
    grid-template-columns: 1fr;
  }
}

.calc-field {
  margin-bottom: 0;
}

.calc-field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: #334155;
  margin-bottom: 4px;
}

.calc-field input[type="number"] {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 0.9rem;
}

.calc-slider-wrap {
  grid-column: 1 / -1;
  margin-top: 2px;
  padding: 8px 10px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
}

.calc-slider-wrap input[type="range"] {
  width: 100%;
  margin: 4px 0 2px 0;
}

.calc-slider-bounds {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  color: #64748b;
}

.dir-badge {
  display: inline-block;
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  vertical-align: middle;
}

.calc-error-box {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-left: 4px solid #d97706;
  border-radius: 6px;
  padding: 10px 14px;
  color: #92400e;
  font-size: 0.88rem;
  margin-bottom: 12px;
}

.ojs-table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.ojs-table-wrap th,
.ojs-table-wrap td {
  padding: 6px 9px;
  border-bottom: 1px solid #e2e8f0;
}

.ojs-table-wrap thead th {
  background: #f1f5f9;
  font-weight: 700;
  color: #0f172a;
}

/* Metric labs, collapsible herb explorer, bias legend, 5x5 SPLOM */
.mini-ex-tbl {
  font-size: 0.82rem;
}

.metric-lab-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 12px 0 22px 0;
}

.lab-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border-soft);
  border-top: 3px solid var(--color-border);
  border-radius: 8px;
  padding: 14px 16px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.lab-card--positive {
  border-top-color: var(--color-primary);
}

.lab-card--negative {
  border-top-color: var(--color-negative);
}

.lab-card--bias {
  border-top-color: var(--color-slate-muted);
}

.lab-card-title {
  margin: 0 0 10px 0;
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--color-slate-dark);
}

.lab-plot-full svg {
  width: 100%;
  height: auto;
  display: block;
}

.lab-subheading {
  margin: 14px 0 8px 0;
  font-size: 0.96rem;
  font-weight: 700;
  color: #0f172a;
}

.lab-subheading:first-child {
  margin-top: 2px;
}

.bias-sub {
  font-size: 0.82rem;
  color: #475569;
  margin: 2px 0 6px 0;
}

.bias-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  font-size: 0.8rem;
  color: #334155;
  margin: 4px 0 12px 0;
}

.bias-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.herb-lab-details {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-left: 4px solid #0f766e;
  border-radius: 8px;
  padding: 10px 14px;
  margin-top: 0;
}

.herb-lab-details .metric-lab-stack {
  margin: 10px 0 0 0;
}

.herb-lab-details > summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 0.94rem;
  color: #0f766e;
  user-select: none;
}

.herb-lab-details[open] > summary {
  margin-bottom: 12px;
}

.herb-controls-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 10px;
}

.herb-ctrl-box label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: #334155;
  margin-bottom: 4px;
}

.herb-search-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(220px, 1.35fr);
  gap: 10px;
  align-items: center;
}

@media (max-width: 600px) {
  .herb-search-row {
    grid-template-columns: 1fr;
  }
}

.herb-ctrl-box input[type="search"],
.herb-ctrl-box select {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 0.88rem;
  background: #ffffff;
  margin-bottom: 0;
}

.splom-wrap {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 12px 14px;
  margin: 10px 0 18px 0;
  overflow-x: auto;
}

.splom-title {
  font-size: 0.98rem;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 8px;
}

.splom-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(145px, 1fr));
  gap: 6px;
  min-width: 740px;
}

.splom-cell {
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #ffffff;
  padding: 4px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 145px;
}

.splom-diag-cell {
  background: #f8fafc;
}

.splom-diag-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: #0f172a;
  text-align: center;
  margin-bottom: 2px;
}

.splom-rho-cell {
  background: #f8fafc;
  text-align: center;
}

.splom-rho-val {
  font-size: 1.05rem;
  font-weight: 700;
}

.splom-rho-sub {
  font-size: 0.72rem;
  color: #64748b;
  margin-top: 3px;
}

.splom-legend {
  font-size: 0.8rem;
  color: #475569;
  margin-top: 8px;
  text-align: center;
}

/* Consistent boxed display math formulas */
span.math.display {
  display: block;
  background: var(--color-surface-soft);
  border: 1px solid var(--color-border-soft);
  border-left: 4px solid var(--color-primary);
  border-radius: 8px;
  padding: 14px 18px;
  margin: 12px 0 16px 0;
  overflow-x: auto;
  text-align: center;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
}

span.math.display .katex-display {
  margin: 0;
}

/* Native dialog zoom modal for plots, SPLOM, and diagrams */
.zoomable-host {
  position: relative;
}

.zoom-trigger-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 5;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--color-border);
  color: var(--color-slate-label);
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  line-height: 1.4;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.zoom-trigger-btn:hover {
  background: var(--color-primary-soft);
  border-color: var(--color-primary-accent);
  color: var(--color-primary);
}

.zoom-modal .zoom-trigger-btn {
  display: none;
}

.zoom-placeholder {
  border: 1px dashed var(--color-border);
  border-radius: 8px;
  background: var(--color-surface-soft);
}

.zoom-modal {
  width: min(94vw, 1360px);
  max-width: 94vw;
  max-height: 90vh;
  margin: auto;
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: var(--color-surface);
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
  overflow: hidden;
}

.zoom-modal[open] {
  display: flex;
  flex-direction: column;
}

.zoom-modal::backdrop {
  background: rgba(15, 23, 42, 0.58);
  backdrop-filter: blur(2px);
}

.zoom-modal-hdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--color-surface-soft);
  border-bottom: 1px solid var(--color-border-soft);
}

.zoom-modal-title {
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--color-slate-dark);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.zoom-modal-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.zoom-modal-scale {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-slate-muted);
  min-width: 42px;
  text-align: center;
}

.zoom-modal-btn {
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-slate-body);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.zoom-modal-btn:hover {
  background: var(--color-primary-soft);
  border-color: var(--color-primary-accent);
  color: var(--color-primary);
}

.zoom-modal-body {
  padding: 16px 20px;
  overflow: auto;
  flex: 1 1 auto;
}

.zoom-modal-stage {
  width: 100%;
  margin: 0 auto;
}

.zoom-modal-stage .ojs-plot-wrap,
.zoom-modal-stage .math-map-wrap,
.zoom-modal-stage .splom-wrap {
  margin: 0;
  overflow: visible;
}

.zoom-modal-stage .ojs-plot-wrap svg,
.zoom-modal-stage .math-map-wrap svg,
.zoom-modal-stage .splom-cell svg {
  width: 100% !important;
  height: auto !important;
  max-width: none;
}
