:root {
  color-scheme: light;
  --bg: #f3f4f6;
  --card: #ffffff;
  --ink: #20242b;
  --muted: #707781;
  --line: #dfe2e7;
  --blue: #0879f9;
  --yellow: #ffeaa8;
  font-family: system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
}

button, input { font: inherit; }

main {
  width: min(680px, calc(100% - 32px));
  margin: 0 auto;
  padding: 9vh 0 32px;
}

h1 {
  margin: 0 0 24px;
  text-align: center;
  font-size: clamp(1.8rem, 6vw, 2.6rem);
  letter-spacing: -0.04em;
}

.tool {
  display: grid;
  grid-template-columns: 42% 58%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(24, 39, 60, 0.08);
}

.preview-panel, .controls-panel { padding: 28px; }
.preview-panel { border-radius: 12px 0 0 12px; }
.controls-panel { border-radius: 0 12px 12px 0; }
.preview-panel { border-right: 1px solid var(--line); }

h2, label {
  display: block;
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: lowercase;
}

.stage {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  overflow: hidden;
  background-color: #eef1f5;
  background-image:
    linear-gradient(45deg, #e2e6eb 25%, transparent 25%),
    linear-gradient(-45deg, #e2e6eb 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e2e6eb 75%),
    linear-gradient(-45deg, transparent 75%, #e2e6eb 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
  border-radius: 8px;
}

#preview, #result {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

#preview[hidden], #result[hidden], #empty-state[hidden], #download[hidden] { display: none; }

#empty-state {
  position: absolute;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  color: #98a0aa;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
  border-radius: 50%;
  font-size: 1.3rem;
  font-weight: 700;
}

form { display: grid; gap: 10px; }
label { margin-bottom: 2px; }

input, button, #download {
  width: 100%;
  min-height: 48px;
  border-radius: 7px;
}

input {
  padding: 0 13px;
  color: var(--ink);
  background: #fafafa;
  border: 1px solid var(--line);
  outline: none;
  font-size: 1rem;
}

input:focus {
  background: #fff;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(8, 121, 249, 0.12);
}

button, #download {
  display: grid;
  place-items: center;
  padding: 0 16px;
  color: #fff;
  background: var(--blue);
  border: 0;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 700;
  text-decoration: none;
}

button:hover, #download:hover { filter: brightness(0.92); }
button:disabled { cursor: wait; opacity: 0.55; }

#status {
  min-height: 21px;
  margin: 16px 0 6px;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.45;
}

#status.error { color: #b42318; }

#progress {
  display: block;
  overflow: hidden;
  width: 100%;
  height: 3px;
  margin-bottom: 16px;
  background: #edf0f3;
  border-radius: 99px;
}

#progress::after {
  display: block;
  width: var(--progress, 0%);
  height: 100%;
  content: "";
  background: var(--blue);
  transition: width 120ms linear;
}

#download { color: var(--ink); background: var(--yellow); }

/* handle typeahead */
.combo { position: relative; }

#suggestions {
  position: absolute;
  z-index: 5;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 9px;
  box-shadow: 0 14px 36px rgba(24, 39, 60, 0.16);
  max-height: 312px;
  overflow-y: auto;
}

#suggestions[hidden] { display: none; }

#suggestions li {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 10px;
  align-items: center;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
}

#suggestions li[aria-selected="true"] { background: #eef4fe; }

#suggestions img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #e2e6eb;
  object-fit: cover;
}

#suggestions img.blank { background: var(--blue); }

#suggestions .who { display: grid; min-width: 0; line-height: 1.25; }

#suggestions .name {
  overflow: hidden;
  font-size: 0.92rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#suggestions .handle {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.8rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

footer { padding-top: 16px; text-align: center; }

footer a {
  color: var(--muted);
  font-size: 0.78rem;
  text-decoration: none;
}

footer a:hover { color: var(--blue); text-decoration: underline; }

@media (max-width: 560px) {
  main { padding-top: 40px; }
  .tool { grid-template-columns: 1fr; }
  .preview-panel { border-right: 0; border-bottom: 1px solid var(--line); border-radius: 12px 12px 0 0; }
  .controls-panel { border-radius: 0 0 12px 12px; }
  .stage { max-width: 240px; margin: 0 auto; }
}

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