:root {
  --bg: #f4f1eb;
  --panel: #fffdf8;
  --panel-border: #e6ddcf;
  --text: #1f2a30;
  --muted: #5f6d74;
  --accent: #1d6a71;
  --accent-strong: #134f54;
  --warn: #9b2c2c;
  --ok: #256b2f;
  --shadow: 0 12px 30px rgba(18, 35, 45, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: #f3efe8;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  position: relative;
  overflow-x: hidden;
}

.background-shape {
  display: none;
}

.shape-a {
  display: none;
}

.shape-b {
  display: none;
}

.dashboard {
  width: min(1200px, 92vw);
  margin: 28px auto 44px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-areas:
    "header header"
    "raw raw"
    "controls matrix"
    "viz viz";
  gap: 18px;
  position: relative;
  z-index: 1;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 20px;
}

h1,
h2,
.subtitle {
  margin: 0;
}

h1 {
  font-family: "Source Serif 4", Georgia, serif;
  font-size: clamp(1.7rem, 2.8vw, 2.3rem);
  letter-spacing: 0.3px;
}

h2 {
  font-size: 1.2rem;
  margin-bottom: 12px;
}

.subtitle {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #2f7b70;
  font-size: 0.82rem;
  margin-bottom: 6px;
  font-weight: 700;
}

.description,
.helper {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.header-panel {
  grid-area: header;
}

.control-panel {
  grid-area: controls;
}

.raw-panel {
  grid-area: raw;
}

.matrix-panel {
  grid-area: matrix;
}

.viz-panel {
  grid-area: viz;
}

.weight-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr 140px;
  gap: 11px 16px;
  align-items: center;
}

.weight-grid label {
  font-weight: 500;
}

input[type="number"] {
  width: 100%;
  border: 1px solid #c8d3d5;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.98rem;
  font-family: inherit;
  background: #ffffff;
}

input[type="number"]:focus {
  outline: 2px solid rgba(30, 118, 127, 0.25);
  border-color: var(--accent);
}

.control-actions {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.scenario-section {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid #dde8ea;
}

.scenario-section h3 {
  margin: 0;
  font-size: 1rem;
  color: #1d3f45;
}

.scenario-buttons {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.scenario-btn {
  font-size: 0.9rem;
  padding: 8px 12px;
}

.scenario-btn.is-playing {
  animation: presetPulse 380ms ease;
}

@keyframes presetPulse {
  0% {
    transform: scale(1);
    background: #ffffff;
  }

  50% {
    transform: scale(1.03);
    background: #e6f0f3;
  }

  100% {
    transform: scale(1);
    background: #ffffff;
  }
}

button {
  align-self: flex-start;
  border: 1px solid #b3c1c5;
  border-radius: 12px;
  background: #ffffff;
  color: #20363a;
  font-weight: 600;
  font-family: inherit;
  padding: 10px 18px;
  cursor: pointer;
  transition: background-color 0.15s ease;
  box-shadow: none;
}

button:hover {
  background: #f0f4f5;
}

button:active {
  background: #e8eff1;
}

.validation {
  min-height: 1.2em;
  font-size: 0.95rem;
  margin: 0;
}

.validation.error {
  color: var(--warn);
}

.validation.ok {
  color: var(--ok);
}

.matrix-editors {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 14px;
}

.matrix-editor {
  border: 1px solid #dfebed;
  border-radius: 12px;
  background: #fcfefc;
  padding: 10px;
}

.matrix-editor h3 {
  margin: 0 0 8px;
  font-size: 1rem;
  color: #19474d;
}

.matrix-input-table {
  width: 100%;
  border-collapse: collapse;
}

.matrix-input-table th,
.matrix-input-table td {
  border: 1px solid #e5eef0;
  padding: 4px;
  text-align: center;
}

.matrix-input-table th {
  font-size: 0.82rem;
  background: #f1f7f8;
}

.matrix-cell-input {
  width: 100%;
  border: 1px solid #c8d3d5;
  border-radius: 6px;
  padding: 5px 4px;
  text-align: center;
  font-size: 0.84rem;
  font-family: inherit;
}

.matrix-cell-input:focus {
  outline: 2px solid rgba(30, 118, 127, 0.2);
  border-color: var(--accent);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: center;
}

th,
td {
  border: 1px solid #deebee;
  padding: 8px;
}

th {
  background: #eef5f7;
  font-weight: 700;
}

td {
  font-variant-numeric: tabular-nums;
}

#routeCanvas {
  width: 100%;
  height: auto;
  border: 1px solid #d8e4e6;
  border-radius: 14px;
  background: linear-gradient(180deg, #fdfefd, #f5faf7);
}

.viz-results {
  margin-top: 16px;
}

.viz-results h3 {
  margin: 0;
  font-size: 1.04rem;
  color: #1d3f45;
}

.route-result,
.cost-result {
  margin: 8px 0;
  font-size: clamp(1.1rem, 2vw, 1.4rem);
  font-weight: 600;
  color: #17353a;
}

@media (max-width: 900px) {
  .dashboard {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "raw"
      "controls"
      "matrix"
      "viz";
  }

  .matrix-editors {
    grid-template-columns: 1fr;
  }

  .scenario-buttons {
    flex-direction: column;
    align-items: stretch;
  }
}
