@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&display=swap');

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #f0f0f3;
  --fg: #111;
  --fg-dim: #999;
  --green: #0a0;
  --border: #ddd;
  --surface: #f5f5f5;
  --bar-height: 36px;
  --bottom-height: 22px;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: 'JetBrains Mono', monospace;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Top bar */
.navbar {
  height: var(--bar-height);
  min-height: var(--bar-height);
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  z-index: 10;
  background: var(--bg);
}

.navbar-logo {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
  image-rendering: pixelated;
}

.navbar-title {
  font-size: 0.65rem;
  font-weight: 700;
  white-space: nowrap;
  color: var(--fg);
}

.navbar-title .strikethrough {
  text-decoration: line-through;
}

.navbar-meta {
  font-size: 0.55rem;
  color: var(--fg-dim);
  white-space: nowrap;
  margin-left: 2px;
}

.navbar-meta a {
  color: var(--fg-dim);
  text-decoration: underline;
  text-decoration-color: var(--border);
}

.navbar-meta a:hover { color: var(--fg); }

.navbar-spacer { flex: 1; }

.navbar-selectors {
  display: flex;
  align-items: center;
  gap: 3px;
  min-width: 0;
  flex-shrink: 1;
  overflow: hidden;
}

.navbar-selectors select {
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 2px 14px 2px 4px;
  font-family: inherit;
  font-size: 0.5rem;
  cursor: pointer;
  width: 90px;
  height: 22px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5'%3E%3Cpath d='M0 0l4 5 4-5z' fill='%23999'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 4px center;
  text-overflow: ellipsis;
}

.navbar-selectors select:hover { border-color: #aaa; }

.navbar-btn {
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  font-family: inherit;
  font-size: 0.55rem;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.navbar-btn:hover { border-color: #aaa; }

#randomize-btn {
  background: var(--fg);
  color: var(--bg);
  border: none;
  padding: 4px 10px;
  height: 22px;
  font-family: inherit;
  font-size: 0.55rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

#randomize-btn:hover { background: #333; }

/* Punk display — fills remaining space, snapped to bottom */
.punk-area {
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
  position: relative;
  min-height: 0;
}

#punk-display {
  height: 100%;
  aspect-ratio: 1;
  max-width: 100%;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  display: flex;
  align-items: flex-end;
  position: relative;
}

#punk-display svg {
  width: 100%;
  height: auto;
  max-height: 100%;
  display: block;
}

#download-btn {
  position: absolute;
  bottom: 0;
  right: 0;
  /* 1/24th of the punk image — always a perfect square */
  width: calc(100% / 24);
  height: 0;
  padding-bottom: calc(100% / 24);
  background: rgb(160,80,80);
  color: rgba(255,255,255,0.9);
  border: none;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.15s;
  z-index: 5;
  overflow: hidden;
  font-size: 0;
}

#download-btn::after {
  content: '\2193';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: min(2.5vw, 2.5vh);
}

#download-btn:hover { opacity: 1; }

/* Bottom bar */
.bottombar {
  height: var(--bottom-height);
  min-height: var(--bottom-height);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding: 0 10px;
  background: var(--bg);
}

#api-url {
  font-size: 0.5rem;
  color: var(--fg-dim);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: calc(100% - 50px);
}

#api-url:hover { color: var(--fg); }

#copy-toast {
  font-size: 0.45rem;
  color: var(--green);
  opacity: 0;
  transition: opacity 0.2s;
}

#copy-toast.show { opacity: 1; }

/* About modal */
#about-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(240,240,243,0.92);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

#about-overlay.show { display: flex; }

#about-box {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 32px;
  max-width: 420px;
  width: 100%;
  font-size: 0.75rem;
  line-height: 1.6;
  color: var(--fg-dim);
  position: relative;
}

#about-box h2 {
  color: var(--fg);
  margin-bottom: 16px;
  font-size: 0.85rem;
}

#about-box p { margin-bottom: 12px; }
#about-box a { color: var(--fg); }

#about-close {
  position: absolute;
  top: 8px;
  right: 12px;
  color: var(--fg-dim);
  cursor: pointer;
  font-size: 1rem;
  background: none;
  border: none;
  font-family: inherit;
}

#about-close:hover { color: var(--fg); }

/* Hidden canvas for PNG export */
#export-canvas { display: none; }

/* Responsive — mobile */
@media (max-width: 640px) {
  :root {
    --bar-height: auto;
  }

  .navbar {
    flex-wrap: wrap;
    padding: 8px;
    gap: 6px;
  }

  .navbar-spacer { flex: 1; min-width: 0; }
  .navbar-meta { margin-left: 0; }

  .navbar-selectors {
    order: 10;
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    overflow: visible;
  }

  .navbar-selectors select {
    width: 100%;
    height: 32px;
    font-size: 0.55rem;
    padding: 4px 16px 4px 6px;
  }

  #randomize-btn {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 44px;
    font-size: 0.65rem;
    padding: 0;
    z-index: 10;
  }

  .bottombar {
    margin-bottom: 44px;
  }

  .navbar-btn {
    width: 28px;
    height: 28px;
    font-size: 0.6rem;
  }

  #punk-display {
    height: auto;
    width: 100%;
  }

  #punk-display svg {
    width: 100%;
    height: auto;
  }
}

@media (max-width: 380px) {
  .navbar-title { font-size: 0.55rem; }

  .navbar-selectors {
    grid-template-columns: repeat(3, 1fr);
  }

  .navbar-selectors select {
    height: 28px;
    font-size: 0.5rem;
  }
}
