:root {
  --bg: #f6f8f7;
  --ink: #183330;
  --accent: #176a53;
  --muted: #475f5b;
  --line: #cfdad6;
  --field: #8fa5a0;
  --surface: #ffffff;
  --error: #a3261b;
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

:focus-visible,
.droparea:focus-within {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar-inner,
main,
.footer {
  max-width: 1120px;
  margin: 0 auto;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s2) var(--s4);
}

.brand { font-size: 18px; font-weight: 700; }

.modes,
.choices,
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
}

main { padding: var(--s4); }

.page-title {
  margin: 0 0 var(--s4);
  font-size: 20px;
  line-height: 1.3;
}

.tool {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--s4);
  align-items: start;
}

@media (min-width: 768px) {
  .tool { grid-template-columns: minmax(0, 1fr) minmax(280px, 360px); }
}

.panel {
  min-width: 0;
  padding: var(--s4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.group {
  min-width: 0;
  margin: 0 0 var(--s4);
  padding: 0;
  border: 0;
}

legend,
label {
  font-size: 14px;
  font-weight: 600;
}

legend { margin-bottom: var(--s2); padding: 0; }

.type-fields > label:not(.check) {
  display: block;
  margin-bottom: var(--s1);
}

input[type="text"],
input[type="password"],
textarea {
  width: 100%;
  padding: var(--s2) var(--s3);
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--field);
  border-radius: 6px;
}

input:disabled { background: var(--bg); color: var(--muted); }

textarea { min-height: 120px; resize: vertical; }

[aria-invalid="true"] { border-color: var(--error); }

.hint,
.error,
.status {
  margin: var(--s1) 0 var(--s3);
  font-size: 14px;
}

.hint { color: var(--muted); font-weight: 400; }

.error { color: var(--error); font-weight: 600; }

.status { min-height: 21px; }

.check {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin: var(--s2) 0;
  font-weight: 400;
}

.check input { width: 18px; height: 18px; margin: 0; }

button {
  min-height: 40px;
  padding: var(--s2) var(--s4);
  font: inherit;
  color: var(--accent);
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 6px;
  cursor: pointer;
}

button[aria-pressed="true"],
button.primary {
  color: #ffffff;
  background: var(--accent);
}

button:disabled {
  color: var(--muted);
  background: #e3eae7;
  border-color: var(--line);
  cursor: not-allowed;
}

.actions { margin-top: var(--s3); }

.square {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  padding: var(--s2);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.square canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.square img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.square-message {
  margin: 0;
  padding: var(--s4);
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}

.square-message.is-error { color: var(--error); font-weight: 600; }

.droparea {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s1);
  min-height: 160px;
  padding: var(--s5) var(--s4);
  text-align: center;
  background: var(--bg);
  border: 2px dashed var(--field);
  border-radius: 8px;
}

.droparea.is-dragging { background: #e4f0eb; border-color: var(--accent); }

.droparea-title { font-size: 16px; }

.droparea .hint { margin: 0; }

.droparea input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.result { margin-top: var(--s4); }

.result-label {
  margin: 0 0 var(--s1);
  font-size: 14px;
  font-weight: 600;
}

.result-text {
  max-height: 240px;
  margin: 0 0 var(--s2);
  padding: var(--s3);
  overflow: auto;
  font: 16px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.cards {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--s4);
  margin-top: var(--s6);
}

@media (min-width: 768px) {
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.card {
  padding: var(--s4);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.card h2 { margin: 0 0 var(--s2); font-size: 16px; }

.card p,
.footer p {
  max-width: 68ch;
  margin: 0;
}

.footer {
  padding: var(--s5) var(--s4) var(--s6);
  font-size: 14px;
  color: var(--muted);
}
