body {
  background: hsl(230deg, 5%, 5%);
  color: hsl(230deg, 5%, 80%);
  font-family: Quicksand, sans-serif;
  font-weight: 100;
  padding: 0;
  margin: 0;
  height: 100%;
  width: 100%;
}

* {
  box-sizing: border-box;
}

h1, h2, h3, h4 {
  color: white;
  font-weight: 100;
  margin-bottom: 0;
}

h1 {
  font-size: 1.6rem;
  margin-top: .5rem;
}

h3 {
  margin-top: 1.5rem;
  margin-bottom: .4rem;
  font-size: 1rem;
}

.hint {
  color: hsl(230deg, 5%, 55%);
  font-size: .85rem;
}

.card {
  width: 1200px;
  max-width: 95%;
  min-height: 100vh;
  margin: 0 auto;
  padding: 1.5rem 2rem 3rem;
  border-radius: 5px;
  background: hsl(230deg, 5%, 15%);
  border-top: 1px solid #3b3d3f;
  box-shadow: 0 2px 3px rgb(10 10 10 / 10%), 0 0 0 1px rgb(10 10 10 / 10%);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .5rem;
}

.card-header h1 {
  margin: 0;
}

.history-controls {
  display: inline-flex;
  gap: 6px;
}

.mode-switch {
  display: inline-flex;
  border: 1px solid #3b3d3f;
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
  margin: .25rem 0 1rem;
}

.mode-btn {
  background: transparent;
  border: 0;
  padding: 8px 22px;
  border-radius: 6px;
  font-family: "Syne Mono", monospace;
  font-weight: 100;
  font-size: 1rem;
  color: hsl(230deg, 5%, 65%);
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}

.mode-btn:hover {
  color: white;
  background: hsl(230deg, 5%, 18%);
}

.mode-btn.active {
  background: hsl(230deg, 5%, 22%);
  color: deepskyblue;
  box-shadow: inset 0 -2px 0 deepskyblue;
}

.mode-btn.active:hover {
  color: deepskyblue;
}

.palette-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 .4rem;
}

.palette-header h3 {
  margin: 0;
}

#paletteGrid {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  margin-bottom: 15px;
  padding: 10px;
  background: #111;
  border-radius: 8px;
  border: 1px solid #3b3d3f;
}

.palette-block {
  flex: 1 1 0;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 3px;
}

.palette-cell {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 3px;
  overflow: hidden;
  user-select: none;
  transition: transform .12s ease, border-color .12s ease;
}

.palette-cell.empty {
  cursor: default;
  pointer-events: none;
  background: transparent;
}

.palette-cell .swatch {
  position: absolute;
  inset: 0;
  border-radius: 1px;
}

.palette-cell .code,
.palette-cell .name {
  display: none;
}

#paletteGrid:not(.show-names) .palette-cell:hover:not(.empty) {
  transform: scale(1.2);
  z-index: 1;
}

.palette-cell.in-gradient {
  border-color: deepskyblue;
  box-shadow: 0 0 6px hsl(195deg, 100%, 50%, .55);
}

.position-badge {
  display: none;
  position: absolute;
  top: -2px;
  right: -2px;
  font-family: "Syne Mono", monospace;
  font-weight: 100;
  font-size: 9px;
  line-height: 1.2;
  color: #000;
  background: deepskyblue;
  padding: 0 3px;
  border-radius: 6px;
  box-shadow: 0 0 4px hsl(195deg, 100%, 50%, .6);
  pointer-events: none;
  z-index: 3;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.palette-cell.in-gradient .position-badge {
  display: inline-block;
}

.palette-cell.is-current {
  border-color: #fff;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.6);
}

.palette-cell.is-brush {
  border-color: #FFBF27;
  box-shadow: 0 0 6px rgba(255, 191, 39, 0.7);
}

.palette-cell.in-gradient.is-current {
  border-color: deepskyblue;
  box-shadow: 0 0 0 1px #fff, 0 0 6px hsl(195deg, 100%, 50%, .55);
}

#paletteGrid.show-names {
  flex-direction: column;
  flex-wrap: nowrap;
}

#paletteGrid.show-names .palette-block {
  flex: 0 0 auto;
  width: 100%;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-auto-rows: auto;
  gap: 2px;
}

#paletteGrid.show-names .palette-cell {
  position: static;
  aspect-ratio: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px;
  border: 1px solid transparent;
  border-radius: 3px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  transition: background .12s ease, border-color .12s ease;
}

#paletteGrid.show-names .palette-cell:hover:not(.empty) {
  background: hsl(230deg, 5%, 18%);
}

#paletteGrid.show-names .palette-cell.in-gradient {
  background: hsl(195deg, 60%, 15%);
  border-color: deepskyblue;
  box-shadow: none;
}

#paletteGrid.show-names .palette-cell.is-current {
  background: hsl(230deg, 5%, 22%);
  border-color: #fff;
  box-shadow: none;
}

#paletteGrid.show-names .palette-cell.is-brush {
  background: hsl(48deg, 60%, 18%);
  border-color: #FFBF27;
  box-shadow: none;
}

#paletteGrid.show-names .palette-cell.in-gradient.is-current {
  background: hsl(195deg, 60%, 18%);
  border-color: deepskyblue;
  box-shadow: inset 0 0 0 1px #fff;
}

#paletteGrid.show-names .position-badge {
  position: static;
  font-size: .7rem;
  padding: 0 4px;
  border-radius: 3px;
  flex: 0 0 auto;
}

#paletteGrid.show-names .palette-cell .swatch {
  position: static;
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  border-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

#paletteGrid.show-names .palette-cell .code {
  display: inline;
  font-family: Quicksand, sans-serif;
  font-size: .8rem;
  letter-spacing: 0.02em;
  flex: 0 0 auto;
}

#paletteGrid.show-names .palette-cell .name {
  display: inline;
  font-size: .75rem;
  letter-spacing: 0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
  min-width: 0;
}

@media screen and (max-width: 900px) {
  #paletteGrid:not(.show-names) {
    flex-wrap: wrap;
  }
  #paletteGrid:not(.show-names) .palette-block {
    flex: 0 0 auto;
    grid-template-columns: repeat(6, 24px);
  }
  #paletteGrid:not(.show-names) .palette-cell {
    aspect-ratio: 1;
  }
  #paletteGrid.show-names .palette-cell .name {
    display: none;
  }
}

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

button {
  padding: 0.45rem 0.9rem;
  background: hsl(230deg, 5%, 18%);
  color: hsl(230deg, 5%, 90%);
  border: 1px solid #3b3d3f;
  border-radius: 5px;
  font-family: "Syne Mono", monospace;
  font-weight: 100;
  font-size: 1rem;
  cursor: pointer;
  letter-spacing: 0.05em;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}

button:hover:not(:disabled) {
  background: hsl(230deg, 5%, 25%);
  color: white;
}

button:focus-visible {
  outline: 1px solid hsl(230deg, 5%, 90%);
}

button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

select {
  padding: 0.45rem 0.9rem;
  background: #494950;
  color: hsl(230deg, 5%, 90%);
  border: 0;
  border-radius: 5px;
  font-family: "Syne Mono", monospace;
  font-weight: 100;
  font-size: 1rem;
  cursor: pointer;
  letter-spacing: 0.05em;
  transition: background .15s ease;
}

select:hover {
  background: hsl(230deg, 5%, 35%);
}

select:focus-visible {
  outline: 1px solid hsl(230deg, 5%, 90%);
}

select:focus {
  outline: none;
  box-shadow: 0 0 0 1px deepskyblue, 0 0 6px deepskyblue;
  background-color: hsl(230deg, 5%, 25%);
  color: white;
}

.toggle-switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  font-family: Quicksand, sans-serif;
  font-weight: 100;
  font-size: .9rem;
  color: hsl(230deg, 5%, 75%);
}

.toggle-switch input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.toggle-track {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 18px;
  background: hsl(230deg, 5%, 22%);
  border: 1px solid #3b3d3f;
  border-radius: 18px;
  transition: background .15s ease, border-color .15s ease;
  flex: 0 0 36px;
}

.toggle-thumb {
  position: absolute;
  top: 1px;
  left: 1px;
  width: 14px;
  height: 14px;
  background: hsl(230deg, 5%, 70%);
  border-radius: 50%;
  transition: transform .18s ease, background .15s ease;
}

.toggle-switch input:checked ~ .toggle-track {
  background: hsl(195deg, 80%, 35%);
  border-color: deepskyblue;
}

.toggle-switch input:checked ~ .toggle-track .toggle-thumb {
  transform: translateX(17px);
  background: #fff;
}

.toggle-switch input:focus-visible ~ .toggle-track {
  box-shadow: 0 0 0 2px hsl(195deg, 100%, 50%, .35);
}

.toggle-switch input:checked ~ .toggle-text {
  color: white;
}

.btn-primary {
  background: hsl(195deg, 80%, 30%);
  color: white;
  border-color: deepskyblue;
}

.btn-primary:hover:not(:disabled) {
  background: hsl(195deg, 90%, 38%);
  color: white;
  border-color: deepskyblue;
}

.editor-actions {
  margin-top: .4rem;
  justify-content: flex-end;
}

.controls-end {
  justify-content: flex-end;
}

textarea {
  width: 100%;
  min-height: 60px;
  resize: vertical;
  background: #111;
  color: hsl(230deg, 5%, 90%);
  padding: 10px 12px;
  border: 1px solid #3b3d3f;
  border-radius: 6px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: Quicksand, sans-serif;
  font-weight: 100;
  font-size: .95rem;
  box-sizing: border-box;
}

textarea:focus {
  outline: none;
  border-color: deepskyblue;
  box-shadow: 0 0 6px hsl(195deg, 100%, 50%, .35);
}

#rawOutput {
  min-height: 90px;
  resize: none;
  overflow: hidden;
}

#editor {
  min-height: 130px;
  background: #111;
  color: hsl(230deg, 5%, 90%);
  padding: 14px 16px;
  border: 1px solid #3b3d3f;
  border-radius: 6px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: Quicksand, sans-serif;
  font-weight: 100;
  font-size: 1.05rem;
  line-height: 1.5;
  outline: none;
  box-sizing: border-box;
  margin-bottom: 8px;
  transition: border-color .2s ease, box-shadow .2s ease;
}

#editor:focus {
  border-color: deepskyblue;
  box-shadow: 0 0 8px hsl(195deg, 100%, 50%, .35);
}

#editor:empty::before {
  content: attr(data-placeholder);
  color: hsl(230deg, 5%, 40%);
  pointer-events: none;
}

#editor ::selection,
#editor::selection {
  background: hsla(195, 100%, 55%, 0.32);
  color: inherit;
}

#editor:not(:focus) .selection-mark {
  background: hsla(195, 100%, 55%, 0.32);
}

#stops {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  min-height: 47px;
  padding: 8px;
  background: #111;
  border: 1px dashed #3b3d3f;
  border-radius: 6px;
}

.stop {
  padding: 6px 12px;
  border-radius: 4px;
  cursor: grab;
  font-size: .85rem;
  color: #000;
  font-family: "Syne Mono", monospace;
  font-weight: 100;
  letter-spacing: 0.05em;
  user-select: none;
}

.stop:active {
  cursor: grabbing;
}

#gradientPreview {
  min-height: 32px;
  border: 1px solid #3b3d3f;
  border-radius: 6px;
  margin: 10px 0;
  background: #111;
}

#gradientPanel {
  border: 1px solid #3b3d3f;
  padding: .75rem 1rem 1rem;
  margin: 1rem 0;
  background: hsl(230deg, 5%, 12%);
  border-radius: 8px;
}

#gradientPanel h3 {
  margin: 0 0 .35rem;
}

label[for="smoothnessInput"] {
  display: inline-flex;
  align-items: center;
  padding:0.45rem 0.9rem 0.45rem 0.9rem;
  border: 1px solid #3b3d3f;
  border-right: 0;
  border-radius: 5px 0 0 5px;
  background: hsl(230deg, 5%, 18%);
  color: hsl(230deg, 5%, 90%);
  font-family: "Syne Mono", monospace;
  font-weight: 100;
  font-size: 1rem;
  letter-spacing: 0.05em;
  margin-right: -10px;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}

#smoothnessInput {
  width: 64px;
  padding: 0.45rem 0.6rem;
  background: hsl(230deg, 5%, 18%);
  color: hsl(230deg, 5%, 90%);
  border: 1px solid #3b3d3f;
  border-radius: 0 5px 5px 0;
  font-family: "Syne Mono", monospace;
  font-weight: 100;
  font-size: 1rem;
  letter-spacing: 0.05em;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}

#smoothnessInput:hover:not(:disabled),
label[for="smoothnessInput"]:has(+ #smoothnessInput:hover:not(:disabled)) {
  border-color: deepskyblue;
  background: hsl(230deg, 5%, 25%);
  color: white;
}

#smoothnessInput:focus {
  outline: none;
  border-color: deepskyblue;
  box-shadow: 0 0 6px hsl(195deg, 100%, 50%, .35);
}

#smoothnessInput:disabled {
  background: hsl(230deg, 5%, 12%);
  color: hsl(230deg, 5%, 40%);
  cursor: not-allowed;
  -moz-appearance: textfield;
  appearance: textfield;
}

#smoothnessInput:disabled::-webkit-inner-spin-button,
#smoothnessInput:disabled::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
  display: none;
}

label[for="smoothnessInput"]:has(+ #smoothnessInput:disabled) {
  background: hsl(230deg, 5%, 12%);
  color: hsl(230deg, 5%, 40%);
  cursor: not-allowed;
}

label:has(> input[type="checkbox"]):not(.toggle-switch) {
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 0.9rem;
  border-radius: 5px;
  border: 1px solid #3b3d3f;
  background: hsl(230deg, 5%, 18%);
  color: hsl(230deg, 5%, 90%);
  cursor: pointer;
  user-select: none;
  font-family: "Syne Mono", monospace;
  font-weight: 100;
  font-size: 1rem;
  letter-spacing: 0.05em;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}

label:has(> input[type="checkbox"]):not(.toggle-switch)::before {
  content: "";
  display: inline-block;
  width: 13px;
  height: 13px;
  margin-right: 8px;
  border: 1px solid hsl(230deg, 5%, 55%);
  border-radius: 3px;
  background: hsl(230deg, 5%, 12%);
  background-repeat: no-repeat;
  background-position: center;
  background-size: 11px 11px;
  flex-shrink: 0;
  transition: background-color .15s ease, border-color .15s ease;
}

label:has(> input[type="checkbox"]:checked):not(.toggle-switch)::before {
  background-color: white;
  border-color: white;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%23146e8e' stroke-width='3' stroke-linecap='round' stroke-linejoin='round' d='M3 8l3 3 7-7'/%3E%3C/svg%3E");
}

label:has(> input[type="checkbox"]):not(.toggle-switch):hover:not(:has(> input:disabled)) {
  background: hsl(230deg, 5%, 25%);
  color: white;
}

label:has(> input[type="checkbox"]):not(.toggle-switch):hover:not(:has(> input:disabled))::before {
  border-color: deepskyblue;
}

label:has(> input[type="checkbox"]:checked):not(.toggle-switch) {
  background: hsl(195deg, 80%, 30%);
  color: white;
  border-color: deepskyblue;
}

label:has(> input[type="checkbox"]:checked):not(.toggle-switch):hover:not(:has(> input:disabled)) {
  background: hsl(195deg, 90%, 38%);
}

label:has(> input[type="checkbox"]:disabled):not(.toggle-switch) {
  opacity: 0.35;
  cursor: not-allowed;
}

label:has(> input[type="checkbox"]:focus-visible):not(.toggle-switch) {
  outline: 1px solid hsl(230deg, 5%, 90%);
}

label:not(.toggle-switch) > input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  margin: 0;
  pointer-events: none;
}

label {
  cursor: pointer;
}

#rawCounter {
  margin: 6px 0;
  font-size: .8rem;
  color: hsl(230deg, 5%, 55%);
  letter-spacing: 0.05em;
}

#rawCounterChars {
  margin-bottom: 0.4rem;
}

.output h3 {
  margin-top: 22px;
}

#flashHint {
  font-family: "Syne Mono", monospace !important;
  font-weight: 100 !important;
}

::-webkit-scrollbar {
  height: 10px;
  width: 8px;
}

::-webkit-scrollbar-track {
  background: hsl(230deg, 5%, 40%);
}

::-webkit-scrollbar-thumb {
  background: hsl(230deg, 5%, 80%);
}

::-webkit-scrollbar-thumb:hover {
  background: hsl(230deg, 5%, 60%);
}

::-webkit-scrollbar-thumb:active {
  background: hsl(230deg, 5%, 60%);
}

@media screen and (max-width: 700px) {
  .card {
    padding: 1rem;
    max-width: 100%;
  }
  h1 {
    font-size: 1.3rem;
  }
}
