:root {
  --paper: #efe9dc;        /* warm page / canvas surround */
  --card: #fbf8f1;         /* slightly lighter paper for panels */
  --white: #ffffff;
  --ink: #221d17;          /* warm near-black */
  --ink-soft: #5d564b;
  --faint: #928a7c;
  --rule: rgba(34,29,23,0.14);
  --tomato: #df4726;
  --blue: #2f5fe0;
  --discord: #5865f2;
  --discord-hi: #4954d8;
  --yellow: #ffd23f;

  --font-pixel: 'Silkscreen', ui-monospace, monospace;
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-mono: 'Space Mono', ui-monospace, 'Courier New', monospace;

  --border: 2px solid var(--ink);
  --lift: 0 2px 0 rgba(34,29,23,0.05), 0 12px 26px -14px rgba(34,29,23,0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-mono);
  -webkit-user-select: none;
  user-select: none;
}

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

#canvas {
  position: fixed;
  inset: 0;
  display: block;
  cursor: crosshair;
  touch-action: none;
  image-rendering: pixelated;
}

/* faint paper grain over everything (handmade texture) */
.paper {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.08;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.35'/%3E%3C/svg%3E");
}

/* ---------- top bar ---------- */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 66px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  z-index: 10;
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
.grow { flex: 1; }

.brand {
  display: flex; align-items: center; gap: 11px;
}
.brand-mark {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 2px;
  width: 28px; height: 28px;
}
.brand-mark .cell { background: transparent; }
.brand-mark .cell.on {
  background: var(--c, var(--ink));
  box-shadow: 0 0 0 1px rgba(34,29,23,0.25);
  animation: pop 0.45s cubic-bezier(0.34,1.56,0.64,1) forwards;
  animation-delay: calc(var(--i) * 45ms + 0.1s);
}
.brand-text { display: flex; flex-direction: column; line-height: 1; }
.brand-name {
  font-family: var(--font-pixel);
  font-size: 19px;
  color: var(--ink);
}
.brand-sub {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-soft);
  margin-top: 5px;
}

/* buttons */
.btn {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  color: var(--ink);
  border: var(--border);
  background: var(--card);
  padding: 9px 15px;
  border-radius: 11px 9px 12px 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--lift);
  transition: transform 0.12s, background 0.15s;
}
.btn:hover { transform: translateY(-2px) rotate(-0.5deg); }
.btn:active { transform: translateY(0); }
.btn-ghost { box-shadow: none; background: transparent; border-color: var(--rule); color: var(--ink-soft); }
.btn-ghost:hover { border-color: var(--ink); color: var(--ink); }
.btn-discord { background: var(--discord); border-color: var(--ink); color: #fff; }
.btn-discord:hover { background: var(--discord-hi); }

.cooldown {
  font-family: var(--font-pixel);
  font-size: 11px;
  color: var(--ink);
  background: var(--yellow);
  border: var(--border);
  border-radius: 10px 8px 11px 9px;
  padding: 8px 11px 6px;
  box-shadow: var(--lift);
}

.account { display: flex; align-items: center; gap: 9px; }
.account .chip {
  display: flex; align-items: center; gap: 9px;
  padding: 5px 12px 5px 5px;
  background: var(--card);
  border: var(--border);
  border-radius: 22px 20px 22px 18px;
  box-shadow: var(--lift);
}
.account .chip img {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--paper);
  border: 2px solid var(--ink);
}
.account .chip .name { font-size: 13px; font-weight: 700; }

/* ---------- color dock ---------- */
.dock {
  position: fixed;
  bottom: 22px; left: 0; right: 0;
  margin-inline: auto;
  width: max-content;
  max-width: calc(100vw - 24px);
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 14px;
  background: var(--card);
  border: var(--border);
  border-radius: 16px 13px 17px 12px;
  box-shadow: var(--lift);
  z-index: 10;
}
.dock-label {
  font-family: var(--font-pixel);
  font-size: 7.5px;
  line-height: 1.5;
  color: var(--faint);
  text-transform: lowercase;
  width: 30px;
  text-align: right;
}
.dock-current { display: flex; align-items: center; gap: 8px; }
.dock-swatch {
  width: 26px; height: 26px;
  border: 2px solid var(--ink);
  border-radius: 7px 5px 7px 6px;
}
.dock-hex {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
  width: 64px;
  text-transform: uppercase;
}
.dock-divider { width: 2px; height: 30px; background: var(--rule); }
.palette {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  max-width: 620px;
}
.swatch {
  width: 24px; height: 24px;
  border-radius: 6px 5px 7px 5px;
  cursor: pointer;
  border: 2px solid var(--ink);
  transition: transform 0.12s ease;
}
.swatch:hover { transform: translateY(-4px) rotate(3deg); }
.swatch.selected {
  transform: translateY(-4px) scale(1.12);
  box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--ink);
}

/* ---------- HUD ---------- */
.hud {
  position: fixed;
  left: 16px; bottom: 18px;
  z-index: 9;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
  background: var(--card);
  border: var(--border);
  border-radius: 9px 11px 8px 10px;
  padding: 6px 11px;
  letter-spacing: 0.01em;
  pointer-events: none;
  display: flex; gap: 7px;
  box-shadow: var(--lift);
  animation: fade 0.7s ease both;
}
.hud-sep { color: var(--faint); }
#hudCoords { color: var(--ink); font-weight: 700; }

/* ---------- hint ---------- */
.hint {
  position: fixed;
  top: 78px; left: 0; right: 0;
  margin-inline: auto;
  width: max-content;
  z-index: 9;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
  max-width: 90vw;
  text-align: center;
  pointer-events: none;
  transition: opacity 0.5s;
  animation: fade 0.7s ease both;
}
.hint.fade { opacity: 0; }

/* ---------- pixel info popover ---------- */
.pixel-info {
  position: fixed;
  width: 250px;
  background: var(--card);
  border: var(--border);
  border-radius: 16px 12px 17px 13px;
  padding: 15px;
  z-index: 20;
  box-shadow: var(--lift);
  animation: pop-in 0.2s cubic-bezier(0.34,1.56,0.64,1) both;
}
.pixel-info .close {
  position: absolute; top: 8px; right: 11px;
  background: none; border: none;
  color: var(--faint); font-size: 20px; line-height: 1;
  cursor: pointer; transition: color 0.15s;
}
.pixel-info .close:hover { color: var(--ink); }
.pi-head { display: flex; align-items: center; gap: 11px; }
.pi-avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--paper);
  border: 2px solid var(--ink);
}
.pi-user { font-family: var(--font-display); font-weight: 600; font-size: 17px; }
.pi-coords { font-family: var(--font-mono); font-size: 11px; color: var(--faint); margin-top: 1px; }
.pi-meta {
  display: flex; align-items: center; gap: 8px;
  margin-top: 13px; padding-top: 12px;
  border-top: 2px dashed var(--rule);
  font-family: var(--font-mono);
  font-size: 12px; color: var(--ink-soft);
}
.pi-swatch {
  width: 17px; height: 17px; border-radius: 5px;
  border: 2px solid var(--ink);
}
.pi-hex { text-transform: uppercase; }
.pi-time { margin-left: auto; color: var(--faint); }
.pi-discord {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-top: 14px;
  background: var(--discord);
  color: #fff;
  text-decoration: none;
  font-family: var(--font-mono);
  font-weight: 700; font-size: 13px;
  padding: 10px;
  border: 2px solid var(--ink);
  border-radius: 11px 9px 12px 8px;
  transition: background 0.15s, transform 0.15s;
}
.pi-discord:hover { background: var(--discord-hi); transform: translateY(-2px); }

/* ---------- login modal ---------- */
.modal-scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(60,52,40,0.34);
  backdrop-filter: blur(2px);
  animation: fade 0.3s ease both;
}
.modal-scrim.closing { animation: fade 0.25s ease reverse forwards; }
.modal-wrap {
  position: relative;
  max-width: 100%;
}
.modal-card {
  position: relative;
  width: 452px;
  max-width: 100%;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: var(--card);
  border: 2.5px solid var(--ink);
  border-radius: 26px 20px 24px 22px;
  padding: 26px 30px 24px;
  box-shadow: 0 3px 0 rgba(34,29,23,0.12), 0 30px 60px -22px rgba(34,29,23,0.7);
  animation: modal-in 0.4s cubic-bezier(0.16,1,0.3,1) both;
}
.modal-dismiss {
  position: absolute; top: 12px; right: 14px; z-index: 3;
  background: var(--paper);
  border: 2px solid var(--ink);
  color: var(--ink);
  width: 28px; height: 28px; border-radius: 50%;
  font-size: 17px; line-height: 1;
  cursor: pointer; transition: transform 0.15s, background 0.15s;
}
.modal-dismiss:hover { transform: rotate(90deg); background: var(--yellow); }

.sticker {
  position: absolute;
  top: -30px; left: -14px;
  z-index: 2;
  background: var(--yellow);
  border: 2px solid var(--ink);
  font-family: var(--font-pixel);
  font-size: 8.5px; line-height: 1.6;
  color: var(--ink);
  text-align: center;
  padding: 8px 11px;
  transform: rotate(-7deg);
  box-shadow: 0 8px 16px -8px rgba(34,29,23,0.6);
}
.sticker::before {
  content: "";
  position: absolute; top: -10px; left: 50%;
  transform: translateX(-50%) rotate(4deg);
  width: 44px; height: 17px;
  background: rgba(255,255,255,0.5);
  border-left: 1px dashed rgba(34,29,23,0.25);
  border-right: 1px dashed rgba(34,29,23,0.25);
}

.modal-top { display: flex; align-items: center; gap: 12px; }
.hero-mark {
  width: 40px; height: 40px;
  gap: 2.5px;
  flex: none;
}
.modal-eyebrow {
  font-family: var(--font-pixel);
  font-size: 11px;
  color: var(--tomato);
  margin: 0;
}
.modal-heading {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 33px;
  line-height: 1.02;
  letter-spacing: -0.01em;
  margin: 16px 0 0;
}
.modal-heading em {
  font-style: italic;
  position: relative;
  white-space: nowrap;
}
.modal-heading em::before {
  content: "";
  position: absolute; left: -3px; right: -3px; bottom: 5px;
  height: 40%;
  background: var(--yellow);
  z-index: -1;
  transform: rotate(-1.5deg);
  border-radius: 4px 9px 5px 8px;
}
.modal-lede {
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--ink-soft);
  margin: 14px 0 0;
}

.modal-reasons {
  list-style: none;
  margin: 18px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 13px;
}
.modal-reasons li {
  display: flex;
  gap: 12px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink-soft);
}
.modal-reasons strong { color: var(--ink); font-weight: 700; }
.reason-num {
  flex: none;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  font-family: var(--font-pixel);
  font-size: 11px;
  color: var(--ink);
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: 9px 7px 8px 10px;
}
.modal-reasons li:nth-child(1) .reason-num { background: #ffb9a8; }
.modal-reasons li:nth-child(2) .reason-num { background: #b9e0a8; }
.modal-reasons li:nth-child(3) .reason-num { background: #a8cfff; }

.modal-cta { position: relative; margin: 22px 0 0; }
.modal-discord {
  display: flex; align-items: center; justify-content: center; gap: 11px;
  width: 100%;
  background: var(--discord);
  color: #fff;
  text-decoration: none;
  font-family: var(--font-mono);
  font-weight: 700; font-size: 15px;
  padding: 15px;
  border: 2.5px solid var(--ink);
  border-radius: 15px 12px 16px 11px;
  box-shadow: 0 4px 0 var(--ink);
  transition: transform 0.12s, background 0.15s, box-shadow 0.12s;
}
.modal-discord:hover { background: var(--discord-hi); transform: translateY(-2px); box-shadow: 0 6px 0 var(--ink); }
.modal-discord:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.cta-doodle {
  position: absolute;
  right: 24px; bottom: -30px;
  display: flex; align-items: flex-end; gap: 4px;
  color: var(--tomato);
  transform: rotate(-2deg);
  pointer-events: none;
}
.cta-doodle span { font-family: var(--font-pixel); font-size: 8.5px; margin-bottom: 7px; }

.modal-browse {
  display: block;
  margin: 46px auto 0;
  background: none; border: none;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 12.5px;
  cursor: pointer;
  transition: color 0.15s;
}
.modal-browse:hover { color: var(--ink); text-decoration: underline wavy; }

.modal-foot {
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 2px dashed var(--rule);
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--faint);
  text-align: center;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 92px; left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  background: var(--ink);
  color: var(--paper);
  padding: 11px 17px;
  border-radius: 12px 9px 13px 10px;
  font-family: var(--font-mono);
  font-size: 13px; font-weight: 700;
  box-shadow: var(--lift);
  animation: toast-in 0.25s cubic-bezier(0.16,1,0.3,1) both;
}

/* ---------- keyframes ---------- */
@keyframes pop { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(18px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

.hidden { display: none !important; }

@media (max-width: 560px) {
  .brand-sub { display: none; }
  .modal-heading { font-size: 27px; }
  .palette { max-width: 50vw; }
  .hint { display: none; }
  .dock-hex, .dock-label { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
