html {
  box-sizing: border-box;
}
*,
*:before,
*:after {
  box-sizing: inherit;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  margin: 0;
  padding: 0;
  height: 100dvh;
  overflow: hidden;
  color: #eaeaea;
  background-color: #101010;
}

[x-cloak] {
  display: none !important;
}

.page-wrapper {
  display: flex;
  height: 100%;
  padding: 20px;
  gap: 20px;
}

.left-column {
  width: 350px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 15px;
  overflow-y: auto;
  padding-right: 10px;
}

.right-column {
  border: 1px solid #333;
  border-radius: 6px;
  background: #1f1f1f;
  justify-content: center;
  align-items: center;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 40px;
  overflow-x: auto;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

select,
input[type="range"],
input[type="text"] {
  padding: 8px 12px;
  border: 1px solid #333;
  border-radius: 4px;
  font-size: 14px;
  background-color: #1f1f1f;
  color: #eaeaea;
}
input[type="range"] {
  padding: 0;
}

.btn {
  padding: 10px 18px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background-color 0.2s, transform 0.1s;
}
.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: #60a5fa;
  color: #101010;
}
.btn-primary:hover {
  background: #3b82f6;
}

.btn-secondary {
  background: #373737;
  color: #eaeaea;
}
.btn-secondary:hover {
  background: #4a4a4a;
}

.btn-warning {
  background: #f59e0b;
  color: #1f1f1f;
}
.btn-warning:hover {
  background: #d97706;
}

.algorithm-details,
.array-display,
.step-info {
  background: #1f1f1f;
  color: #eaeaea;
  padding: 15px;
  border-radius: 6px;
}
.algorithm-details h3,
.algorithm-details h4 {
  color: #60a5fa;
  margin-top: 0;
}
.algorithm-details h4 {
  margin-top: 10px;
  margin-bottom: 5px;
}
.algorithm-details ul {
  list-style-type: none;
  padding-left: 0;
  margin-bottom: 0;
}
.algorithm-details li {
  padding: 2px 0;
}
.array-display {
  word-break: break-all;
  font-family: monospace;
}
.step-info {
  font-family: monospace;
}

.visualization {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 100%;
  gap: 2px;
  height: 90%;
}

.bar {
  background: #60a5fa;
  border-radius: 2px 2px 0 0;
  min-width: 4px;
  position: relative;
  transition: height 0.3s ease;
}
.bar.comparing {
  background: #fbbf24;
}
.bar.swapping {
  background: #f87171;
}
.bar.sorted {
  background: #34d399;
}
.bar-value {
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  font-weight: bold;
  color: #eaeaea;
}

h1 {
  color: #60a5fa;
  text-align: center;
  margin-top: 0;
  margin-bottom: 0;
  font-size: 1.8em;
}

.loading {
  text-align: center;
  padding: 20px;
  color: #eaeaea;
  font-size: 1.1em;
  background: #1f1f1f;
  border-radius: 6px;
}

.speed-control {
  display: flex;
  align-items: center;
  gap: 10px;
  background-color: #1f1f1f;
  padding: 10px;
  border-radius: 4px;
}
.speed-control label {
  white-space: nowrap;
}
.speed-control input[type="range"] {
  flex-grow: 1;
}
.speed-control span {
  min-width: 25px;
  text-align: right;
}

.left-column::-webkit-scrollbar {
  width: 8px;
}
.left-column::-webkit-scrollbar-track {
  background: #101010;
  border-radius: 4px;
}
.left-column::-webkit-scrollbar-thumb {
  background: #373737;
  border-radius: 4px;
}
.left-column::-webkit-scrollbar-thumb:hover {
  background: #4a4a4a;
}

@media (max-width: 768px) {
  body {
    height: auto;
    overflow: auto;
  }

  .page-wrapper {
    flex-direction: column-reverse;
    padding: 10px;
    height: 100%;
  }

  .left-column {
    width: 100%;
    overflow-y: visible;
    padding-right: 0;
    flex-direction: column;
    flex: 0 0 auto;
  }

  .left-column .algorithm-details,
  .left-column .array-display,
  .left-column .step-info {
    display: none;
  }

  .left-column .controls {
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    flex-wrap: wrap;
  }

  .left-column .controls .speed-control {
    flex: 1;
    min-width: 150px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 5px;
    padding: 5px;
    background-color: transparent;
  }

  .left-column .controls .speed-control label {
    text-align: center;
    white-space: normal;
  }

  .left-column .controls .speed-control input[type="range"] {
    width: 100%;
  }

  .left-column .controls .speed-control span {
    text-align: center;
    min-width: auto;
  }

  .left-column h1 {
    display: none !important;
  }
  .left-column label[for="algorithmSelect"] {
    display: none !important;
  }
  .left-column select#algorithmSelect,
  .left-column .btn {
    display: block;
    margin-bottom: 10px;
  }

  .left-column .btn {
    width: 100%;
  }

  .right-column {
    width: 100%;
    flex: 1 1 auto;

    padding: 10px;
    display: grid;

    grid-template-columns: 100%;
    grid-template-rows: 100%;
  }

  .visualization {
    width: 100%;
    height: 50dvh;
  }

  .bar {
    min-height: 1px;
  }
}
