:root {
  color-scheme: dark;
  --margin: 1.5rem;
  --bg-colour: #0f1115;
  --panel-colour: #1e2227;
  --accent-colour: #007bff;
  --text-colour: #e0e0e0;
  --text-muted: #aaa;
  --border-colour: #444;
  --input-bg: #2c313a;
  --link-colour: #a5b4fc;
  --card-shadow: rgba(0,0,0,0.5);
  --overlay-bg: rgba(15, 17, 21, 0.9);
}

.light-mode {
  color-scheme: light;
  --margin: 1.5rem;
  --bg-colour: #f0f2f5;
  --panel-colour: #ffffff;
  --text-colour: #1a1d23;
  --text-muted: #64748b;
  --border-colour: #aaa;
  --input-bg: #f1f5f9;
  --link-colour: #4f46e5;
  --overlay-bg: rgba(255, 255, 255, 0.8);
}

body {
  margin: 0;
  background: var(--bg-colour);
  color: var(--text-colour);
  font-family: sans-serif;
  height: 100vh;

  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.dashboard {
  display: grid;
  grid-template-rows: 1fr 0.5fr;
  grid-template-columns: 1fr 1fr;
  gap: var(--margin);
  width: fit-content;
  max-width: 1200px;
  max-height: 95vh;
  margin: 0 auto;
  padding: 2em;
  box-sizing: border-box;
}

.row {
  display: grid;
  grid-column: span 2;
  grid-template-columns: subgrid;
  min-height: 0;
  align-items: center;
  justify-items: center;
}

.row:first-child > :first-child {
  justify-self: start;
}

.row:first-child > :last-child {
  justify-self: end;
}

.row .fw {
  grid-column: span 2;
  justify-self: stretch;
  min-width: 0;
}

.square {
  aspect-ratio: 1 / 1;
  min-width: 100px;
}

.output {
  max-width: 100%;
  max-height: 100%;
  min-width: 0;
  min-height: 0;
  background: #000;
  border: 4px solid var(--border-colour);
  border-radius: 12px;
  box-sizing: border-box;
}

.buttons-container {
  position: fixed;
  top: var(--margin);
  right: var(--margin);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  z-index: 2;
}

.btn-wrapper {
  display: inline-block;
  margin-bottom: 0.6rem;
}

.btn {
  width: 3rem;
  height: 3rem;
  padding: 0.6rem;
  background: var(--accent-colour);
  color: white;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  font-size: 1.5em;
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: background-color 0.2s ease, transform 0.1s ease;
}

.btn:hover {
  filter: brightness(1.1);
}

.btn:active {
  transform: scale(0.96);
  filter: brightness(0.95);
}

.btn:focus-visible {
  outline: 2px solid var(--accent-colour);
  outline-offset: 3px;
}

#settings-btn {
  anchor-name: --anchor-settings;
}

#help-btn {
  anchor-name: --anchor-help;
}

.popup {
  position: fixed;
  padding: 1.5rem;
  border-radius: 12px;
  border: 1px solid var(--border-colour);
  background: var(--panel-colour);
  color: var(--text-colour);
  box-shadow: 0 10px 30px var(--card-shadow);
  width: 280px;
  margin: 0;
  inset: auto;

  top: anchor(bottom);
  right: anchor(right);
  margin-top: 0.6rem;

  overflow: auto;
  max-height: 66vh;
}

.popup::-webkit-scrollbar {
  width: 8px;
  height: 8px;
  background-color: transparent !important;
}

.popup::-webkit-scrollbar-track {
  background: transparent !important;
}

.popup::-webkit-scrollbar-corner {
  background-color: var(--panel-colour);
}

.popup::-webkit-scrollbar-thumb {
  background-color: rgba(155, 155, 155, 0.4);
  border-radius: 20px;
  border: 2px solid transparent;
  background-clip: content-box;
}

.popup::-webkit-scrollbar-thumb:hover {
  background-color: rgba(155, 155, 155, 0.7);
}

.popup {
  scrollbar-width: thin;
  scrollbar-color: rgba(155, 155, 155, 0.4) transparent;
}


#settings-popup {
  position-anchor: --anchor-settings;
}

#help-popup {
  position-anchor: --anchor-help;
  width: 500px;
}

.popup section {
  margin-bottom: 1.2rem;
}

.popup section label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

select {
  width: 100%;
  padding: 0.5rem;
  border-radius: 4px;
  background: var(--input-bg);
  color: var(--text-colour);
  border: 1px solid var(--border-colour);
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;

  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-colour) 50%),
    linear-gradient(135deg, var(--text-colour) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 50%,
    calc(100% - 13px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;

  padding-right: 2rem;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  background: transparent;
  cursor: pointer;
}

input[type="range"]:focus { outline: none; }

input[type="range"]::-webkit-slider-runnable-track {
  height: 8px; background: var(--input-bg); border: 1px solid var(--border-colour); border-radius: 4px;
}

input[type="range"]::-moz-range-track {
  height: 8px; background: var(--input-bg); border: 1px solid var(--border-colour); border-radius: 4px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 18px; width: 18px; border-radius: 50%;
  background: var(--accent-colour); margin-top: -6px; border: none;
}

input[type="range"]::-moz-range-thumb {
  height: 18px; width: 18px; border-radius: 50%;
  background: var(--accent-colour); border: none;
}

input[type="range"]:focus::-webkit-slider-runnable-track { border-color: var(--accent-colour); }
input[type="range"]:focus::-moz-range-track { border-color: var(--accent-colour); }

input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  background-color: var(--input-bg);
  margin: 0;
  font: inherit;
  color: var(--accent-colour);
  width: 1.25rem;
  height: 1.25rem;
  border: 1px solid var(--border-colour);
  border-radius: 4px;
  display: grid;
  place-content: center;
  cursor: pointer;
  transition: border-color 0.15s ease-in-out;
}

input[type="checkbox"]::before {
  content: "";
  width: 0.65rem;
  height: 0.65rem;
  transform: scale(0);
  transition: 120ms transform ease-in-out;
  box-shadow: inset 1em 1em var(--accent-colour);
  background-color: CanvasText;
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}

input[type="checkbox"]:checked::before {
  transform: scale(1);
}

input[type="checkbox"]:focus {
  outline: none;
  border-color: var(--accent-colour);
}

.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: var(--overlay-bg);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  padding: 2rem;
  text-align: center;
}

.card {
  background: var(--panel-colour);
  padding: 2rem;
  border-radius: 12px;
  border: 1px solid var(--border-colour);
  max-width: 500px;
  box-shadow: 0 10px 30px var(--card-shadow);
}

.card h2 {
  margin-top: 0;
}

.card p {
  line-height: 1.6;
  color: var(--text-muted);
}

.card code {
  background: #000;
  padding: 0.5rem;
  margin-top: 1rem;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.9rem;
}

.hidden {
  display: none;
}

.card.error {
  border: 1px solid #ff4444;
}

.card.error h2 {
  color: #ff4444;
}

#error-message {
  white-space: pre-line;
}

.card.message {
  border: 2px solid #4444ff;
}

.card.message h2 {
  color: #4444ff;
}

.plural {
  display: none;
}

.contains-plural .plural {
  display: inline;
}

#drop-overlay {
  pointer-events: none;
  z-index: 99;
}

#no-images-overlay {
  z-index: 0;
  pointer-events: none;
}

footer {
  text-align: center;
  padding: 0;
  font-size: 0.8rem;
  opacity: 0.7;
}

a {
  position: relative;
  color: var(--link-colour);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.3s ease;
}

a::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 1.5px;
  bottom: -2px;
  left: 0;
  background-color: var(--link-colour);
  transform: scaleX(0);
  transform-origin: center;
  transition: transform 0.3s ease-out;
}

a:hover, a:active {
  color: var(--text-colour);
}

a:hover::after, a:active::after {
  transform: scaleX(1);
}

a:active::after {
  background-color: var(--text-colour);
}

/* Light / Dark mode toggle */
.theme-switcher {
  --size: 3rem;
  --gap: 0.5rem;
  --expanded-width: calc((var(--size) * 3) + (var(--gap) * 2));

  width: var(--size);
  height: var(--size);
  position: relative;
  margin-left: auto;

  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.theme-switcher:hover,
.theme-switcher:focus-within {
  width: var(--expanded-width);
  margin-left: calc(auto - (var(--expanded-width) - var(--size)));
}

.theme-option {
  position: absolute;
  top: 0;
  right: 0;

  background: var(--panel-colour);
  border: 1px solid var(--border-colour);
  color: var(--text-muted);

  box-sizing: border-box;
  transition:
    transform 0.4s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.3s,
    background-color 0.2s;
}

.theme-option svg {
  width: 100%;
  height: 100%;
  stroke-width: 2;
}

.theme-option input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}

.theme-option:not(:has(input:checked)) {
  opacity: 0;
  pointer-events: none;
  z-index: 1;
}

.theme-option:has(input:checked) {
  opacity: 1;
  z-index: 5;
  background: var(--accent-colour);
  color: white;
  border-color: transparent;
  transform: translateX(0);
  z-index: 200;
}

.theme-switcher:hover .theme-option,
.theme-switcher:focus-within .theme-option {
  opacity: 1;
  pointer-events: auto;
}

.theme-switcher:hover .theme-option:nth-child(1),
.theme-switcher:focus-within .theme-option:nth-child(1) {
  transform: translateX(calc((var(--size) + var(--gap)) * -2));
}

.theme-switcher:hover .theme-option:nth-child(2),
.theme-switcher:focus-within .theme-option:nth-child(2) {
  transform: translateX(calc((var(--size) + var(--gap)) * -1));
}

.theme-switcher:hover .theme-option:nth-child(3),
.theme-switcher:focus-within .theme-option:nth-child(3) {
  transform: translateX(0);
}

.theme-switcher:not(:hover):not(:focus-within) .theme-option:has(input:checked) {
  transform: translateX(0);
}

.theme-option:has(input:focus-visible) {
  outline: 2px solid var(--accent-colour);
  outline-offset: 3px;
  opacity: 1;
}

.theme-switcher:focus-within .theme-option {
  opacity: 1;
  pointer-events: auto;
}
