:root {
  color-scheme: light dark;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  line-height: 1.5;
  background: #050505;
  color: #f5f5f5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #1a1a1a, #050505 70%);
}

.container {
  width: min(1200px, 100% - 2rem);
  margin-inline: auto;
}

.site-header {
  padding: 2rem 0 1rem;
}

.site-header h1 {
  margin-bottom: 0.4rem;
  font-size: clamp(1.8rem, 1.5rem + 1vw, 2.6rem);
}

.app-grid {
  display: grid;
  gap: 2rem;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  align-items: start;
  padding: 1rem 0;
}

@media (max-width: 900px) {
  .app-grid {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: rgba(15, 15, 15, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  padding: 1.5rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(18px);
}

.panel h2,
.panel h3 {
  margin-top: 0;
  margin-bottom: 1rem;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1.15rem;
}

.control-group label {
  font-weight: 600;
  font-size: 0.95rem;
}

input[type="file"],
select,
input[type="range"],
.button {
  font: inherit;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

select option,
select optgroup {
  background: #0f0f0f;
  color: #f5f5f5;
}

select {
  padding: 0.5rem 0.65rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.05);
  color: inherit;
}

.palette-grid {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.palette-grid select {
  flex: 1 1 180px;
}

.adaptive-control {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.multitone-control {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.65rem;
}

.multitone-options {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.multitone-pickers {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.multitone-picker {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.multitone-picker input[type="color"] {
  width: 42px;
  height: 32px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.canvas-pair {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.5rem;
}

.dithered-panel {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.levels-controls {
  margin-top: 0.4rem;
  display: grid;
  grid-template-columns: repeat(4, minmax(50px, 1fr));
  gap: 1rem;
  padding: 0.2rem 0;
  width: min(100%, 420px);
}

.levels-wrapper {
  margin-top: 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.levels-toggle {
  align-self: flex-start;
}

.levels-link {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0;
  border: none;
  background: none;
  text-decoration: underline;
  font-size: 0.8rem;
  color: #f5f5f5;
}

.levels-controls:not(.hidden) .levels-link {
  padding-top: 1rem;
}

.levels-toggle {
  padding-top: 0;
}

.levels-link:hover,
.levels-link:focus-visible {
  color: #a5e4ff;
}

.levels-slider {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.85rem;
}

.levels-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
  opacity: 0.65;
  font-size: 0.8rem;
}

.levels-label strong {
  font-size: 0.85rem;
  font-weight: 600;
}

.levels-slider input[type="range"] {
  width: 100%;
}

.canvas-panel {
  position: relative;
  border-radius: 12px;
  padding-bottom: 0.5rem;
  outline: none;
}

.canvas-panel canvas {
  cursor: pointer;
}

.canvas-panel.dragging canvas {
  outline: 3px dashed rgba(56, 189, 248, 0.9);
  outline-offset: 4px;
}

.canvas-hint {
  font-size: 0.8rem;
  opacity: 0.7;
  margin: 0.4rem 0 0;
}

.resize-control {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.resize-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
}

.resize-option {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.95rem;
}

.preset-export {
  margin-top: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.preset-export textarea {
  width: 100%;
  min-height: 120px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.2);
  color: inherit;
  padding: 0.75rem;
  font-family: "JetBrains Mono", "SFMono-Regular", monospace;
  font-size: 0.85rem;
  resize: vertical;
}

.multitone-ramp-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.5rem;
  height: clamp(180px, 30vh, 280px);
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 0.25rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.35) rgba(255, 255, 255, 0.08);
  overscroll-behavior: contain;
}

.multitone-ramp-list::-webkit-scrollbar {
  width: 6px;
}

.multitone-ramp-list::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
}

.multitone-ramp-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.35);
  border-radius: 999px;
}

.ramp-option {
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  padding: 0.2rem;
  cursor: pointer;
  display: flex;
  width: 100%;
  transition: border-color 0.2s, transform 0.15s;
  text-align: left;
}

.ramp-option:focus-visible {
  outline: 2px solid #38bdf8;
  outline-offset: 2px;
}

.ramp-option:hover {
  border-color: rgba(255, 255, 255, 0.35);
}

.ramp-option.selected {
  border-color: #38bdf8;
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.5);
}

.ramp-swatches {
  display: flex;
  border-radius: 6px;
  overflow: hidden;
  min-height: 32px;
  width: 100%;
}

.ramp-color {
  flex: 1;
  min-height: 32px;
  display: block;
}

.ramp-status {
  font-size: 0.85rem;
  opacity: 0.7;
  margin: 0.2rem 0;
}

canvas {
  width: 100%;
  height: auto;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: #111;
}

.preview-actions {
  margin-top: 1.5rem;
  display: flex;
  justify-content: flex-start;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 0.65rem 1.2rem;
  text-decoration: none;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: transparent;
  color: inherit;
  transition: opacity 0.2s, background 0.2s;
}

.button.secondary[disabled] {
  opacity: 0.4;
  pointer-events: none;
}

.button.secondary:not([disabled]):hover {
  background: rgba(255, 255, 255, 0.08);
}

.status {
  font-size: 0.9rem;
  opacity: 0.8;
  min-height: 1.4em;
}

@media (max-width: 600px) {
  .panel {
    padding: 1.25rem;
  }

  .palette-grid select {
    flex-basis: 100%;
  }
}
