@font-face {
  font-family: "Pixelify Sans";
  src: url("/fonts/PixelifySans.ttf") format("truetype");
  font-weight: 400 700;
  font-display: swap;
}

:root {
  --ink: #5b3b57;
  --ink-soft: #8a6a86;
  --paper: #fff6e8;
  --paper-2: #fdebd5;
  --paper-3: #f6dcc0;
  --pink: #ff8fb8;
  --pink-d: #df5f97;
  --mint: #8fe3c2;
  --mint-d: #4fb894;
  --gold: #ffd166;
  --sky: #74c8ec;
  --shadow: rgba(70, 35, 80, 0.32);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--sky); }
body {
  font-family: "Pixelify Sans", ui-rounded, "Trebuchet MS", sans-serif;
  font-size: 15px; line-height: 1.3; color: var(--ink);
  -webkit-font-smoothing: none; user-select: none; -webkit-user-select: none;
  touch-action: none;
}
[hidden] { display: none !important; }
canvas { image-rendering: pixelated; image-rendering: crisp-edges; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
#view.dragging { cursor: grabbing; }
#view.pointing { cursor: pointer; }

/* --- the chunky pixel frame used by every panel and button --------------- */
.px {
  background: var(--paper);
  box-shadow:
    -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink),
    0 7px 0 0 var(--shadow), -3px 4px 0 0 var(--shadow), 3px 4px 0 0 var(--shadow),
    inset 0 2px 0 0 #fff, inset 0 -3px 0 0 var(--paper-3);
  margin: 3px;
}

.bar { position: fixed; top: 10px; left: 10px; display: flex; align-items: center; gap: 9px; padding: 6px 12px 7px; white-space: nowrap; }
.bar canvas { width: 22px; height: 22px; }
.brand { font-weight: 700; color: var(--pink-d); letter-spacing: 0.3px; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.mini { font: inherit; font-size: 13px; color: var(--ink); background: var(--paper-2); border: 0; padding: 1px 7px 2px; cursor: pointer; box-shadow: 0 0 0 2px var(--paper-3); }
.mini:hover { background: #fff; box-shadow: 0 0 0 2px var(--pink); }
/* thumbs up / down with counts (top bar and Atlas entries) */
.votes { display: inline-flex; gap: 5px; align-items: center; }
.vote { font: inherit; font-size: 12px; color: var(--ink); border: 0; background: var(--paper-2); box-shadow: 0 0 0 2px var(--paper-3); padding: 1px 5px 1px 3px; cursor: pointer; display: inline-flex; align-items: center; gap: 3px; }
.vote:hover { background: #fff; box-shadow: 0 0 0 2px var(--pink); }
.vote.mine { background: #fff3c4; box-shadow: 0 0 0 2px var(--gold); }
.vote canvas { width: 22px !important; height: 20px !important; }
#hud { position: relative; z-index: 7; }
#tip { position: fixed; z-index: 8; padding: 3px 9px 5px; font-size: 13px; pointer-events: none; white-space: nowrap; }
/* the white-sparkle fade between worlds */
#fade { position: fixed; inset: 0; z-index: 6; background: radial-gradient(#fffdf6, #ffe9f3); opacity: 0; transition: opacity 0.35s steps(6); pointer-events: none; }
#fade.on { opacity: 1; pointer-events: auto; }
#fade canvas { width: 100%; height: 100%; display: block; }
#problem { z-index: 12; }
.sep { width: 3px; height: 14px; background: var(--paper-3); }

#topright { position: fixed; top: 10px; right: 10px; display: flex; gap: 9px; flex-wrap: wrap; justify-content: flex-end; max-width: 60vw; }
#zoom { position: fixed; left: 236px; bottom: 14px; display: flex; flex-direction: column; gap: 9px; }

.btn {
  font: inherit; color: var(--ink); border: 0; padding: 6px 12px 7px; cursor: pointer;
  transition: transform 0.05s;
}
.btn:hover { background: #fff; }
.btn:active { transform: translateY(3px); box-shadow: -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), inset 0 2px 0 0 var(--paper-3); }
.btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 4px; }
.btn.sq { width: 34px; padding: 4px 0 6px; font-size: 20px; font-weight: 700; }
.btn.pink { background: var(--pink); color: #fff; font-weight: 700; text-shadow: 0 2px 0 var(--pink-d);
  box-shadow: -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), 0 7px 0 0 var(--shadow), -3px 4px 0 0 var(--shadow), 3px 4px 0 0 var(--shadow), inset 0 2px 0 0 #ffc2d9, inset 0 -3px 0 0 var(--pink-d); }
.btn.pink:hover { background: #ffa3c5; }
.btn.mint { background: var(--mint); font-weight: 700;
  box-shadow: -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), 0 7px 0 0 var(--shadow), -3px 4px 0 0 var(--shadow), 3px 4px 0 0 var(--shadow), inset 0 2px 0 0 #c9f5e3, inset 0 -3px 0 0 var(--mint-d); }
.btn.on { background: var(--gold); }
.btn.big { font-size: 18px; padding: 9px 20px 11px; }
.btn[disabled] { opacity: 0.55; cursor: default; }

/* --- minimap --------------------------------------------------------------- */
#minimap-wrap { position: fixed; left: 10px; bottom: 14px; padding: 5px; }
/* --mmw / --mmh: the world's width and height over its longer side, set by ui.js */
#minimap { display: block; width: calc(200px * var(--mmw, 1)); height: calc(200px * var(--mmh, 0.75)); cursor: crosshair; }
#place { text-align: center; font-size: 13px; padding-top: 4px; color: var(--ink-soft); min-height: 20px; }

/* --- ticker + toasts --------------------------------------------------------- */
#ticker {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%);
  padding: 6px 14px 8px; max-width: min(560px, calc(100vw - 500px)); text-align: center; font-size: 14px;
  animation: rise 0.25s steps(4);
}
#ticker b { color: var(--pink-d); }
#toasts { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 10px; align-items: center; pointer-events: none; }
.toast { padding: 7px 14px 9px; animation: rise 0.25s steps(4); background: var(--gold); }
@keyframes rise { from { opacity: 0; translate: 0 10px; } to { opacity: 1; translate: 0 0; } }

/* --- side panels --------------------------------------------------------------- */
.panel {
  position: fixed; top: 62px; right: 10px; width: 318px; max-height: calc(100vh - 150px);
  display: flex; flex-direction: column; animation: slide 0.2s steps(4);
}
@keyframes slide { from { opacity: 0; translate: 16px 0; } to { opacity: 1; translate: 0 0; } }
.panel header { display: flex; gap: 10px; padding: 10px 10px 8px; border-bottom: 3px solid var(--paper-3); }
.panel .scroll { overflow-y: auto; padding: 8px 10px 12px; scrollbar-width: thin; scrollbar-color: var(--pink) var(--paper-2); touch-action: pan-y; }
.portrait { width: 84px; height: 84px; flex: none; background: linear-gradient(#bfeeff 0 62%, #8fdcae 62%); box-shadow: 0 0 0 3px var(--ink); position: relative; overflow: hidden; }
.portrait canvas { position: absolute; left: 50%; bottom: -8px; transform: translateX(-50%); }
.who { flex: 1; min-width: 0; }
.who h2 { margin: 0; font-size: 21px; line-height: 1.1; color: var(--pink-d); overflow: hidden; text-overflow: ellipsis; }
.who .tag { display: inline-block; font-size: 12px; background: var(--paper-3); padding: 1px 6px 2px; margin: 3px 4px 0 0; }
.who .tag.you { background: var(--pink); color: #fff; }
.who .status { margin-top: 5px; font-size: 13px; color: var(--ink-soft); min-height: 34px; }
.x { position: absolute; top: 4px; right: 6px; background: none; border: 0; font: inherit; font-size: 20px; color: var(--ink-soft); cursor: pointer; padding: 2px 6px; }
.x:hover { color: var(--pink-d); }

h3 { margin: 12px 0 5px; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--ink-soft); display: flex; justify-content: space-between; }
h3:first-child { margin-top: 2px; }
.needs { display: grid; grid-template-columns: auto 1fr; gap: 4px 8px; align-items: center; font-size: 13px; }
.meter { height: 10px; background: var(--paper-3); box-shadow: 0 0 0 2px var(--ink); }
.meter i { display: block; height: 100%; box-shadow: inset 0 3px 0 0 rgba(255, 255, 255, 0.45); transition: width 0.6s steps(8); }
.bag { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.slot { position: relative; aspect-ratio: 1; background: var(--paper-2); box-shadow: 0 0 0 2px var(--paper-3); display: grid; place-items: center; }
.slot.worn { box-shadow: 0 0 0 2px var(--pink); background: #ffe6f0; }
.slot.r2 { background: #e8e0ff; } .slot.r3 { background: #fff0b8; }
.slot canvas { max-width: 92%; max-height: 92%; }
.slot b { position: absolute; right: 1px; bottom: -2px; font-size: 11px; color: var(--ink); text-shadow: 0 0 2px #fff, 0 0 2px #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { font-size: 12px; padding: 2px 7px 3px; background: var(--paper-2); box-shadow: 0 0 0 2px var(--paper-3); }
.chip.got { background: #d9f7e8; box-shadow: 0 0 0 2px var(--mint-d); }
.chip.link { cursor: pointer; } .chip.link:hover { background: #fff; box-shadow: 0 0 0 2px var(--pink); }
.chip.dim { color: #c9b3b9; }
.chip .in { font-style: normal; color: var(--ink-soft); }
.who .tag.where { background: #e3f4ff; }

/* --- the Atlas -------------------------------------------------------------------- */
#atlas .home { width: 100%; margin: 4px 0 10px; }
a.btn { text-decoration: none; display: inline-block; }
#atlas .build { display: block; text-align: center; margin: 2px 3px 10px; padding: 4px 10px 5px; font-size: 14px; }
.world .edit { display: inline-grid; place-items: center; padding: 1px 3px; background: var(--paper); box-shadow: 0 0 0 2px var(--paper-3); }
.world .edit:hover { background: #fff; box-shadow: 0 0 0 2px var(--pink); }
.world .edit canvas { display: block; }
.worlds + .empty, .worlds ~ .empty { margin-top: 8px; }
.worlds { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.world { display: grid; grid-template-columns: 84px 1fr; gap: 9px; padding: 6px; background: var(--paper-2); box-shadow: 0 0 0 2px var(--paper-3); cursor: pointer; }
.world:hover { background: #fff; box-shadow: 0 0 0 2px var(--pink); }
.world.here { background: #e9f9f1; box-shadow: 0 0 0 2px var(--mint-d); cursor: default; }
.world .thumb { width: 84px; height: 63px; display: grid; place-items: center; background: #5cadde; box-shadow: 0 0 0 2px var(--ink); overflow: hidden; }
.world .thumb canvas { max-width: 84px; max-height: 63px; width: 84px; object-fit: contain; }
.world .info { min-width: 0; display: flex; flex-direction: column; gap: 1px; font-size: 13px; }
.world .info b { font-size: 15px; color: var(--pink-d); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.world .by { color: var(--ink-soft); font-size: 12px; }
.world .blurb { font-size: 12px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; user-select: text; -webkit-user-select: text; }
.world .meta { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; margin-top: 3px; font-size: 12px; }
.world .yours { color: #fff; background: var(--pink); padding: 0 5px 1px; }
.world .herenow { color: var(--mint-d); font-weight: 700; }
.world .votes { margin-left: auto; }
.diary { list-style: none; margin: 0; padding: 0; font-size: 13.5px; }
.diary li { padding: 5px 0 6px; border-bottom: 2px dotted var(--paper-3); display: grid; grid-template-columns: 22px 1fr; gap: 6px; user-select: text; -webkit-user-select: text; }
.diary li.new { background: #fff9c9; }
.diary .when { display: block; font-size: 11px; color: var(--ink-soft); }
.diary canvas { margin-top: 2px; }
.empty { color: var(--ink-soft); font-size: 13px; }
.stats { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; text-align: center; font-size: 11px; color: var(--ink-soft); }
.stats b { display: block; font-size: 17px; color: var(--ink); }

/* --- modals --------------------------------------------------------------------- */
.veil { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(90, 50, 100, 0.28); z-index: 10; padding: 12px; overflow: auto; touch-action: pan-y; }
#loading { background: linear-gradient(#bfeeff, #ffd9ea); }
.card { padding: 20px 26px 24px; max-width: 460px; position: relative; animation: rise 0.25s steps(4); }
.card.center { text-align: center; }
.card.wide { max-width: 860px; width: 100%; padding: 16px 20px 20px; }
.card h1 { margin: 0 0 8px; }
.card h2 { margin: 0 0 6px; font-size: 22px; color: var(--pink-d); }
.card p { margin: 6px 0 12px; }
.logo { font-size: 44px; line-height: 0.95; color: var(--pink); text-shadow: 0 3px 0 var(--pink-d), 0 6px 0 var(--ink); letter-spacing: 1px; }
.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.small { font-size: 13px; color: var(--ink-soft); }

.creator { display: grid; grid-template-columns: 250px 1fr; gap: 18px; }
.stage { background: linear-gradient(#bfeeff 0 58%, #8fdcae 58%); box-shadow: 0 0 0 3px var(--ink); height: 250px; overflow: hidden; position: relative; }
.stage canvas { position: absolute; left: 50%; bottom: 6px; transform: translateX(-50%); }
.left { display: flex; flex-direction: column; gap: 12px; }
.name-row { display: flex; gap: 8px; }
input[type="text"] {
  font: inherit; font-size: 18px; color: var(--ink); width: 100%; min-width: 0; padding: 6px 9px 7px; border: 0; background: #fff;
  box-shadow: 0 0 0 3px var(--ink), inset 0 3px 0 0 var(--paper-3); user-select: text; -webkit-user-select: text;
}
input[type="text"]:focus { outline: 3px solid var(--gold); outline-offset: 3px; }
.opts { max-height: min(68vh, 560px); overflow-y: auto; padding: 3px 8px 6px 3px; scrollbar-width: thin; scrollbar-color: var(--pink) var(--paper-2); touch-action: pan-y; }
.pick { display: flex; flex-wrap: wrap; gap: 7px; }
.opt { font: inherit; font-size: 13px; color: var(--ink); border: 0; cursor: pointer; background: var(--paper-2); box-shadow: 0 0 0 2px var(--paper-3); padding: 3px 8px 4px; display: grid; place-items: center; }
.opt:hover { background: #fff; }
.opt.sel { background: #ffe6f0; box-shadow: 0 0 0 3px var(--pink-d); }
.opt canvas { width: 56px; height: 68px; margin: -14px -4px -2px; pointer-events: none; }
.opt.sw { width: 30px; height: 30px; padding: 0; box-shadow: 0 0 0 2px var(--ink), inset 0 3px 0 0 rgba(255, 255, 255, 0.5), inset 0 -3px 0 0 rgba(0, 0, 0, 0.15); }
.opt.sw.sel { box-shadow: 0 0 0 2px var(--ink), 0 0 0 5px var(--gold), inset 0 3px 0 0 rgba(255, 255, 255, 0.5), inset 0 -3px 0 0 rgba(0, 0, 0, 0.15); }
.opt.persona { text-align: left; display: block; width: calc(50% - 4px); padding: 5px 8px 6px; }
.opt.persona b { display: block; font-size: 14px; }
.opt.persona span { font-size: 12px; color: var(--ink-soft); }
.err { color: #d0304f; font-size: 13px; min-height: 18px; }

@media (max-width: 760px) {
  body { font-size: 14px; }
  .bar .sep, #pop { display: none; }
  /* the world's name on its own line above the clock; votes and Home live in the Atlas here */
  .bar { max-width: calc(42vw - 10px); flex-wrap: wrap; row-gap: 1px; }
  .brand { flex-basis: 100%; max-width: 100%; font-size: 13px; }
  #world-votes, #btn-home { display: none; }
  .bar { padding: 5px 8px 6px; gap: 6px; }
  #topright { max-width: 58vw; gap: 7px; }
  #btn-names, #btn-help, #btn-build { display: none; } /* Build a world is in the Atlas here */
  .btn { padding: 5px 9px 6px; }
  #minimap { width: calc(120px * var(--mmw, 1)); height: calc(120px * var(--mmh, 0.75)); }
  #place { display: none; }
  #ticker { bottom: auto; top: 58px; max-width: calc(100vw - 30px); }
  .panel { top: auto; bottom: 0; right: 0; left: 0; width: auto; max-height: 52vh; margin: 3px 6px 6px; }
  .creator { grid-template-columns: 1fr; }
  .stage { height: 190px; } .stage canvas { scale: 0.8; transform-origin: bottom center; translate: -40% 0; transform: none; left: 50%; }
  .opts { max-height: none; }
  .opt.persona { width: 100%; }
  #zoom { left: 152px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
