:root {
  --bg: #f4f4f2;
  --surface: #ffffff;
  --ink: #16161a;
  --muted: #6b6b76;
  --line: #e4e4df;
  --accent: #1a1a1a;
  --accent-ink: #ffffff;
  --danger: #b4341f;
  --tile-bg: #ffffff;
  --checker: rgba(0, 0, 0, 0.06);
  --shadow: 0 1px 2px rgba(20, 20, 25, 0.04), 0 10px 28px rgba(20, 20, 25, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #0f1012;
  --surface: #17181b;
  --ink: #ededf0;
  --muted: #9a9aa3;
  --line: #2a2b30;
  --accent: #ededf0;
  --accent-ink: #16161a;
  --danger: #ff7a66;
  --tile-bg: #1c1d21;
  --checker: rgba(255, 255, 255, 0.05);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 28px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  overflow: hidden; /* single viewport — no page scroll */
}

.app {
  height: 100vh;
  height: 100dvh;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px clamp(16px, 4vw, 40px);
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.brand {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.brand span { color: var(--muted); font-weight: 400; }

.settings { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.select,
.key-input {
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  outline: none;
}
.select { cursor: pointer; }
.key-input { width: min(40vw, 260px); }
.key-input::placeholder { color: #a6a6ad; }
.select:focus,
.key-input:focus { border-color: var(--muted); }

.icon-btn {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  cursor: pointer;
  color: var(--ink);
}
.icon-btn:hover { border-color: var(--muted); }
.theme-icon { width: 18px; height: 18px; display: block; }
/* sun (light theme) / moon (dark theme) drawn with CSS */
.theme-icon::before {
  content: "";
  display: block;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, var(--ink) 0 32%, transparent 33%);
  box-shadow:
    0 -11px 0 -7px var(--ink), 0 11px 0 -7px var(--ink),
    -11px 0 0 -7px var(--ink), 11px 0 0 -7px var(--ink),
    -8px -8px 0 -7px var(--ink), 8px 8px 0 -7px var(--ink),
    -8px 8px 0 -7px var(--ink), 8px -8px 0 -7px var(--ink);
}
[data-theme="dark"] .theme-icon::before {
  background: var(--ink);
  box-shadow: inset -6px -3px 0 0 var(--surface);
  width: 16px; height: 16px;
}

/* Composer */
.composer {
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.prompt {
  flex: 1;
  font-family: inherit;
  font-size: 16px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  outline: none;
}
.prompt::placeholder { color: #a6a6ad; }
.prompt:focus { border-color: var(--muted); }

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 0 24px;
  border-radius: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.55; cursor: default; }

.spinner {
  width: 15px; height: 15px;
  border: 2px solid color-mix(in srgb, var(--accent-ink) 35%, transparent);
  border-top-color: var(--accent-ink);
  border-radius: 50%;
  display: none;
  animation: spin 0.7s linear infinite;
}
.btn-primary.loading .spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Stage */
.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.placeholder {
  text-align: center;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 420px;
}
.placeholder p { margin: 0; font-size: 14px; }
.placeholder-mark {
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 2px dashed var(--line);
}

.variants {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.variant {
  position: relative;
  min-height: 0;
  background: var(--tile-bg);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.08s ease;
}
.variant:hover { border-color: var(--muted); }
.variant:active { transform: scale(0.99); }
.variant.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent), var(--shadow); }
.variant.failed { cursor: default; border-style: dashed; }

.variant-art { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
/* Checkerboard behind transparent logos so the transparency is visible. */
.variant-art.has-image {
  background-color: var(--tile-bg);
  background-image:
    linear-gradient(45deg, var(--checker) 25%, transparent 25%, transparent 75%, var(--checker) 75%),
    linear-gradient(45deg, var(--checker) 25%, transparent 25%, transparent 75%, var(--checker) 75%);
  background-size: 18px 18px;
  background-position: 0 0, 9px 9px;
  border-radius: 8px;
}
.variant-art img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  display: block;
  animation: fade-in 0.35s ease;
}
.variant-art .msg { color: var(--muted); font-size: 13px; text-align: center; }
@keyframes fade-in { from { opacity: 0; transform: scale(0.98); } to { opacity: 1; } }

/* Pulsing dashed ring in any tile still waiting for its image. */
.variants.loading .variant-art:empty::after {
  content: "";
  width: 64px; aspect-ratio: 1;
  border-radius: 50%;
  border: 2px dashed var(--line);
  animation: spin 2.4s linear infinite;
}

.error {
  margin: 0;
  padding: 20px;
  text-align: center;
  color: var(--danger);
  font-size: 14px;
  max-width: 520px;
}

/* Bottom bar */
.bottom {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  min-height: 40px;
}
.pick-hint { color: var(--muted); font-size: 13px; }
.actions { display: flex; gap: 10px; }

.btn-ghost {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 9px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.btn-ghost:hover { border-color: var(--muted); }
.btn-ghost:active { transform: scale(0.98); }

.foot { color: var(--muted); font-size: 12.5px; }
.foot a { color: var(--muted); text-decoration: none; border-bottom: 1px solid var(--line); }
.foot a:hover { color: var(--ink); }

@media (max-width: 680px) {
  .topbar { gap: 10px; }
  .settings { width: 100%; }
  .key-input { flex: 1; width: auto; }
  .variants { grid-template-columns: 1fr; grid-auto-rows: 1fr; overflow: auto; }
  body { overflow: auto; }
  .app { height: auto; min-height: 100dvh; }
}
