:root {
  --sort-swap: #e05050;
  --sort-card-shadow: 0 18px 30px rgba(26, 26, 26, 0.05);
}

main {
  max-width: 68rem;
  padding-top: 5rem;
}

.site-header {
  margin-bottom: 2rem;
}

.algorithm-card,
.sort-panel,
.status-card,
.chart-card {
  background: var(--wa-white);
  border: 1px solid var(--wa-gray-light);
  border-radius: 6px;
  box-shadow: var(--sort-card-shadow);
}

.algorithm-card {
  margin-bottom: 1.25rem;
  padding: 1rem 1.25rem;
}

.algorithm-card-heading h2 {
  font-size: 1rem;
  margin-bottom: 0.3rem;
}

.algorithm-card-heading p {
  color: var(--wa-ink-light);
  font-size: 0.93rem;
}

.algorithm-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 0.95rem;
}

.algorithm-meta-item {
  padding-top: 0.8rem;
  border-top: 1px solid var(--wa-gray-light);
}

.algorithm-meta-item dt {
  font-size: 0.72rem;
  color: var(--wa-gray);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.algorithm-meta-item dd {
  margin-top: 0.2rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--wa-ink);
}

.sort-panel {
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.field {
  display: grid;
  gap: 0.55rem;
}

.field-label {
  font-size: 0.85rem;
  color: var(--wa-ink-light);
}

.field strong {
  color: var(--wa-orange-dark);
  font-size: 0.95rem;
  margin-left: 0.35rem;
}

.field select,
.field input[type="range"] {
  width: 100%;
}

.field select {
  appearance: none;
  border: 1px solid var(--wa-gray-light);
  border-radius: 4px;
  background: var(--wa-white);
  color: var(--wa-ink);
  font: inherit;
  padding: 0.7rem 0.85rem;
}

.field-mode {
  border: none;
  padding: 0;
}

.mode-toggle {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(4.75rem, 1fr));
  width: fit-content;
  align-items: center;
  gap: 0.2rem;
  border: 1px solid var(--wa-gray-light);
  border-radius: 999px;
  background: var(--wa-bg);
  padding: 0.25rem;
}

.mode-option {
  position: relative;
  display: block;
  cursor: pointer;
}

.mode-option input {
  position: absolute;
  opacity: 0;
  inset: 0;
}

.mode-option span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  color: var(--wa-ink-light);
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.2;
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.mode-option input:checked + span {
  background: var(--wa-orange);
  color: var(--wa-white);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
}

.action-row .btn-primary {
  margin: 0;
}

.action-button {
  appearance: none;
  border: 1px solid var(--wa-gray-light);
  border-radius: 6px;
  background: var(--wa-white);
  color: var(--wa-ink);
  font: inherit;
  font-weight: 700;
  padding: 0.85rem 1.2rem;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

.action-button:hover:not(:disabled) {
  border-color: var(--wa-orange);
  color: var(--wa-orange-dark);
}

.action-button:disabled,
.btn-primary:disabled {
  opacity: 0.5;
  cursor: default;
}

.warning-banner {
  margin-top: 1rem;
  padding: 0.8rem 1rem;
  border-radius: 4px;
  background: #fff3ef;
  border: 1px solid #f5c6ba;
  color: #7e3b31;
  font-size: 0.88rem;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.25rem;
}

.status-card {
  padding: 1rem 1.1rem;
}

.status-label {
  font-size: 0.72rem;
  color: var(--wa-gray);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.status-value {
  margin-top: 0.3rem;
  font-size: clamp(1.5rem, 3vw, 2.2rem);
  font-weight: 700;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.status-text {
  margin-top: 0.4rem;
  font-weight: 700;
  color: var(--wa-ink-light);
}

.chart-card {
  padding: 1.25rem;
}

.chart-heading {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.chart-heading h2 {
  font-size: 1.1rem;
  margin-bottom: 0.15rem;
}

.chart-heading p {
  font-size: 0.88rem;
  color: var(--wa-ink-light);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.4rem 0.8rem;
  font-size: 0.78rem;
  color: var(--wa-gray);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-swatch {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 2px;
  background: var(--wa-orange);
  border: 1px solid rgba(26, 26, 26, 0.08);
}

.legend-swatch.is-compare {
  background: var(--wa-sea);
}

.legend-swatch.is-swap {
  background: var(--sort-swap);
}

.legend-swatch.is-sorted {
  background: var(--wa-green);
}

.legend-swatch.is-pivot {
  background: var(--wa-orange);
  border: 2px solid var(--wa-ink);
}

.chart-shell {
  position: relative;
  min-height: 26rem;
  padding: 1.5rem 0.85rem 0.75rem 2.8rem;
  background:
    linear-gradient(to bottom, rgba(255, 255, 255, 0.84), rgba(255, 255, 255, 0.84)),
    repeating-linear-gradient(
      to right,
      rgba(255, 153, 0, 0.03) 0,
      rgba(255, 153, 0, 0.03) 24px,
      rgba(247, 245, 240, 0.5) 24px,
      rgba(247, 245, 240, 0.5) 48px
    );
  border: 1px solid var(--wa-gray-light);
  border-radius: 6px;
  overflow: hidden;
}

.chart-grid {
  position: absolute;
  inset: 1rem 0.75rem 0.75rem 0.75rem;
  display: grid;
  grid-template-rows: repeat(4, 1fr);
  pointer-events: none;
}

.chart-grid span {
  align-self: start;
  position: relative;
  color: var(--wa-gray);
  font-size: 0.72rem;
  padding-left: 0.2rem;
}

.chart-grid span::after {
  content: "";
  position: absolute;
  top: 0.7rem;
  left: 2.1rem;
  right: 0;
  border-top: 1px dashed rgba(107, 114, 128, 0.22);
}

.chart-bars {
  position: relative;
  z-index: 1;
  height: 23rem;
  display: grid;
  align-items: end;
  gap: 0.35rem;
}

.bar-slot {
  position: relative;
  min-width: 0;
  height: 100%;
}

.bar-item {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  align-items: center;
  min-width: 0;
  height: 100%;
  will-change: transform;
}

.bar-shape {
  position: relative;
  width: 100%;
  min-height: 1.5rem;
  align-self: end;
  border-radius: 4px 4px 0 0;
  background: var(--wa-orange);
  border: 1px solid rgba(26, 26, 26, 0.08);
}

.bar-item.is-compare .bar-shape {
  background: var(--wa-sea);
}

.bar-item.is-swap .bar-shape {
  background: var(--sort-swap);
}

.bar-item.is-sorted .bar-shape {
  background: var(--wa-green);
}

.bar-item.is-sorted .mikan-tag {
  color: var(--wa-green);
}

.bar-item.is-pivot .bar-shape {
  box-shadow: inset 0 0 0 3px rgba(26, 26, 26, 0.75);
}

.bar-value {
  position: absolute;
  top: 0.35rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--wa-white);
  white-space: nowrap;
  line-height: 1;
}

.bar-caption {
  position: relative;
  width: 100%;
  margin-top: 0.45rem;
  min-height: 3rem;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow: visible;
}

.bar-caption.is-mountain {
  min-height: 3.4rem;
}

.bar-label {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  width: max-content;
  max-width: 7rem;
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(43, 122, 158, 0.18);
  color: var(--wa-ink-light);
  font-size: 0.64rem;
  line-height: 1.35;
  text-align: center;
  white-space: nowrap;
  z-index: 1;
}

.bar-subvalue {
  display: block;
  color: var(--wa-gray);
  font-size: 0.6rem;
}

.mikan-tag {
  display: inline-block;
  font-size: 0.66rem;
  color: var(--wa-orange-dark);
  line-height: 1.1;
  writing-mode: vertical-rl;
  text-orientation: upright;
  white-space: nowrap;
  letter-spacing: 0.08em;
}

@media (max-width: 900px) {
  .control-grid,
  .algorithm-meta,
  .status-grid {
    grid-template-columns: 1fr;
  }

  .chart-heading {
    flex-direction: column;
  }

  .legend {
    justify-content: flex-start;
  }
}

@media (max-width: 640px) {
  main {
    padding-top: 4.5rem;
  }

  .sort-panel,
  .chart-card,
  .algorithm-card {
    padding: 1rem;
  }

  .action-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .action-row .btn-primary,
  .action-button {
    width: 100%;
  }

  .chart-shell {
    min-height: 22rem;
    padding-left: 2.2rem;
  }

  .chart-bars {
    height: 19rem;
    gap: 0.2rem;
  }

  .bar-label {
    max-width: 5rem;
    font-size: 0.58rem;
  }
}
