:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f5f7fa;
  color: #17202a;
  line-height: 1.45;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid #c6d0dc;
  background: #ffffff;
  color: #17202a;
  height: 38px;
  padding: 0 12px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

button:hover:not(:disabled) {
  border-color: #6e7e90;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.app {
  width: min(1480px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

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

.topActions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

h1 {
  font-size: 31px;
  line-height: 1.08;
  margin: 0 0 8px;
  font-weight: 720;
}

h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

p {
  margin: 0;
  color: #617084;
}

.export {
  background: #17202a;
  color: #fff;
  border-color: #17202a;
}

.controls {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 18px;
  margin-bottom: 14px;
}

.uploadZone,
.settings,
.empty,
.result {
  background: #ffffff;
  border: 1px solid #d8e0e8;
  border-radius: 8px;
}

.uploadZone {
  min-height: 132px;
  padding: 18px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
}

.uploadZone strong {
  display: block;
  margin-bottom: 4px;
}

.uploadZone span {
  display: block;
  color: #66758a;
}

.uploadActions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.uploadZone input[type="file"] {
  display: none;
}

.settings {
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.settingsTitle {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 680;
}

.settings label {
  min-width: 0;
  color: #3b4756;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.settings input[type="number"] {
  width: 82px;
  height: 34px;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  padding: 0 8px;
}

.settings select {
  min-width: 150px;
  height: 34px;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  padding: 0 8px;
  background: #ffffff;
  color: #17202a;
}

.settings label.parameterDisabled {
  color: #9aa6b4;
  flex-wrap: wrap;
}

.settings label.parameterDisabled input,
.settings label.parameterDisabled select {
  background: #edf1f5;
  border-color: #d8e0e8;
  color: #9aa6b4;
  cursor: not-allowed;
}

.settings label.parameterDisabled::after {
  content: attr(data-disabled-reason);
  font-size: 11px;
  color: #8a97a8;
  width: 100%;
  margin-top: -4px;
}

.statusLine {
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #536174;
  margin-bottom: 14px;
}

.statusLine strong {
  margin-left: auto;
  color: #17202a;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2e9d57;
}

.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #c4cfdb;
  border-top-color: #17202a;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.empty {
  min-height: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
}

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

.summaryCard {
  background: #ffffff;
  border: 1px solid #d8e0e8;
  border-radius: 8px;
  padding: 16px;
}

.summaryHeader {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.summaryTable td:nth-child(2),
.summaryTable th:nth-child(2) {
  text-align: left;
}

.recognitionLine {
  color: #2f6f9f;
  font-weight: 560;
  margin: 3px 0;
}

.result {
  padding: 16px;
}

.result header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.stepValue {
  color: #0d6b2c;
  font-weight: 760;
  white-space: nowrap;
}

.resultActions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  justify-content: flex-end;
}

.runControls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.runControls label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #536174;
  font-size: 13px;
}

.runControls input {
  width: 68px;
  height: 34px;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  padding: 0 8px;
}

.rerunMapButton {
  color: #ffffff;
  border-color: transparent;
  min-width: 104px;
  justify-content: center;
  transition: background 120ms ease, border-color 120ms ease, opacity 120ms ease;
}

.rerunMapButton.ready {
  background: #2563eb;
}

.rerunMapButton.ready:hover:not(:disabled) {
  background: #1d4ed8;
}

.rerunMapButton.running,
.rerunMapButton.running:disabled {
  background: #e78921;
  color: #ffffff;
  opacity: 1;
}

.rerunMapButton.done {
  background: #12803a;
}

.rerunMapButton.done:hover:not(:disabled) {
  background: #0d6b2c;
}

.rerunMapButton.error {
  background: #a73535;
}

.mapStatus {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #536174;
  font-weight: 520;
  font-size: 13px;
  max-width: 360px;
  text-align: right;
}

.mapStatus.idle {
  color: #7b8796;
}

.mapStatus.done {
  color: #0d6b2c;
}

.mapStatus.error {
  color: #a73535;
}

.miniSpinner {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid #c4cfdb;
  border-top-color: #7f8ea3;
  animation: spin 1s linear infinite;
  flex: 0 0 auto;
}

.miniDot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #8fa0b4;
  flex: 0 0 auto;
}

.visuals {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.visuals.withSampleImage {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

figure {
  margin: 0;
  min-width: 0;
  background: #f7f9fb;
  border: 1px solid #e1e7ef;
  border-radius: 6px;
  overflow: hidden;
}

figure img {
  display: block;
  width: 100%;
  height: auto;
}

.colorScale {
  padding: 8px 10px 4px;
  border-top: 1px solid #e1e7ef;
}

.colorBar {
  height: 12px;
  border-radius: 3px;
  border: 1px solid rgba(23, 32, 42, 0.18);
  background: linear-gradient(90deg, rgb(68, 1, 84), rgb(59, 82, 139), rgb(33, 145, 140), rgb(94, 201, 98), rgb(253, 231, 37), rgb(244, 109, 67), rgb(165, 0, 38));
}

.scaleTicks {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 4px;
  color: #536174;
  font-size: 12px;
}

.scaleTicks span:nth-child(2) {
  text-align: center;
}

.scaleTicks span:nth-child(3) {
  text-align: right;
}

figcaption {
  padding: 9px 10px;
  color: #536174;
  font-size: 13px;
  border-top: 1px solid #e1e7ef;
}

.legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 12px;
  margin-top: 8px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  border: 1px solid rgba(23, 32, 42, 0.18);
  flex: 0 0 auto;
}

.basinCore {
  background: rgb(0, 45, 220);
}

.basinAssigned {
  background: rgb(88, 120, 220);
}

.landCore {
  background: rgb(0, 170, 35);
}

.landAssigned {
  background: rgb(110, 205, 90);
}

.excluded {
  background: rgb(230, 145, 30);
}

.invalid {
  background: rgb(28, 28, 28);
}

.basinContour {
  background: rgb(0, 240, 255);
}

.landContour {
  background: #ffffff;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  text-align: right;
  padding: 10px 12px;
  border-bottom: 1px solid #e5ebf2;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  color: #5b6878;
  font-weight: 680;
  background: #f8fafc;
}

tr:last-child td {
  border-bottom: 0;
}

@media (max-width: 1300px) {
  .visuals,
  .visuals.withSampleImage {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.recognitionHover {
  position: relative;
  color: #145ea8;
  font-weight: 560;
  cursor: help;
}

.recognitionPreview {
  display: none;
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  left: 0;
  width: min(640px, 70vw);
  grid-template-columns: 0.85fr 1.15fr;
  gap: 10px;
  padding: 10px;
  background: #ffffff;
  border: 1px solid #cbd5e0;
  box-shadow: 0 16px 38px rgba(23, 32, 42, 0.2);
  border-radius: 8px;
  color: #536174;
  font-size: 12px;
}

.recognitionHover:hover .recognitionPreview,
.recognitionHover:focus-within .recognitionPreview {
  display: grid;
}

.recognitionPreview span {
  display: grid;
  gap: 6px;
}

.recognitionPreview img {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  background: #f8fafc;
  border: 1px solid #e1e7ef;
  border-radius: 5px;
}

.recognitionSelect {
  width: 180px;
  height: 32px;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  padding: 0 8px;
  background: #ffffff;
  color: #17202a;
  font-size: 13px;
}

.recognitionSelect.variantSelect {
  width: 72px;
}

.smallAction {
  height: 32px;
  padding: 0 10px;
  border-radius: 6px;
  font-size: 13px;
}

@media (max-width: 900px) {
  .app {
    width: min(100vw - 24px, 1480px);
    padding-top: 18px;
  }

  .topbar,
  .result header {
    flex-direction: column;
  }

  .controls,
  .visuals,
  .visuals.withSampleImage {
    grid-template-columns: 1fr;
  }

  .uploadZone {
    grid-template-columns: 1fr;
  }

  .uploadActions {
    justify-content: flex-start;
  }
}

/* ===== Tribo-Texture Study Suite — dark theme override ===== */
:root { color-scheme: dark; background: #0d1b2a; color: #e8eef5; }
body { background: #0d1b2a; color: #e8eef5; }
p { color: #9fb3c8; }
button { background: #1b3047; color: #e8eef5; border-color: #26415e; }
button:hover:not(:disabled) { border-color: #3b82f6; }
.export { background: #3b82f6; color: #fff; border-color: #3b82f6; }
.uploadZone, .settings, .empty, .result, .summaryCard { background: #14253a; border-color: #26415e; }
.uploadZone span { color: #9fb3c8; }
.settings label, .runControls label, .mapStatus, .scaleTicks, figcaption { color: #9fb3c8; }
input, select,
.settings input[type="number"], .settings select,
.runControls input, .recognitionSelect { background: #1b3047; color: #e8eef5; border-color: #26415e; }
.settings label.parameterDisabled, .settings label.parameterDisabled input,
.settings label.parameterDisabled select { background: #0f2236; border-color: #26415e; color: #6b7d92; }
.statusLine { color: #9fb3c8; }
.statusLine strong { color: #e8eef5; }
figure { background: #0f2236; border-color: #26415e; }
.colorScale, figcaption { border-top-color: #26415e; }
table { color: #e8eef5; }
th { background: #1b3047; color: #9fb3c8; }
th, td { border-bottom-color: #26415e; }
.stepValue, .mapStatus.done { color: #3ecf8e; }
.recognitionLine, .recognitionHover { color: #5aa6e0; }
.recognitionPreview { background: #14253a; border-color: #26415e; color: #9fb3c8; }
.recognitionPreview img { background: #0f2236; border-color: #26415e; }

