:root {
  color-scheme: light;
  --background: #ffffff;
  --foreground: #1e1e1e;
  --line: #1e1e1e;
  --muted: #6b6b6b;
  --edge: clamp(22px, 2.5vw, 40px);
  --panel-width: clamp(340px, 27.8vw, 445px);
  --top-line: 1px;
  --header-h: clamp(92px, 13vh, 132px);
  --footer-h: clamp(42px, 7vh, 66px);
  --ui-font: clamp(12px, 1.125vw, 18px);
  --small-font: clamp(10px, 0.875vw, 14px);
  --button-h: clamp(42px, 5.55vh, 50px);
  --download-h: clamp(44px, 6.65vh, 60px);
  --mode-h: clamp(40px, 5.55vh, 50px);
  --range-block-h: clamp(55px, 7.2vh, 65px);
  --panel-top-pad: clamp(48px, 6.1vh, 55px);
  --gap-upload-range: clamp(36px, 6vh, 54px);
  --gap-mode: clamp(14px, 2.45vh, 22px);
  --gap-checkbox: clamp(24px, 3.8vh, 34px);
  --gap-download: clamp(48px, 8.2vh, 74px);
  font-family: Arial, Helvetica, sans-serif;
  background: var(--background);
  color: var(--foreground);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--background);
  color: var(--foreground);
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app {
  position: relative;
  width: 100%;
  height: 100dvh;
  display: grid;
  grid-template-rows: var(--header-h) minmax(0, 1fr) var(--footer-h);
  padding: 0 var(--edge);
  overflow: hidden;
  background: var(--background);
  border-top: var(--top-line) solid var(--line);
  border-bottom: 1px solid var(--line);
}

.header {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  padding-top: clamp(13px, 2.2vh, 20px);
  font-size: var(--small-font);
  line-height: 1.2;
}

.header p {
  margin: 0;
  font-size: clamp(12px, 1.125vw, 18px);
  white-space: nowrap;
}

.header p:last-child {
  text-align: right;
}

.header a {
  color: inherit;
  text-decoration: none;
}

.header a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.logo {
  display: block;
  width: clamp(340px, 33.9vw, 542px);
  height: auto;
  margin-top: clamp(-4px, -0.45vh, 0px);
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: var(--panel-width) minmax(0, 1fr);
  column-gap: clamp(24px, 2vw, 32px);
  overflow: hidden;
}

.panel {
  position: relative;
  z-index: 2;
  display: block;
  width: var(--panel-width);
  align-content: start;
  padding-top: var(--panel-top-pad);
}

.upload-button,
.download-button,
.mode-selector button {
  border: 0;
  border-radius: 3px;
  background: var(--foreground);
  color: var(--background);
  cursor: pointer;
}

.upload-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  height: var(--button-h);
  padding: 0 clamp(12px, 0.94vw, 15px);
  font-size: var(--ui-font);
  line-height: 1.2;
}

.upload-button span:last-child {
  font-size: clamp(11px, 1.125vw, 18px);
  text-align: right;
  white-space: nowrap;
}

.upload-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.range-control {
  display: grid;
  grid-template-rows: auto 30px;
  align-content: end;
  gap: clamp(5px, 0.75vh, 10px);
  height: var(--range-block-h);
}

.upload-button + .range-control {
  margin-top: var(--gap-upload-range);
}

.range-control + .range-control {
  margin-top: 0;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  font-size: var(--ui-font);
  line-height: 1.2;
}

.control-row output {
  min-width: 44px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  --track: var(--line);
  --thumb: var(--foreground);
  width: 100%;
  height: 30px;
  margin: 0;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 1px;
  background: var(--track);
}

input[type="range"]::-webkit-slider-thumb {
  width: 15px;
  height: 15px;
  margin-top: -7px;
  appearance: none;
  border: 0;
  border-radius: 0;
  background: var(--thumb);
}

input[type="range"]::-moz-range-track {
  height: 1px;
  background: var(--track);
}

input[type="range"]::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border: 0;
  border-radius: 0;
  background: var(--thumb);
}

.mode-selector {
  display: grid;
  grid-template-columns: 145fr 145fr 92fr;
  align-items: center;
  column-gap: clamp(18px, 2.68vw, 43px);
  height: var(--mode-h);
  margin-top: var(--gap-mode);
}

.mode-selector button {
  height: var(--mode-h);
  min-width: 0;
  padding: 0 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--foreground);
  font-size: var(--ui-font);
  line-height: 1.2;
}

.mode-selector button.active {
  background: var(--foreground);
  color: var(--background);
}

.checkbox-control {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 30px;
  margin-top: var(--gap-checkbox);
  font-size: var(--ui-font);
  line-height: 1.2;
  cursor: pointer;
}

.checkbox-control input {
  position: absolute;
  width: clamp(22px, 1.85vw, 30px);
  height: clamp(22px, 1.85vw, 30px);
  margin: 0;
  appearance: none;
  opacity: 0;
}

.checkbox-box {
  position: relative;
  flex: 0 0 auto;
  width: clamp(22px, 1.85vw, 30px);
  height: clamp(22px, 1.85vw, 30px);
  border: 1px solid var(--line);
  border-radius: 3px;
  background: transparent;
}

.checkbox-control input:focus-visible + .checkbox-box {
  outline: 1px solid var(--foreground);
  outline-offset: 3px;
}

.checkbox-control input:checked + .checkbox-box::after {
  content: "";
  position: absolute;
  left: 22%;
  top: 47%;
  width: 54%;
  height: 28%;
  border-left: 3px solid var(--foreground);
  border-bottom: 3px solid var(--foreground);
  transform: translateY(-50%) rotate(-45deg);
  transform-origin: center;
}

.download-button {
  width: 100%;
  height: var(--download-h);
  margin-top: var(--gap-download);
  font-size: var(--ui-font);
  line-height: 1.2;
}

.status {
  min-height: 0;
  margin: calc(clamp(4px, 0.65vh, 8px) * -1) 0 0;
  color: var(--muted);
  font-size: clamp(10px, 0.78vw, 12px);
  line-height: 1.25;
}

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  margin-top: var(--panel-top-pad);
  overflow: hidden;
  touch-action: none;
}

#asciiCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.footer {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 20px;
  padding-top: clamp(12px, 2.45vh, 22px);
  font-size: var(--small-font);
  line-height: 1.2;
}

.footer p {
  margin: 0;
  white-space: nowrap;
}

.footer p:last-child {
  text-align: right;
}

@media (max-height: 800px) and (min-width: 768px) {
  :root {
    --header-h: clamp(78px, 12vh, 96px);
    --footer-h: clamp(34px, 6vh, 48px);
    --button-h: 42px;
    --download-h: 44px;
    --mode-h: 40px;
    --range-block-h: 56px;
  }

  .panel {
    padding-top: var(--panel-top-pad);
  }

  .logo {
    width: clamp(300px, 30vw, 430px);
  }

  input[type="range"]::-webkit-slider-thumb {
    width: 12px;
    height: 12px;
    margin-top: -6px;
  }

  input[type="range"]::-moz-range-thumb {
    width: 12px;
    height: 12px;
  }
}

@media (max-width: 1199px) {
  :root {
    --edge: clamp(18px, 3vw, 28px);
    --panel-width: clamp(300px, 34vw, 340px);
  }

  .workspace {
    column-gap: 22px;
  }

  .mode-selector {
    column-gap: 12px;
  }
}

@media (max-width: 900px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow: auto;
  }

  .app {
    min-height: 100dvh;
    height: auto;
    grid-template-rows: auto auto auto;
    overflow: visible;
  }

  .header {
    min-height: 96px;
  }

  .workspace {
    grid-template-columns: 1fr;
    row-gap: 18px;
    overflow: visible;
  }

  .stage {
    order: -1;
    height: 54vh;
    min-height: 360px;
  }

  .panel {
    width: 100%;
    grid-template-rows: none;
    display: flex;
    flex-direction: column;
    row-gap: 18px;
    padding-top: 0;
  }

  .footer {
    min-height: 48px;
    gap: 12px;
  }
}

@media (max-width: 767px) {
  :root {
    --ui-font: 12px;
    --small-font: 12px;
    --button-h: 42px;
    --download-h: 42px;
    --mode-h: 42px;
  }

  .app {
    padding: 0 18px;
  }

  .header {
    grid-template-columns: 1fr 1fr;
    row-gap: 18px;
    min-height: 116px;
    padding-top: 16px;
  }

  .header .logo {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: center;
    width: min(100%, 340px);
    margin-top: 0;
  }

  .header p:last-child {
    font-size: 12px;
  }

  .stage {
    height: 54vh;
    min-height: 360px;
  }

  .upload-button {
    font-size: 12px;
  }

  .upload-button span:last-child {
    font-size: 12px;
  }

  .range-control {
    grid-template-rows: auto 41px;
    gap: 2px;
    height: auto;
  }

  .panel {
    gap: 30px;
  }

  .range-control + .range-control {
    margin-top: -15px;
  }

  input[type="range"] {
    height: 44px;
  }

  input[type="range"]::-webkit-slider-thumb {
    width: 15px;
    height: 15px;
    margin-top: -7px;
  }

  .mode-selector {
    grid-template-columns: repeat(3, 1fr);
    column-gap: 8px;
    margin-top: 0;
  }

  .mode-selector button,
  .control-row,
  .checkbox-control {
    font-size: 12px;
  }

  .checkbox-control input {
    width: 24px;
    height: 24px;
  }

  .checkbox-control {
    margin-top: 0;
  }

  .download-button {
    margin-top: 0;
    font-size: 12px;
  }

  .footer {
    flex-wrap: wrap;
    gap: 4px;
    padding-top: 18px;
    padding-bottom: 14px;
    justify-content: center;
    text-align: center;
  }

  .footer p:first-child {
    width: 100%;
    font-size: 9px;
    white-space: nowrap;
  }

  .footer p:last-child {
    width: 100%;
    font-size: 9px;
    text-align: center;
  }
}
