/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', sans-serif;
  background: #f0f4f8;
  color: #1a202c;
  min-height: 100vh;
  padding: 2rem;
}

h1 {
  font-size: 2rem;
  font-weight: 700;
  color: #2d3748;
  margin-bottom: 1.5rem;
  letter-spacing: -0.5px;
}

/* ── Container ── */
.container {
  max-width: 860px;
  margin: 0 auto;
}

/* ── Panels ── */
.panel {
  background: #fff;
  border-radius: 10px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.panel .label { font-weight: 600; color: #4a5568; }

.row-group { display: flex; align-items: center; gap: 0.6rem; }

label { font-weight: 500; color: #4a5568; }

input[type="number"] {
  width: 64px;
  padding: 0.35rem 0.5rem;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-size: 0.95rem;
  text-align: center;
}

input[type="number"]:focus { outline: none; border-color: #667eea; box-shadow: 0 0 0 3px rgba(102,126,234,.2); }

/* ── Buttons ── */
.btn {
  padding: 0.4rem 1rem;
  border: none;
  border-radius: 7px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.btn:active { transform: scale(.97); }

.btn-primary   { background: #667eea; color: #fff; }
.btn-primary:hover { background: #5a67d8; }

.btn-secondary { background: #48bb78; color: #fff; }
.btn-secondary:hover { background: #38a169; }

.btn-danger    { background: #fc8181; color: #fff; }
.btn-danger:hover { background: #f56565; }

.btn-vi        { background: #805ad5; color: #fff; }
.btn-vi:hover  { background: #6b46c1; }

.btn-mode {
  background: #edf2f7;
  color: #2d3748;
  border: 2px solid transparent;
}
.btn-mode:hover { background: #e2e8f0; }
.btn-mode.active {
  border-color: #667eea;
  background: #ebf4ff;
  color: #434190;
}

.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ── Status Bar ── */
.status-bar {
  background: #ebf8ff;
  border-left: 4px solid #63b3ed;
  padding: 0.55rem 1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  color: #2b6cb0;
  margin-bottom: 1rem;
}

.info-tag {
  background: #edf2f7;
  padding: 0.25rem 0.7rem;
  border-radius: 20px;
  font-size: 0.82rem;
  color: #4a5568;
  font-weight: 600;
}

/* ── Grid ── */
.grid-wrapper {
  background: #fff;
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: 0 1px 6px rgba(0,0,0,.1);
  display: inline-block;
  margin-bottom: 1rem;
}

.grid {
  display: inline-grid;
  gap: 3px;
  background: #a0aec0;
  border: 3px solid #a0aec0;
  border-radius: 6px;
  overflow: hidden;
}

/* ── Cells ── */
.cell {
  width: 80px;
  height: 80px;
  background: #f7fafc;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  transition: background .12s, transform .08s;
  position: relative;
}

.cell:hover { background: #e2e8f0; }

.cell.start    { background: #38a169; }
.cell.start:hover { background: #2f855a; }

.cell.end      { background: #e53e3e; }
.cell.end:hover { background: #c53030; }

.cell.obstacle { background: #718096; cursor: default; }
.cell.obstacle:hover { background: #4a5568; }

.cell.optimal-path { background: #68d391; }
.cell.optimal-path:hover { background: #48bb78; }
.cell.optimal-path .cell-arrow { color: #1a202c; }
.cell.optimal-path .cell-value { color: #1a202c; }

.cell-number {
  font-size: 0.72rem;
  color: #718096;
  position: absolute;
  top: 4px;
  left: 6px;
  line-height: 1;
}

.cell.start .cell-number,
.cell.end   .cell-number { color: rgba(255,255,255,.7); }

.cell.obstacle .cell-number { color: rgba(255,255,255,.5); }

.cell-arrow {
  font-size: 1.6rem;
  line-height: 1;
  color: #2d3748;
}

.cell.start .cell-arrow,
.cell.end   .cell-arrow { color: rgba(255,255,255,.9); }

.cell-value {
  font-size: 0.68rem;
  font-weight: 700;
  color: #4a5568;
  margin-top: 2px;
}

.cell.start .cell-value,
.cell.end   .cell-value { color: rgba(255,255,255,.9); }

/* value heat colour applied via JS inline style */

/* ── Legend ── */
.legend {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.legend-item { display: flex; align-items: center; gap: 0.4rem; font-size: 0.88rem; color: #4a5568; }

.swatch {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,.12);
}
.swatch-start    { background: #38a169; }
.swatch-end      { background: #e53e3e; }
.swatch-obstacle { background: #718096; }
.swatch-normal   { background: #f7fafc; }
.swatch-path     { background: #68d391; }
