:root {
  --bg: #081018;
  --bg-accent: #0f2334;
  --panel: #10283c;
  --panel-soft: #15344d;
  --line: #2c5168;
  --text: #dceef8;
  --muted: #99bbcc;
  --wall: #4b6b82;
  --open: #0b1c2a;
  --start: #0fa36b;
  --exit: #e0962e;
  --bug: #ffd84f;
  --danger: #e14c62;
  --ok: #7bf0aa;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 20%, #173c55 0%, transparent 35%),
    radial-gradient(circle at 85% 0%, #1a4a45 0%, transparent 30%),
    linear-gradient(145deg, var(--bg), #060d14 70%);
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
}

.layout {
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
}

.board-panel,
.card,
.top-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, var(--panel) 0%, #0d2234 100%);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
}

.board-panel {
  padding: 16px;
}

.headline h1,
.top-headline h1 {
  margin: 0;
  font-size: clamp(1.6rem, 2.8vw, 2.2rem);
}

.badge {
  margin: 0 0 6px;
  display: inline-block;
  padding: 4px 8px;
  border-radius: 99px;
  border: 1px solid var(--line);
  color: var(--ok);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.75rem;
}

.hint,
.top-hint {
  margin: 8px 0 0;
  color: var(--muted);
}

.board-wrap {
  margin-top: 16px;
  overflow: auto;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #0a1c2b 0%, #08131d 100%);
  padding: 10px;
}

.board {
  --cell-size: 23px;
  display: grid;
  grid-template-columns: repeat(31, var(--cell-size));
  grid-template-rows: repeat(21, var(--cell-size));
  gap: 1px;
  width: fit-content;
  user-select: none;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 2px;
  background: var(--open);
  border: 1px solid #132f45;
  position: relative;
  cursor: pointer;
  transition: transform 120ms ease, background-color 120ms ease;
}

.cell:hover {
  transform: scale(1.06);
}

.cell.wall {
  background: linear-gradient(145deg, #56768e, #3d5669);
  border-color: #6d90a8;
}

.cell.start {
  background: linear-gradient(145deg, #14bd7d, #0f865c);
  border-color: #5cedb2;
}

.cell.exit {
  background: linear-gradient(145deg, #f2b34e, #cc7f21);
  border-color: #ffd39a;
}

.cell.bug::after {
  content: "";
  position: absolute;
  width: 88%;
  height: 88%;
  top: 6%;
  left: 6%;
  background-image: url("/assets/bug.svg");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  transform-origin: center center;
  filter: drop-shadow(0 0 3px rgba(255, 216, 79, 0.45));
}

.cell.bug.dir-down::after {
  transform: rotate(270deg);
}

.cell.bug.dir-right::after {
  transform: rotate(0deg) scaleX(-1);
}

.cell.bug.dir-up::after {
  transform: rotate(90deg);
}

.cell.bug.dir-left::after {
  transform: rotate(0deg);
}

.side-panel {
  display: grid;
  gap: 14px;
  align-content: start;
}

.card,
.top-card {
  padding: 14px;
}

.card h2,
.top-card h2 {
  margin: 0 0 10px;
  font-size: 1.1rem;
}

.metric-row {
  display: grid;
  grid-template-columns: 90px 1fr;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
}

.metric-row strong {
  font-family: "JetBrains Mono", monospace;
  font-size: 1.15rem;
}

.metric-row input[type="range"] {
  width: 100%;
}

.metric-row input[type="text"],
.metric-row input,
#session-name {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #0b1d2b;
  color: var(--text);
  font-family: "JetBrains Mono", monospace;
  width: 100%;
}

#speed-value {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.85rem;
}

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

.controls-secondary {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.btn {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, #17344a, #10293b);
  color: var(--text);
  font-family: "JetBrains Mono", monospace;
  padding: 10px 12px;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}

.btn:hover {
  filter: brightness(1.08);
}

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

.btn-primary {
  border-color: #5e97bd;
  background: linear-gradient(180deg, #226094, #18456a);
}

.status {
  margin: 12px 0 0;
  color: var(--muted);
  min-height: 1.35em;
}

.status.ok {
  color: var(--ok);
}

.status.error {
  color: var(--danger);
}

.flag {
  margin: 10px 0 0;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid #4f955f;
  background: rgba(34, 75, 42, 0.4);
  font-family: "JetBrains Mono", monospace;
  color: #9df8be;
  word-break: break-word;
}

.hidden {
  display: none;
}

.leaderboard {
  margin: 0;
  padding-left: 20px;
}

.leaderboard li {
  margin: 6px 0;
  font-family: "JetBrains Mono", monospace;
  color: var(--muted);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(3, 10, 17, 0.78);
  backdrop-filter: blur(3px);
}

.modal-backdrop.hidden {
  display: none;
}

.modal-card {
  width: min(460px, 92vw);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, #0f2a40 0%, #0a1c2b 100%);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  padding: 18px;
}

.modal-card h2 {
  margin: 0;
}

.modal-card p {
  margin: 8px 0 0;
  color: var(--muted);
}

.modal-form {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

.session-error {
  color: var(--danger);
  min-height: 1.25em;
  margin: 8px 0 0;
  font-size: 0.92rem;
}

.top-layout {
  width: min(1000px, 100%);
  margin: 0 auto;
  padding: 24px;
  display: grid;
  gap: 14px;
}

.top-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.top-tools {
  display: flex;
  gap: 8px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.top-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 560px;
}

.top-table th,
.top-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #1d4259;
  text-align: left;
}

.top-table th {
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
  color: #bce4f8;
  background: #14364f;
}

.top-table td {
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
}

.top-table tbody tr:hover {
  background: rgba(30, 79, 103, 0.25);
}

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 880px) {
  .side-panel {
    grid-template-columns: 1fr;
  }

  .layout,
  .top-layout {
    padding: 14px;
  }

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

  .top-head {
    align-items: flex-start;
  }
}
