:root {
  --bg-color: #f4f8fb;
  --white-bg: #ffffff;
  --text-color: #0f2540;
  --border-color: #dfeaf7;
  --primary: #1f6fb3;
  --primary-light: #3bb4e8;
  --table-header-bg: linear-gradient(90deg, #1d6fb8, #2d8ed8);
  --navy: #1b365d;
  --soft-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Poppins', 'Segoe UI', Roboto, Arial, sans-serif;
  background: linear-gradient(180deg, #f6fbff 0%, var(--bg-color) 100%);
  color: var(--text-color);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition:
    background 0.4s,
    color 0.4s;
}

header {
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  color: #fff;
  padding: 18px 24px;
  text-align: center;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.2px;
  box-shadow: 0 6px 18px rgba(9, 25, 44, 0.06);
}

.top-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid rgba(24, 58, 94, 0.04);
  flex-wrap: wrap;
}

.start-group {
  display: flex;
  gap: 10px;
  align-items: center;
}

.top-bar input[type='text'] {
  width: 3.2em;
  padding: 7px 8px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.top-bar label {
  color: var(--text-color);
  font-weight: 600;
  font-size: 14px;
}

.btn,
button {
  background: var(--primary);
  color: #fff;
  padding: 8px 12px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  font-weight: 700;
  transition:
    transform 0.16s ease,
    box-shadow 0.16s ease,
    background 0.3s;
  box-shadow: 0 6px 18px rgba(31, 111, 179, 0.12);
}

.btn:hover,
button:hover {
  background: var(--primary-light);
  transform: translateY(-3px);
}

main.layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 20px;
  padding: 18px;
  align-items: start;
  width: 100%;
}

.graph {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 580px;
  padding: 6px;
}

.canvas-wrap {
  width: 100%;
  max-width: 980px;
  display: flex;
  align-items: center;
  justify-content: center;
}

canvas {
  width: 100%;
  height: 560px;
  border-radius: 14px;
  border: 1px solid rgba(20, 60, 100, 0.06);
  box-shadow: var(--soft-shadow);
  background: linear-gradient(180deg, #ffffff, #f4fbff);
}

.side {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.code,
.distance,
.input {
  background: var(--white-bg);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 8px 28px rgba(7, 22, 48, 0.06);
  transition:
    background 0.4s,
    color 0.4s;
}

.hidden {
  display: none !important;
}

.code .tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.code .tab {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  color: var(--navy);
  background: transparent;
}

.code .tab.active {
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  color: #fff;
}

.code pre {
  margin: 0;
  padding: 14px;
  overflow: auto;
  max-height: 320px;
  line-height: 1.4;
  border-radius: 8px;
  background: var(--white-bg);
  border: 1px solid var(--border-color);
  color: var(--text-color);
}

.distance h3 {
  margin: 0 0 10px 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--navy);
}

.distance table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 6px;
}

.distance th,
.distance td {
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  text-align: center;
  font-size: 14px;
}

.distance th {
  background: var(--table-header-bg);
  color: #fff;
  font-weight: 800;
}

.status {
  background: var(--white-bg);
  padding: 10px 12px;
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(12, 36, 63, 0.06);
  font-weight: 600;
  display: none;
  color: var(--navy);
  margin-top: 10px;
}

.status.show {
  display: block;
  animation: slideFade 0.28s ease both;
}

@keyframes slideFade {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.dist-cell {
  transition:
    box-shadow 0.38s ease,
    background 0.38s ease,
    border-color 0.38s ease;
}
.dist-cell.update-border {
  background: #fff9e6;
  box-shadow: inset 0 0 0 4px rgba(245, 197, 66, 0.16);
  border-color: #f5c542 !important;
}

footer {
  position: sticky;
  bottom: 0;
  background: var(--footer-bg, #e8eef7);
  border-top: 2px solid #a0b7cc;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
  z-index: 999;
}

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
}

#speed {
  width: 200px;
  accent-color: var(--primary);
}
body.dark {
  background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
  color: #e2e8f0;
}

body.dark header {
  background: linear-gradient(90deg, #1e40af, #3b82f6);
  color: #ffffff;
}

body.dark .btn {
  background: #3b82f6;
  color: #ffffff;
}

body.dark .graph {
  background: #1e293b;
}

body.dark .code,
body.dark .distance,
body.dark .input {
  background: #1e293b;
  color: #f1f5f9;
  border-color: rgba(59, 130, 246, 0.2);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}

body.dark .code pre {
  background: #0f172a;
  color: #93c5fd;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

body.dark canvas {
  background: linear-gradient(180deg, #1e293b, #0f172a);
  border: 1px solid rgba(59, 130, 246, 0.1);
}

body.dark .status {
  background: #334155;
  color: #ffffff;
}

body.dark th,
body.dark td,
body.dark label,
body.dark h3,
body.dark .heading {
  color: #ffffff !important;
}

body.dark .distance th {
  background: linear-gradient(90deg, #1e3a8a, #2563eb);
  color: #ffffff;
}

body.dark footer {
  background: #1e293b;
  border-top: 2px solid #3b82f6;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
}

body.dark .controls {
  color: #ffffff;
}

body.dark #speed {
  accent-color: #3b82f6;
}

body.dark footer label,
body.dark footer span {
  color: #ffffff !important;
}

@media (max-width: 980px) {
  main.layout {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .side {
    order: 2;
  }

  .graph {
    order: 1;
    padding: 10px;
    min-height: 420px;
  }

  canvas {
    height: 420px;
  }

  .code {
    width: 100%;
  }
}
