:root {
  --rows: 5;
  --cols: 4;
  --cell-size: 60px;
  --gap: 4px;
  --color-start: #ff632b;
  --color-middle: #ff9f00;
  --color-end: #d7d300;
  --color-bg: #f4f6f8;
  --color-card: #fff;
  --color-text: #111;
  --color-shadow: rgba(10, 20, 40, 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', 'Segoe UI', Arial, sans-serif;
}

body {
  background: var(--color-bg);
  color: var(--color-text);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: linear-gradient(90deg, var(--color-start), var(--color-middle));
  color: #fff;
  box-shadow: 0 4px 12px var(--color-shadow);
}

.topbar h1 {
  font-size: 1.5rem;
  font-weight: 700;
}

.topbar button {
  background: var(--color-end);
  color: var(--color-text);
  border: none;
  border-radius: 6px;
  padding: 6px 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.topbar button:hover {
  background: var(--color-middle);
  color: #fff;
}

.container {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  padding: 20px;
}

.left {
  flex: 1;
  min-width: 300px;
}

.right {
  width: 320px;
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell-size));
  grid-template-rows: repeat(var(--rows), var(--cell-size));
  gap: var(--gap);
  background: #dfe7ef;
  padding: 10px;
  border-radius: 8px;
  width: calc(var(--cell-size) * var(--cols) + var(--gap) * (var(--cols) - 1) + 20px);
  height: calc(var(--cell-size) * var(--rows) + var(--gap) * (var(--rows) - 1) + 20px);
}

.board-config {
  --cell-size: 40px;
  padding: 8px;
  width: calc(var(--cell-size) * var(--cols) + var(--gap) * (var(--cols) - 1) + 16px);
  height: calc(var(--cell-size) * var(--rows) + var(--gap) * (var(--rows) - 1) + 16px);
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 1px solid #e3e8ef;
  border-radius: 6px;
  position: relative;
  transition: background 0.15s, transform 0.08s;
}

.cell.path {
  background: #8fd19e;
}

.cell.start {
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.25);
  border: 2px solid #2b9e4a;
}

.cell.goal {
  background: #ffd166;
  border: 2px solid #e09b00;
}

.robot {
  width: 70%;
  height: 70%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #2b6cb0;
  color: #fff;
  font-weight: 700;
  font-size: 1.6rem;
  border-radius: 6px;
  transform-origin: center;
}

.controls {
  background: var(--color-card);
  padding: 16px;
  border-radius: 12px;
  box-shadow: 0 6px 18px var(--color-shadow);
}

.controls h3,
.controls h4 {
  margin-bottom: 8px;
}

.btn-row,
.action-row,
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn-row button,
.action-row button,
.modal-actions button {
  flex: 1;
  min-width: 80px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #cfd8e3;
  background: var(--color-end);
  color: var(--color-text);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.btn-row button:hover,
.action-row button:hover,
.modal-actions button:hover {
  background: var(--color-middle);
  color: #fff;
}

.message {
  margin-top: 12px;
  padding: 10px;
  border-radius: 8px;
  min-height: 28px;
  font-weight: 600;
}

.message.success {
  background: #e6ffed;
  border: 1px solid #2b9e4a;
  color: #165c2b;
}

.message.fail {
  background: #fff1f0;
  border: 1px solid #e21a1a;
  color: #7a0b0b;
}

.move-list {
  background: #fafafa;
  padding: 8px;
  border-radius: 8px;
  min-height: 80px;
  max-height: 200px;
  overflow-y: auto;
  box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.05);
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--color-card);
  padding: 20px;
  border-radius: 12px;
  max-width: 90%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: 0 6px 20px var(--color-shadow);
}

.config-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-top: 8px;
}

#track-select {
  min-width: 160px;
  padding: 4px 8px;
  border: 1px solid #cfd8e3;
  border-radius: 6px;
}

.navbar {
  background: linear-gradient(90deg, var(--color-start), var(--color-middle));
  padding: 12px 24px;
  box-shadow: 0 4px 12px var(--color-shadow);
  display: flex;
  justify-content: center;
  align-items: center;
}

.nav-links {
  list-style: none;
  display: flex;
  gap: 16px;
  margin: 0;
  padding: 0;
}

.nav-links li {
  margin: 0;
}

.nav-links a {
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  font-size: 1rem;
  padding: 8px 16px;
  border-radius: 6px;
  transition: background 0.2s, color 0.2s;
  display: block;
}

.nav-links a:hover {
  background: var(--color-middle);
  color: var(--color-text);
}

.nav-links a.active {
  background: var(--color-end);
  color: var(--color-text);
}

.admin-table {
  width: 100%;
  margin-top: 16px;
  border-collapse: collapse;
}

.table-header {
  background: var(--color-middle);
  color: #fff;
}

.table-cell {
  padding: 8px;
  border: 1px solid #cfd8e3;
}

.form-group {
  margin-bottom: 12px;
}

.form-input {
  width: 100%;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid #cfd8e3;
}

.button {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #cfd8e3;
  background: var(--color-end);
  color: var(--color-text);
  font-family: 'Inter', 'Segoe UI', Arial, sans-serif;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.button:hover {
  background: var(--color-middle);
  color: #fff;
}

@media (max-width: 768px) {
  .container {
    flex-direction: column;
  }

  .right {
    width: 100%;
  }

  .board {
    margin: 0 auto;
  }

  .navbar {
    padding: 12px;
  }

  .nav-links {
    flex-direction: column;
    gap: 12px;
    width: 100%;
    align-items: center;
  }

  .nav-links a {
    text-align: center;
    padding: 10px;
    width: 100%;
    max-width: 200px;
  }
}

.track-header {
    font-size: 1.2em;
    font-weight: bold;
    margin: 1em 0 0.5em;
    color: var(--color-dark);
}