@font-face {
  font-family: "Gaegu";
  src: url("assets/fonts/gaegu-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Gaegu";
  src: url("assets/fonts/gaegu-latin-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  --paper: #fbfbf8;
  --ink: #111111;
  --ink-soft: #55534e;
  --card: #fffffc;
  --line: #1a1a1a;
  --danger: #b3261e;
  --gutter: clamp(16px, 6.6vw, 110px);
  --hand: "Gaegu", "Comic Sans MS", "Chalkboard SE", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background-color: var(--paper);
  /* faint paper grain */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .45  0 0 0 0 .43  0 0 0 0 .38  0 0 0 .045 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  color: var(--ink);
  font-family: var(--hand);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }

/* ---------- stage / world ---------- */
#stage {
  position: fixed; inset: 0;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  user-select: none; -webkit-user-select: none;
}
#stage.dragging { cursor: grabbing; }
#world {
  position: absolute; left: 0; top: 0;
  width: 0; height: 0;
  transform-origin: 0 0;
  will-change: transform;
}
#dog {
  position: absolute;
  /* anchor point (head top) lives at world 0,0 */
  left: -172px; top: -121px;
  width: 320px; height: 440px;
  pointer-events: none;
}
#stack { position: absolute; left: 0; top: 0; }
.item {
  position: absolute;
  transform-origin: 50% 100%;
}
.item img {
  display: block; width: 100%; height: 100%;
  pointer-events: none;
  -webkit-user-drag: none;
}
.item.mine::after {
  content: ""; position: absolute; inset: -8px;
  border: 2px dashed rgba(17,17,17,.35); border-radius: 14px;
}
.item.drop { animation: drop .7s cubic-bezier(.25,1.4,.5,1) both; }
@keyframes drop {
  0% { transform: translateY(-160px) rotate(var(--r, 0deg)); opacity: 0; }
  60% { opacity: 1; }
  100% { transform: translateY(0) rotate(var(--r, 0deg)); opacity: 1; }
}
.ghost {
  position: absolute;
  border: 3px dashed rgba(17,17,17,.3);
  border-radius: 50%;
  animation: bob 1.4s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translateY(-8px) rotate(4deg); } }

/* ---------- header ---------- */
#top {
  position: fixed; left: 0; right: 0; top: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: clamp(18px, 3.6vw, 40px) var(--gutter) 0;
  pointer-events: none;
  z-index: 10;
}
#top > * { pointer-events: auto; }
.logo {
  font-weight: 700;
  font-size: clamp(34px, 3.3vw, 54px);
  letter-spacing: -.01em;
  color: var(--ink);
  text-decoration: none;
  line-height: 1;
}
.actions { position: relative; display: flex; align-items: center; gap: clamp(14px, 2vw, 30px); }
.xbtn { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; }
.xbtn:hover svg { transform: scale(1.1); }
.xbtn svg { transition: transform .2s; }

.pill {
  position: relative;
  border: 0; background: none; cursor: pointer;
  padding: 9px 18px 10px;
  font-weight: 700;
  font-size: clamp(18px, 1.45vw, 23px);
  letter-spacing: .005em;
  color: #fff;
  line-height: 1.1;
  white-space: nowrap;
}
.pill-bg {
  position: absolute; inset: 0;
  background: var(--ink);
  border-radius: 11px;
  box-shadow: inset 0 0 0 2px #2b2b2b;
  filter: url(#rough);
  transition: transform .15s;
}
.pill-label { position: relative; }
.pill:hover .pill-bg { transform: rotate(-1deg) scale(1.03); }
.pill:active .pill-bg { transform: scale(.97); }
.pill:disabled { cursor: default; opacity: .55; }
.pill.small { font-size: 20px; padding: 7px 16px 8px; }

.menu {
  position: absolute; right: 0; top: calc(100% + 10px);
  min-width: 200px;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  box-shadow: 3px 4px 0 rgba(0,0,0,.12);
  font-size: 19px;
}
.menu[hidden] { display: none; }
.menu-addr { padding: 4px 10px 8px; color: var(--ink-soft); }
.menu button {
  display: block; width: 100%; text-align: left;
  background: none; border: 0; padding: 6px 10px; border-radius: 8px; cursor: pointer;
}
.menu button:hover { background: #f1efe8; }

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 2.5px solid var(--line);
  border-radius: 16px;
  box-shadow: 4px 5px 0 rgba(0,0,0,.10);
}
/* desktop: tucked under the wallet button, clear of the stack in the middle */
#composer {
  position: fixed; z-index: 9;
  right: var(--gutter); top: clamp(96px, 12vh, 124px);
  width: min(430px, calc(50vw - 150px));
  padding: 18px 20px 14px;
  animation: pop .35s cubic-bezier(.3,1.4,.5,1);
}
#composer[hidden] { display: none; }
@keyframes pop { from { transform: translateY(-10px) scale(.97); opacity: 0; } }
/* narrow screens: a sheet at the bottom, over the dog's body */
@media (max-width: 900px) {
  #composer {
    left: 12px; right: 12px; top: auto;
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: auto;
    animation-name: rise;
  }
  @keyframes rise { from { transform: translateY(20px); opacity: 0; } }
}
.c-title { display: block; font-weight: 700; font-size: 26px; line-height: 1.1; margin-bottom: 10px; padding-right: 26px; }
.c-row { display: flex; gap: 10px; align-items: center; }
#promptInput {
  flex: 1; min-width: 0;
  font-size: 22px;
  padding: 8px 12px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #fff;
  outline: none;
}
#promptInput:focus { box-shadow: 0 0 0 3px rgba(17,17,17,.12); }
.c-note { margin: 10px 0 0; font-size: 17px; color: var(--ink-soft); line-height: 1.25; }
.c-note.err { color: var(--danger); }
.c-close {
  position: absolute; right: 10px; top: 6px;
  width: 34px; height: 34px;
  border: 0; background: none; cursor: pointer;
  font-size: 30px; line-height: 1; color: var(--ink-soft);
}
.c-close:hover { color: var(--ink); }
.dots i { font-style: normal; animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 100% { opacity: .15; } 40% { opacity: 1; } }

/* ---------- wallet modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  background: rgba(251,251,248,.72);
  backdrop-filter: blur(2px);
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal-card { position: relative; width: min(400px, 100%); padding: 20px 20px 16px; }
.modal-card h2 { margin: 0 0 14px; font-size: 30px; line-height: 1; }
.wallet-list { display: grid; gap: 10px; }
.wallet-opt {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 10px 12px;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  font-size: 22px; font-weight: 700;
  text-align: left; text-decoration: none; color: var(--ink);
  transition: transform .12s, box-shadow .12s;
}
.wallet-opt:hover { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 rgba(0,0,0,.15); }
.wallet-opt img, .wallet-opt .wi {
  width: 32px; height: 32px; border-radius: 8px; flex: none;
  display: grid; place-items: center; background: #f1efe8; font-size: 18px;
}
.wallet-opt small { margin-left: auto; font-weight: 400; font-size: 16px; color: var(--ink-soft); }
.wallet-opt[aria-busy="true"] { opacity: .6; pointer-events: none; }

/* ---------- tooltip / toast / hud ---------- */
#tip {
  position: fixed; z-index: 15;
  pointer-events: none;
  background: var(--ink); color: #fff;
  padding: 6px 11px 7px;
  border-radius: 10px;
  font-size: 18px; line-height: 1.15;
  white-space: nowrap;
  transform: translate(-50%, calc(-100% - 12px));
}
#tip[hidden] { display: none; }
#tip .t-prompt { color: #d9d6cc; font-size: 16px; }
#toast {
  position: fixed; z-index: 25; left: 50%; bottom: 26px;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  background: var(--ink); color: #fff;
  padding: 10px 16px 11px; border-radius: 12px;
  font-size: 20px; text-align: center;
  animation: pop2 .3s ease-out;
}
#toast[hidden] { display: none; }
#toast.err { background: var(--danger); }
@keyframes pop2 { from { transform: translate(-50%, 10px); opacity: 0; } }
#hud {
  position: fixed; z-index: 5;
  left: var(--gutter); right: var(--gutter); bottom: 18px;
  display: flex; justify-content: flex-end; align-items: flex-end;
  font-size: 19px; color: var(--ink-soft);
  pointer-events: none;
}
#hint[hidden] { display: none; }
#hint { animation: nudge 2.4s ease-in-out infinite; }
@keyframes nudge { 50% { transform: translateY(3px); } }

@media (max-width: 640px) {
  #top { padding-top: 16px; }
  .xbtn { width: 34px; height: 34px; }
  .xbtn svg { width: 21px; height: 21px; }
  .pill { font-size: 17px; padding: 7px 13px 8px; }
  .c-title { font-size: 23px; }
  #promptInput { font-size: 20px; }
  #hud { font-size: 17px; bottom: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
