:root {
  color-scheme: light dark;
  font-family: sans-serif;
  line-height: 1.5;
  --background: #ffffff;
  --foreground: #171717;
  --muted: #5b5b5b;
  --border: #1f1f1f;
  --soft-border: #b5b5b5;
  --panel: #f5f5f5;
  --accent: #1457a6;
  --accent-foreground: #ffffff;
  --error: #a20e0e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
}

main {
  width: min(100%, 1000px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px;
  border-inline: 2px solid var(--border);
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
}

h2 {
  margin-bottom: 12px;
  font-size: 1.25rem;
}

hr {
  margin: 24px 0;
  border: 0;
  border-top: 1px solid var(--soft-border);
}

button,
select,
input {
  font: inherit;
}

button,
select {
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--background);
  color: var(--foreground);
}

button {
  padding: 7px 16px;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: var(--panel);
}

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

#convert-button,
#copy-button {
  background: var(--accent);
  color: var(--accent-foreground);
  border-color: var(--accent);
}

#convert-button:hover:not(:disabled),
#copy-button:hover:not(:disabled) {
  filter: brightness(0.9);
  background: var(--accent);
}

.drop-zone {
  display: flex;
  min-height: 150px;
  padding: 24px;
  border: 2px dashed var(--soft-border);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 6px;
  text-align: center;
  cursor: pointer;
  background: var(--panel);
}

.drop-zone:hover,
.drop-zone.dragging {
  border-color: var(--accent);
}

.drop-zone span,
.hint,
#result-summary {
  color: var(--muted);
  font-size: 0.9rem;
}

.drop-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.controls {
  display: flex;
  margin-top: 16px;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.controls label {
  display: flex;
  min-width: min(100%, 330px);
  flex-direction: column;
  gap: 5px;
  font-weight: 600;
}

.controls .toggle-control {
  min-width: 0;
  flex-direction: row;
  align-items: center;
  gap: 9px;
}

.toggle-control input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.toggle-control span {
  display: flex;
  flex-direction: column;
}

.toggle-control small {
  color: var(--muted);
  font-weight: 400;
}

select {
  padding: 5px 9px;
}

.button-row {
  display: flex;
  gap: 8px;
}

.hint {
  margin: 12px 0 0;
}

.preview-shell {
  margin-top: 18px;
  padding: 10px;
  border: 1px solid var(--soft-border);
  background: var(--panel);
  text-align: center;
}

#image-preview {
  display: block;
  max-width: 100%;
  max-height: 360px;
  margin: auto;
}

.progress-shell {
  margin-top: 18px;
}

.status-row {
  display: flex;
  margin-bottom: 5px;
  justify-content: space-between;
  gap: 10px;
}

progress {
  width: 100%;
  height: 16px;
}

.error {
  margin: 16px 0 0;
  color: var(--error);
  font-weight: 600;
}

.result-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.result-heading h2 {
  margin-bottom: 2px;
}

#result-summary {
  margin-bottom: 0;
}

.result-scroll {
  max-height: 70vh;
  overflow: auto;
  border: 1px solid var(--border);
  background: #ffffff;
  color: #000000;
}

#ascii-output {
  width: max-content;
  min-width: 100%;
  min-height: 200px;
  margin: 0;
  padding: 16px;
  font-family: Arial, sans-serif;
  line-height: normal;
  white-space: pre;
  background: #ffffff;
  color: #000000;
}

[hidden] {
  display: none !important;
}

@media (max-width: 650px) {
  main {
    padding: 16px;
    border-inline: 0;
  }

  .controls,
  .result-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .controls label {
    min-width: 100%;
  }

  .button-row button,
  #copy-button {
    flex: 1;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #2c2c2c;
    --foreground: #f0f0f0;
    --muted: #c4c4c4;
    --border: #d5d5d5;
    --soft-border: #666666;
    --panel: #383838;
    --accent: #80b3ff;
    --accent-foreground: #151515;
    --error: #ff9a9a;
  }
}
