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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #0f1923;
  color: #e8edf2;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
#header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 18px;
  background: #1a2635;
  border-bottom: 2px solid #2a3f55;
  flex-shrink: 0;
  z-index: 10;
}
.header-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: #4fc3f7;
  white-space: nowrap;
}
#game-info { display: flex; gap: 8px; flex: 1; }
.stat-box {
  background: #0f1923;
  border: 1px solid #2a3f55;
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 0.8rem;
  white-space: nowrap;
}
.stat-box strong { color: #4fc3f7; }
.header-actions { display: flex; gap: 8px; }

.hdr-btn {
  background: #1a3448;
  border: 1px solid #2a3f55;
  border-radius: 7px;
  color: #e8edf2;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.hdr-btn:hover { background: #2a4a60; border-color: #4fc3f7; }

/* ── Setup panel ──────────────────────────────────────────────────────────── */
#setup-panel {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
#setup-panel.hidden { display: none; }

#setup-box {
  background: #1a2635;
  border: 2px solid #2a3f55;
  border-radius: 20px;
  padding: 40px 50px;
  width: 360px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: center;
}
.setup-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: #4fc3f7;
  text-align: center;
}
.setup-subtitle {
  font-size: 0.82rem;
  color: #7a9bb5;
  text-align: center;
  line-height: 1.5;
}
.setup-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  font-size: 0.9rem;
  color: #b0bec5;
}
.setup-stepper {
  display: flex;
  align-items: center;
  gap: 12px;
}
.setup-stepper button {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 1px solid #2a3f55;
  background: #0f1923;
  color: #e8edf2;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.setup-stepper button:hover { border-color: #4fc3f7; color: #4fc3f7; }
.setup-stepper span {
  font-size: 1.2rem;
  font-weight: 700;
  color: #4fc3f7;
  min-width: 24px;
  text-align: center;
}
#btn-start {
  width: 100%;
  padding: 12px;
  background: #1565c0;
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 6px;
}
#btn-start:hover { background: #1976d2; }

/* ── Game area ────────────────────────────────────────────────────────────── */
#game-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
#game-area.hidden { display: none; }

/* ── Map canvas ───────────────────────────────────────────────────────────── */
#map-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
  background: #0c1620;
}
#map-canvas { display: block; width: 100%; height: 100%; }

/* ── Legend ───────────────────────────────────────────────────────────────── */
#legend {
  position: absolute;
  top: 10px; right: 12px;
  background: rgba(15,25,35,0.85);
  border: 1px solid #2a3f55;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.72rem;
  color: #7a9bb5;
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
}
.legend-row { display: flex; align-items: center; gap: 6px; }
.legend-circle {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #4fc3f7;
  border: 1.5px solid #fff;
  flex-shrink: 0;
}
.legend-diamond {
  width: 10px; height: 10px;
  background: #4fc3f7;
  border: 1.5px solid #fff;
  transform: rotate(45deg);
  flex-shrink: 0;
}

/* ── Vehicle panels ───────────────────────────────────────────────────────── */
#vehicle-panels {
  display: flex;
  flex-shrink: 0;
  background: #131f2e;
  border-top: 2px solid #2a3f55;
  min-height: 110px;
  max-height: 140px;
  overflow: hidden;
}

.veh-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 8px 10px;
  border-right: 1px solid #2a3f55;
  cursor: pointer;
  transition: background 0.15s;
  overflow: hidden;
  border-top: 3px solid transparent;
}
.veh-panel:last-child { border-right: none; }
.veh-panel:hover { background: #1a2e44; }
.veh-panel.active {
  background: #0d2137;
  border-top-color: var(--veh-color);
}
.veh-panel.violation { background: #1f1215; }

.veh-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
}
.veh-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.veh-name { font-size: 0.8rem; font-weight: 700; flex: 1; }
.veh-cap  { font-size: 0.72rem; color: #7a9bb5; }

.veh-stops {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  overflow-y: auto;
  align-content: flex-start;
}
.veh-empty { font-size: 0.72rem; color: #3a5068; font-style: italic; }

.veh-stop-chip {
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  background: #0f1923;
  border: 1.5px solid transparent;
  border-radius: 4px;
  padding: 2px 6px;
  cursor: pointer;
  white-space: nowrap;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #e8edf2;
}
.veh-stop-chip:hover { background: #1a2e44; opacity: 0.8; }

.veh-dist {
  font-size: 0.7rem;
  color: #4fc3f7;
  margin-top: 4px;
  font-weight: 600;
}
.veh-panel.violation .veh-dist { color: #e57373; }

/* ── Action bar ───────────────────────────────────────────────────────────── */
#action-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 14px;
  background: #1a2635;
  border-top: 1px solid #2a3f55;
  flex-shrink: 0;
}
#assignment-hint {
  flex: 1;
  font-size: 0.78rem;
  color: #7a9bb5;
  text-align: center;
}
#btn-reset {
  background: none;
  border: 1px solid #2a3f55;
  border-radius: 7px;
  color: #b0bec5;
  font-size: 0.78rem;
  padding: 5px 12px;
  cursor: pointer;
}
#btn-reset:hover { border-color: #4fc3f7; color: #e8edf2; }

#btn-submit {
  padding: 6px 20px;
  background: #2e7d32;
  color: #fff;
  border: none;
  border-radius: 7px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
#btn-submit:hover { background: #388e3c; }
#btn-submit:disabled { background: #2a3f55; color: #556; cursor: not-allowed; }

/* ── Result overlay ───────────────────────────────────────────────────────── */
#result-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
#result-overlay.hidden { display: none; }

#result-box {
  background: #1a2635;
  border: 2px solid #4fc3f7;
  border-radius: 16px;
  padding: 28px 36px;
  width: 420px;
  max-width: 94vw;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
#result-title {
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  color: #4fc3f7;
}
.res-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
  padding: 6px 0;
  border-bottom: 1px solid #2a3f55;
  color: #b0bec5;
}
.res-row:last-child { border-bottom: none; }
.res-row strong { color: #e8edf2; }
.green { color: #81c784 !important; }
.red   { color: #e57373 !important; }

.violations-list {
  background: #1f1215;
  border: 1px solid #c62828;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.78rem;
  color: #e57373;
  max-height: 100px;
  overflow-y: auto;
}
.viol-item { padding: 2px 0; }

#submit-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#submit-fields {
  display: flex;
  gap: 8px;
}
#submit-fields input {
  flex: 1;
  padding: 8px 12px;
  background: #0f1923;
  border: 1px solid #2a3f55;
  border-radius: 8px;
  color: #e8edf2;
  font-size: 0.85rem;
  outline: none;
}
#submit-fields input:focus { border-color: #4fc3f7; }
#submit-fields input::placeholder { color: #3a5068; }

#btn-submit-score {
  padding: 9px;
  background: #1565c0;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
#btn-submit-score:hover { background: #1976d2; }
#btn-submit-score:disabled { background: #2a3f55; cursor: not-allowed; }

#rank-result {
  background: #0d2137;
  border: 1px solid #4fc3f7;
  border-radius: 10px;
  padding: 12px;
  font-size: 0.9rem;
  text-align: center;
  line-height: 1.8;
}

#result-actions {
  display: flex;
  gap: 8px;
}
#result-actions button {
  flex: 1;
  padding: 9px;
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
}
#result-actions button:first-child { background: #2e7d32; }
#result-actions button:first-child:hover { background: #388e3c; }
#result-actions button:last-child  { background: #1a3448; border: 1px solid #2a3f55; }
#result-actions button:last-child:hover  { background: #2a4a60; }

/* ── Leaderboard screen ───────────────────────────────────────────────────── */
#leaderboard-screen {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  background: #0f1923;
}

.lb-screen-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}
.lb-screen-nav button {
  background: #1a3448;
  border: 1px solid #2a3f55;
  border-radius: 8px;
  color: #e8edf2;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 16px;
  cursor: pointer;
}
.lb-screen-nav button:hover { background: #2a4a60; border-color: #4fc3f7; }

.lb-screen-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: #4fc3f7;
}

.lb-screen-subtitle {
  font-size: 1rem;
  font-weight: 700;
  color: #e8edf2;
  margin-bottom: 6px;
}

#comments-section { flex-shrink: 0; }

.lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.lb-table th {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 2px solid #2a3f55;
  color: #7a9bb5;
  font-weight: 600;
}
.lb-table td {
  padding: 7px 8px;
  border-bottom: 1px solid #1e3045;
  color: #e8edf2;
}
.lb-table tr:last-child td { border-bottom: none; }
.lb-table tr:hover td { background: #1a2e44; }

.lb-msg { padding: 16px; color: #7a9bb5; text-align: center; font-size: 0.85rem; }

/* ── Toast ────────────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: #1a2e44;
  border: 1px solid #4fc3f7;
  color: #e8edf2;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 0.82rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 300;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Comments ─────────────────────────────────────────────────────────────── */
#comment-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid #2a3f55;
  margin-bottom: 10px;
}
#comment-form input,
#comment-form textarea {
  background: #0f1923;
  border: 1px solid #2a3f55;
  border-radius: 7px;
  color: #e8edf2;
  font-size: 0.85rem;
  padding: 8px 12px;
  outline: none;
  font-family: inherit;
}
#comment-form input:focus,
#comment-form textarea:focus { border-color: #4fc3f7; }
#comment-form input::placeholder,
#comment-form textarea::placeholder { color: #3a5068; }
#comment-form textarea { height: 68px; resize: none; }
.comment-post-btn {
  align-self: flex-end;
  padding: 7px 20px;
  background: #1565c0;
  color: #fff;
  border: none;
  border-radius: 7px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.comment-post-btn:hover { background: #1976d2; }
.comment-card {
  padding: 10px 4px;
  border-bottom: 1px solid #1e3045;
}
.comment-card:last-child { border-bottom: none; }
.comment-meta { font-size: 0.72rem; color: #7a9bb5; margin-bottom: 4px; }
.comment-body { font-size: 0.82rem; color: #e8edf2; line-height: 1.5; }

/* ── Mobile ───────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  #setup-box { width: 92vw; padding: 28px 24px; }
  #vehicle-panels { max-height: 120px; }
  .veh-panel { padding: 6px 8px; }
  #result-box { padding: 20px 18px; }
  #submit-fields { flex-direction: column; }
  .lb-table th:nth-child(5),
  .lb-table td:nth-child(5),
  .lb-table th:nth-child(6),
  .lb-table td:nth-child(6) { display: none; }
}
