/* ===== FABICONS — Bauhaus brutalist, mobile-first ===== */
:root {
  --ink: #0a0a0a;
  --paper: #f4f1ea;
  --paper-2: #e9e5d8;
  --red: #d62828;
  --bright-red: #ff1a1a;
  --blue: #1d3557;
  --yellow: #ffc857;
  --bw: 4px;
}

*, *::before, *::after { box-sizing: border-box; }
html { background: var(--paper); color-scheme: light; overflow-x: clip; }
html, body { margin: 0; padding: 0; color: var(--ink); }
body {
  font-family: "Space Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-weight: 500;
  -webkit-font-smoothing: antialiased;
  background: var(--paper);
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: none;
  overflow-x: clip;
  /* leave room for the sticky preview bar at the bottom */
  padding-bottom: var(--previewbar-h, 240px);
}

/* ===== topbar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--paper);
  border-bottom: var(--bw) solid var(--ink);
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.brand h1 {
  font-family: "Archivo Black", "Inter", system-ui, sans-serif;
  font-size: clamp(28px, 8vw, 42px);
  line-height: 0.9;
  letter-spacing: -0.025em;
  margin: 0;
}
.brand .tag {
  margin: 4px 0 0;
  font-size: clamp(10px, 2.6vw, 12px);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.7;
}
.brand .tag .by { opacity: 0.55; margin-left: 4px; }
.brand .tag .by a {
  color: var(--bright-red);
  text-decoration: none;
  letter-spacing: 0.14em;
  font-weight: 800;
  opacity: 1;
}
.brand .tag .by a:hover { text-decoration: underline; text-underline-offset: 3px; }

/* mode tabs */
.modes {
  display: flex;
  gap: 8px;
}
.mode-btn {
  flex: 1;
  font: 800 13px/1 "Space Grotesk", sans-serif;
  letter-spacing: 0.14em;
  padding: 14px 12px;
  background: #fff;
  color: var(--ink);
  border: var(--bw) solid var(--ink);
  border-radius: 0;
  cursor: pointer;
  transition: transform 80ms ease, background 80ms ease, color 80ms ease, box-shadow 80ms ease;
  min-height: 48px;
}
.mode-btn:hover, .mode-btn:focus-visible {
  transform: translate(-2px, -2px);
  box-shadow: 4px 4px 0 0 var(--ink);
  outline: none;
}
.mode-btn[aria-selected="true"] {
  background: var(--ink);
  color: var(--paper);
  transform: none;
  box-shadow: none;
}

@media (min-width: 720px) {
  .topbar {
    padding: 16px 22px;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 22px;
  }
  .modes { max-width: 320px; margin-left: auto; }
}

/* ===== workspace ===== */
.workspace {
  padding: 18px 14px;
}
@media (min-width: 720px) {
  .workspace { padding: 22px; }
}

.mode-panel { display: block; }
.mode-panel[hidden] { display: none; }

/* ===== PAINT mode ===== */
.paint-stage {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  align-items: start;
}
@media (min-width: 880px) {
  .paint-stage {
    grid-template-columns: minmax(0, 1fr) 260px;
    gap: 28px;
  }
}

.paint-grid-wrap {
  position: relative;
  width: 100%;
  max-width: 560px;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  background:
    /* checkerboard transparency indicator */
    repeating-conic-gradient(#ddd 0% 25%, #fff 0% 50%) 0 0 / 32px 32px;
  border: var(--bw) solid var(--ink);
  box-shadow: 8px 8px 0 0 var(--ink);
}
.paint-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: crosshair;
  position: relative;
  z-index: 1;
}
.paint-grid-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background-image:
    linear-gradient(to right, rgba(10,10,10,0.12) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(10,10,10,0.12) 1px, transparent 1px);
  background-size: calc(100% / 32) calc(100% / 32);
}

.paint-tools {
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 14px;
}

.palette {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  padding: 8px;
  background: #fff;
  border: var(--bw) solid var(--ink);
}
.palette button {
  position: relative;
  aspect-ratio: 1 / 1;
  background: var(--c, transparent);
  border: 2px solid var(--ink);
  border-radius: 0;
  cursor: pointer;
  padding: 0;
  transition: transform 60ms ease;
}
.palette button:hover { transform: scale(1.05); }
.palette button[aria-checked="true"] {
  outline: 3px solid var(--bright-red);
  outline-offset: 2px;
  z-index: 1;
}
.palette button.transparent {
  background:
    repeating-conic-gradient(#bbb 0% 25%, #fff 0% 50%) 0 0 / 8px 8px;
}
.palette button.transparent::after {
  content: "";
  position: absolute;
  left: 10%; right: 10%;
  top: 50%;
  height: 3px;
  background: var(--bright-red);
  transform: rotate(-45deg) translateY(-1.5px);
}

.tools, .actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.actions { grid-template-columns: 1fr 1fr; }
.tool-btn, .act-btn {
  font: 800 11px/1 "Space Grotesk", sans-serif;
  letter-spacing: 0.12em;
  padding: 12px 6px;
  background: #fff;
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 0;
  cursor: pointer;
  min-height: 42px;
  transition: transform 60ms ease, background 60ms ease, color 60ms ease;
}
.tool-btn[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.tool-btn:hover, .act-btn:hover { background: var(--yellow); }

/* ===== EMOJI mode ===== */
.emoji-search-wrap { width: 100%; max-width: 720px; margin: 0 auto 14px; }
.emoji-search {
  width: 100%;
  font: 700 clamp(16px, 4vw, 18px)/1 "Space Grotesk", sans-serif;
  background: #fff;
  color: var(--ink);
  border: var(--bw) solid var(--ink);
  border-radius: 0;
  padding: 14px 16px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: background 80ms ease, box-shadow 80ms ease, transform 80ms ease;
}
.emoji-search::placeholder { color: #8a857a; font-weight: 500; }
.emoji-search:focus { background: var(--yellow); box-shadow: 6px 6px 0 0 var(--ink); transform: translate(-2px, -2px); }

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 6px;
  max-width: 960px;
  margin: 0 auto;
}
.emoji-tile {
  aspect-ratio: 1 / 1;
  background: #fff;
  border: 0;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0;
  transition: transform 80ms ease;
}
.emoji-tile:hover { transform: translateY(-2px); }
.emoji-tile:focus-visible { outline: 3px solid var(--bright-red); outline-offset: 2px; }
.emoji-tile span {
  font-size: 36px;
  line-height: 1;
  font-family: "Apple Color Emoji","Segoe UI Emoji","Noto Color Emoji","Twemoji Mozilla",system-ui,sans-serif;
  pointer-events: none;
}
.emoji-tile.selected { background: var(--yellow); outline: 3px solid var(--ink); outline-offset: -3px; }

/* ===== preview + export ===== */
.preview-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  background: var(--paper);
  border-top: var(--bw) solid var(--ink);
  padding: 12px 14px max(12px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
@media (min-width: 720px) {
  .preview-bar {
    padding: 14px 22px max(14px, env(safe-area-inset-bottom));
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 22px;
  }
}

.previews { display: flex; gap: 16px; align-items: center; justify-content: flex-start; }
.preview-cell { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.preview-label {
  font: 800 9px/1 "Space Grotesk", sans-serif;
  letter-spacing: 0.18em;
  opacity: 0.55;
}

/* 16px favicon shown in a "tab" mock */
.preview-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 2px solid var(--ink);
  padding: 4px 8px 4px 6px;
  min-width: 120px;
}
.preview-tab canvas {
  width: 16px;
  height: 16px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.preview-tab .tab-text {
  font: 700 11px/1 "Space Grotesk", sans-serif;
  letter-spacing: 0.04em;
  color: var(--ink);
  opacity: 0.7;
}

.preview-box-32 {
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: repeating-conic-gradient(#ddd 0% 25%, #fff 0% 50%) 0 0 / 8px 8px;
  border: 2px solid var(--ink);
}
.preview-box-180 {
  width: 64px;
  height: 64px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: repeating-conic-gradient(#ddd 0% 25%, #fff 0% 50%) 0 0 / 12px 12px;
  border: 2px solid var(--ink);
}
@media (min-width: 720px) {
  .preview-box-180 { width: 72px; height: 72px; }
}

.export {
  display: flex;
  gap: 8px;
  align-items: stretch;
  flex-wrap: wrap;
}
.export-btn {
  font: 800 12px/1 "Space Grotesk", sans-serif;
  letter-spacing: 0.14em;
  padding: 14px 18px;
  background: #fff;
  color: var(--ink);
  border: var(--bw) solid var(--ink);
  border-radius: 0;
  cursor: pointer;
  min-height: 48px;
  transition: transform 80ms ease, background 80ms ease, color 80ms ease, box-shadow 80ms ease;
}
.export-btn:hover, .export-btn:focus-visible {
  transform: translate(-2px, -2px);
  box-shadow: 4px 4px 0 0 var(--ink);
  outline: none;
}
.export-btn.primary {
  background: var(--ink);
  color: var(--paper);
}
.export-btn.primary:hover {
  background: var(--bright-red);
  color: #fff;
}

/* ===== toast ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--previewbar-h, 240px) + 16px);
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  font: 800 13px/1 "Space Grotesk", sans-serif;
  letter-spacing: 0.12em;
  padding: 14px 20px;
  border: var(--bw) solid var(--ink);
  box-shadow: 6px 6px 0 0 var(--yellow);
  z-index: 30;
  animation: pop 1.8s ease forwards;
}
@keyframes pop {
  0%   { opacity: 0; transform: translate(-50%, 10px); }
  10%  { opacity: 1; transform: translate(-50%, 0); }
  85%  { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, 6px); }
}

/* ===== footer ===== */
.foot {
  padding: 28px 22px 44px;
  font-size: 12px;
  line-height: 1.5;
  opacity: 0.75;
  max-width: 900px;
  margin: 32px auto 0;
}
.foot code {
  background: #fff;
  border: 1px solid var(--ink);
  padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}
.foot p { margin: 0 0 8px; }
.foot a { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.foot a:hover { background: var(--yellow); }
.foot .src { font-weight: 700; font-size: 11px; letter-spacing: 0.04em; opacity: 0.8; }

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