*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
}

body {
  background: #1c1510;
  color: #f0e6d3;
  font-family: "Georgia", "Inter", "Segoe UI", system-ui, serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  padding: 1.5rem 1rem 2rem;
  line-height: 1.6;
}
@media (max-width: 640px) {
  body::before {
    content: "Please open on a larger screen";
    position: fixed;
    inset: 0;
    background: #1c1510;
    color: #9e856a;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 1.1rem;
    text-align: center;
    padding: 2rem;
    z-index: 100;
  }
}

.app {
  width: 100%;
  max-width: 960px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  gap: 1rem;
}

.header {
  text-align: center;
  padding: 0.5rem 0 0.25rem;
}
.header .title {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  background: linear-gradient(135deg, #c8763a, #d9a94b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.header .subtitle {
  color: #9e856a;
  font-size: 0.9rem;
  margin-top: 0.25rem;
  font-style: italic;
}

.tabs {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  gap: 0.25rem;
  border-bottom: 2px solid #4e3a2a;
  padding-bottom: 0;
}

.tab {
  padding: 0.5rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  background: #36291e;
  color: #9e856a;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  position: relative;
  bottom: -2px;
}
.tab:hover:not(.tab-active) {
  color: #f0e6d3;
  background: rgb(67.1142857143, 50.9571428571, 37.2857142857);
}
.tab-active {
  background: #2a1f17;
  color: #c8763a;
  border-color: #4e3a2a;
  border-bottom-color: #2a1f17;
}

.panel {
  display: none;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  gap: 1rem;
}
.panel-active {
  display: flex;
}

.controls {
  background: #2a1f17;
  border: 1px solid #4e3a2a;
  border-radius: 12px;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 1rem;
}
.controls-path {
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
}
.controls-row {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 1rem;
}

.control-group-inline {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  gap: 0.5rem;
  flex: 0 0 auto;
}
.control-group-inline label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #9e856a;
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  white-space: nowrap;
}

.control-group {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: flex-start;
  gap: 0.35rem;
  flex: 1;
  min-width: 130px;
}
.control-group label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #9e856a;
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
}

.input-row {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
}

.btn-group-inline {
  gap: 0.35rem;
}

.slider {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: #36291e;
  border-radius: 2px;
  outline: none;
  flex: 1;
  cursor: pointer;
  border: 1px solid #4e3a2a;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: #c8763a;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid #1c1510;
  box-shadow: 0 0 0 2px rgba(200, 118, 58, 0.1803921569);
}
.slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: #c8763a;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid #1c1510;
}

.value-display {
  font-size: 0.8rem;
  font-weight: 700;
  color: #c8763a;
  min-width: 2rem;
  text-align: right;
  font-family: "Inter", monospace;
}

.number-input {
  width: 100%;
  background: #36291e;
  color: #f0e6d3;
  border: 1px solid #4e3a2a;
  border-radius: 8px;
  padding: 0.4rem 0.75rem;
  font-size: 0.9rem;
  outline: none;
  font-family: inherit;
}
.number-input:focus {
  border-color: #c8763a;
  box-shadow: 0 0 0 3px rgba(200, 118, 58, 0.1803921569);
}
.number-input::placeholder {
  color: #9e856a;
}

.select {
  width: 100%;
  background: #36291e;
  color: #f0e6d3;
  border: 1px solid #4e3a2a;
  border-radius: 8px;
  padding: 0.4rem 0.75rem;
  font-size: 0.9rem;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%239e856a' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.25rem;
  font-family: inherit;
}
.select:focus {
  border-color: #c8763a;
  box-shadow: 0 0 0 3px rgba(200, 118, 58, 0.1803921569);
}
.select optgroup {
  background: #2a1f17;
  color: #9e856a;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.select option {
  background: #36291e;
  color: #f0e6d3;
  padding: 0.25rem;
}

.btn-group {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: opacity 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  font-family: inherit;
}
.btn.btn-sm {
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
}
.btn.btn-active-tool {
  outline: 2px solid #c8763a;
  outline-offset: 1px;
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn:not(:disabled):hover {
  opacity: 0.88;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3333333333);
}
.btn-primary {
  background: #c8763a;
  color: #1c1510;
  border-color: rgb(211.130952381, 145.7261904762, 97.869047619);
}
.btn-secondary {
  background: #36291e;
  color: #f0e6d3;
  border-color: #4e3a2a;
}
.btn-danger {
  background: #b84040;
  color: #f0e6d3;
  border-color: rgb(200.5483870968, 98.4516129032, 98.4516129032);
}

.stats-bar {
  background: #2a1f17;
  border: 1px solid #4e3a2a;
  border-radius: 12px;
  padding: 0.6rem 1.25rem;
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.stat {
  font-size: 0.82rem;
  color: #9e856a;
  font-variant-numeric: tabular-nums;
  font-family: "Inter", monospace;
}
.stat .stat-label {
  font-weight: 600;
  color: #f0e6d3;
  margin-right: 0.25rem;
}

.algo-tag {
  margin-left: auto;
  font-size: 0.78rem;
  font-weight: 600;
  color: #c8763a;
  background: rgba(200, 118, 58, 0.1803921569);
  padding: 0.2rem 0.6rem;
  border-radius: 99px;
  border: 1px solid #c8763a;
  font-family: "Inter", sans-serif;
}

.canvas-wrapper {
  background: #2a1f17;
  border: 1px solid #4e3a2a;
  border-radius: 12px;
  padding: 0.5rem;
  overflow: hidden;
}

.canvas {
  width: 100%;
  height: 400px;
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: flex-end;
  gap: 1px;
  overflow: hidden;
  border-radius: 8px;
  background: #1c1510;
  padding: 4px 4px 0;
}

.bar {
  border-radius: 2px 2px 0 0;
  transition: height 0.04s;
  background: #7a5c3e;
  min-width: 1px;
}
.bar-compare {
  background: #d9a94b !important;
}
.bar-swap {
  background: #b84040 !important;
}
.bar-pivot {
  background: #8a5c8a !important;
}
.bar-sorted {
  background: #7aaa5c !important;
}
.bar-min {
  background: #e07c3a !important;
}
.bar-found {
  background: #7aaa5c !important;
}
.bar-discarded {
  background: rgb(71.277173913, 53.75, 36.222826087) !important;
  opacity: 0.45;
}

.canvas-wrapper-grid {
  padding: 0.75rem;
  cursor: crosshair;
}

.grid-canvas {
  width: 100%;
  display: grid;
  border-radius: 6px;
  overflow: hidden;
  gap: 1px;
  background: #4e3a2a;
  user-select: none;
}

.cell {
  aspect-ratio: 1;
  background: #231912;
  transition: background 0.08s;
  min-width: 0;
  min-height: 0;
}
.cell-wall {
  background: #3d2a1a !important;
}
.cell-start {
  background: #7aaa5c !important;
}
.cell-end {
  background: #b84040 !important;
}
.cell-visited {
  background: #5c4a7a !important;
}
.cell-frontier {
  background: #d9a94b !important;
}
.cell-path {
  background: #c8763a !important;
}

.legend {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 0.5rem 0;
}

.legend-item {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: #9e856a;
  font-family: "Inter", sans-serif;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}
.dot-default {
  background: #7a5c3e;
}
.dot-compare {
  background: #d9a94b;
}
.dot-swap {
  background: #b84040;
}
.dot-pivot {
  background: #8a5c8a;
}
.dot-sorted {
  background: #7aaa5c;
}
.dot-wall {
  background: #3d2a1a;
  border: 1px solid #4e3a2a;
}
.dot-start {
  background: #7aaa5c;
}
.dot-end {
  background: #b84040;
}
.dot-visited {
  background: #5c4a7a;
}
.dot-frontier {
  background: #d9a94b;
}
.dot-path {
  background: #c8763a;
}
