:root {
  color-scheme: light dark;
  --text: #1b1b1f;
  --muted: #4a4a52;
  --surface: #ffffff;
  --panel: #f1f3f8;
  --line: #767680;
  --accent: #0b57d0;
  --on-accent: #ffffff;
  --error: #b3261e;
}

@media (prefers-color-scheme: dark) {
  :root {
    --text: #e6e6ec;
    --muted: #b4b4bf;
    --surface: #121316;
    --panel: #1c1e24;
    --line: #8a8a96;
    --accent: #8ab4f8;
    --on-accent: #0b0b0f;
    --error: #ffb4ab;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--surface);
  color: var(--text);
  font: 1rem/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-wrap: anywhere;
}

a {
  color: var(--accent);
}

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

[hidden] {
  display: none !important;
}

header,
main,
footer {
  max-width: 44rem;
  margin: 0 auto;
  padding: 1rem;
}

header a {
  display: inline-block;
  min-height: 44px;
  font-weight: 700;
  line-height: 44px;
  text-decoration: none;
}

h1 {
  margin: 1rem 0 0.5rem;
  font-size: 1.75rem;
  line-height: 1.25;
}

.tool {
  margin: 1.5rem 0;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--panel);
}

.tool label {
  display: block;
  margin: 0.75rem 0 0.25rem;
  font-weight: 600;
}

.tool input[type="text"],
.tool select {
  width: 100%;
  min-height: 44px;
  padding: 0.5rem;
  border: 1px solid var(--line);
  border-radius: 0.25rem;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.tool input[aria-invalid="true"] {
  border-color: var(--error);
  border-width: 2px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0 1rem;
}

.row > * {
  flex: 1 1 8rem;
  min-width: 0;
}

.sizes {
  margin: 1rem 0 0;
  padding: 0;
  border: 0;
}

.sizes legend {
  padding: 0;
  font-weight: 600;
}

.size {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 0.5rem;
  min-height: 44px;
  margin: 0 !important;
  padding: 0.25rem 0;
  font-weight: 400 !important;
}

.size input {
  width: 1.5rem;
  height: 1.5rem;
  margin: 0;
}

.size-name {
  font-weight: 600;
}

.size-detail {
  color: var(--muted);
}

.drop {
  margin: 0.25rem 0;
  padding: 0.75rem;
  border: 2px dashed var(--line);
  border-radius: 0.5rem;
  background: var(--surface);
}

.drop.dragging {
  border-style: solid;
  border-color: var(--accent);
}

.drop p {
  margin: 0.5rem 0 0;
  color: var(--muted);
}

.tool input[type="file"] {
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 0;
}

.crop-area {
  margin: 1rem 0 0;
  touch-action: none;
  border: 1px solid var(--line);
  border-radius: 0.25rem;
  background: #202124;
  line-height: 0;
}

.crop-area canvas {
  display: block;
  width: 100%;
  height: auto;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0 1rem;
}

.controls .field {
  flex: 1 1 12rem;
}

.controls input[type="range"] {
  width: 100%;
  min-height: 44px;
}

.buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.buttons button {
  min-width: 44px;
  min-height: 44px;
  padding: 0.5rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 0.25rem;
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-weight: 600;
}

.buttons button:disabled {
  border-color: var(--line);
  background: transparent;
  color: var(--muted);
}

.export {
  margin-top: 1rem;
}

#quality-row input {
  width: 100%;
  min-height: 44px;
}

#format-notice {
  margin: 0.5rem 0 0;
  color: var(--muted);
}

.result {
  margin-top: 0.75rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--line);
  border-radius: 0.25rem;
  background: var(--surface);
}

.result a {
  display: inline-block;
  min-height: 44px;
  line-height: 44px;
  font-weight: 600;
}

.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
}

.check input {
  width: 1.5rem;
  height: 1.5rem;
  margin: 0;
}

.check label {
  display: flex;
  align-items: center;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
}

#readout,
#enlargement {
  margin: 0.5rem 0 0;
}

#enlargement {
  color: var(--error);
}

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

.readout,
#resolved {
  margin: 0.75rem 0 0;
}

#resolved {
  font-weight: 600;
}

#source-line,
#authority,
#generic-note,
#notes {
  margin: 0.5rem 0 0;
  color: var(--muted);
}

#notes {
  padding-left: 1.25rem;
}

#status {
  min-height: 1.6em;
  margin: 0.75rem 0 0;
  font-weight: 600;
}

.privacy {
  color: var(--muted);
}

footer {
  border-top: 1px solid var(--line);
  color: var(--muted);
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
