:root {
  --panel-bg: rgba(255, 255, 255, 0.88);
  --panel-border: rgba(0, 0, 0, 0.12);
  --panel-shadow: 0 14px 45px rgba(0, 0, 0, 0.12);
  --page-bg: #fff;
  --button-bg: #fff;
  --tooltip-bg: #111;
  --tooltip-text: #fff;
  --text: #111;
  --muted: #666;
}

body.is-dark {
  --panel-bg: rgba(18, 18, 20, 0.86);
  --panel-border: rgba(255, 255, 255, 0.16);
  --panel-shadow: 0 16px 50px rgba(0, 0, 0, 0.34);
  --page-bg: #050506;
  --button-bg: #18181b;
  --tooltip-bg: #f6f6f6;
  --tooltip-text: #111;
  --text: #f4f4f5;
  --muted: #b4b4bb;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--page-bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

.stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--page-bg);
  cursor: none;
  touch-action: none;
}

.ascii-field {
  position: absolute;
  inset: 0;
  contain: strict;
  pointer-events: none;
  user-select: none;
}

.ascii-block {
  position: absolute;
  left: 0;
  top: 0;
  margin: 0;
  color: #000;
  font-family: "Courier New", Courier, monospace;
  font-size: var(--font-size);
  font-weight: var(--font-weight);
  line-height: var(--line-height);
  white-space: pre;
  contain: layout style paint;
  will-change: transform, contents, color;
}

.ascii-block.is-gradient {
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
}

.controls {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 5;
  width: min(290px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 12px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel-bg);
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(12px);
  cursor: auto;
  overflow: visible;
}

.controls,
.controls * {
  cursor: auto;
}

.controls__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.controls h1 {
  margin: 0;
  font-size: 14px;
  line-height: 1.2;
  letter-spacing: 0;
}

.controls__toggle {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid rgba(0, 0, 0, 0.18);
  border-radius: 6px;
  background: var(--button-bg);
  color: var(--text);
  font: inherit;
}

.controls__body {
  display: grid;
  gap: 9px;
  max-height: calc(100vh - 92px);
  overflow: auto;
  padding-top: 12px;
}

.controls.is-collapsed .controls__body {
  display: none;
}

.control {
  display: grid;
  grid-template-columns: 98px 1fr;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.control__label {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 5px;
}

.help {
  position: relative;
  display: inline-grid;
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid rgba(0, 0, 0, 0.22);
  border-radius: 50%;
  background: var(--button-bg);
  color: var(--muted);
  font: 700 10px/1 Arial, Helvetica, sans-serif;
  padding: 0;
}

body.is-dark .help {
  border-color: rgba(255, 255, 255, 0.24);
}

.tooltip {
  position: fixed;
  z-index: 20;
  width: min(230px, calc(100vw - 40px));
  padding: 8px 9px;
  border-radius: 7px;
  background: var(--tooltip-bg);
  color: var(--tooltip-text);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
  font-size: 11px;
  font-weight: 400;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  text-align: left;
  transform: translateY(4px);
  transition: opacity 120ms ease, transform 120ms ease;
}

.tooltip.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.control input {
  width: 100%;
  accent-color: #111;
}

.control input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 18px;
  background: transparent;
}

.control input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  border: 1px solid rgba(0, 0, 0, 0.24);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.12);
}

.control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border: 2px solid #111;
  border-radius: 50%;
  background: #111;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.5);
}

.control input[type="range"]::-moz-range-track {
  height: 5px;
  border: 1px solid rgba(0, 0, 0, 0.24);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.12);
}

.control input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 2px solid #111;
  border-radius: 50%;
  background: #111;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.5);
}

body.is-dark .control input[type="range"] {
  accent-color: #f4f4f5;
}

body.is-dark .control input[type="range"]::-webkit-slider-runnable-track {
  border-color: rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.16);
}

body.is-dark .control input[type="range"]::-webkit-slider-thumb {
  border-color: #050506;
  background: #f4f4f5;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.9), 0 2px 8px rgba(0, 0, 0, 0.65);
}

body.is-dark .control input[type="range"]::-moz-range-track {
  border-color: rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.16);
}

body.is-dark .control input[type="range"]::-moz-range-thumb {
  border-color: #050506;
  background: #f4f4f5;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.9), 0 2px 8px rgba(0, 0, 0, 0.65);
}

.control--check input {
  justify-self: start;
  width: 18px;
  height: 18px;
  margin: 0;
}

@media (max-width: 640px) {
  .controls {
    top: auto;
    right: 12px;
    bottom: 12px;
    left: 12px;
    width: auto;
    max-height: 44vh;
    padding: 10px;
  }

  .controls h1 {
    font-size: 13px;
  }

  .controls__body {
    grid-template-columns: 1fr 1fr;
    column-gap: 14px;
    max-height: calc(44vh - 46px);
  }

  .control {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}
