:root {
  --ink: #1b1530;
  --cream: #fff4d6;
  --gold: #ffcf4a;
  --top-h: 72px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #0f0c22; color: var(--cream); overflow: hidden; overscroll-behavior: none; }
body { font-family: "VT323", ui-monospace, monospace; font-size: 20px; -webkit-user-select: none; user-select: none; }
button, input { font-family: inherit; }
input { -webkit-user-select: text; user-select: text; }
img, canvas { image-rendering: pixelated; image-rendering: crisp-edges; }

/* ---------- header ---------- */
.top {
  height: var(--top-h); display: flex; align-items: center; gap: 16px;
  padding: 0 16px; background: var(--ink); border-bottom: 4px solid #000;
  position: relative; z-index: 20;
}
.brand { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.logo { font-family: "Press Start 2P", monospace; font-size: 18px; color: var(--gold); text-shadow: 3px 3px 0 #b1452d; white-space: nowrap; }
.slogan { font-size: 18px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats { margin-left: auto; font-size: 22px; white-space: nowrap; }
.stats span { color: var(--gold); font-family: "Press Start 2P", monospace; font-size: 14px; }
.actions { display: flex; gap: 8px; }

.px-btn {
  font-family: "Press Start 2P", monospace; font-size: 10px; line-height: 1;
  padding: 10px 12px; background: var(--cream); color: var(--ink);
  border: 0; box-shadow: inset -3px -3px 0 #c9b98f, 0 0 0 3px #000;
  cursor: pointer; text-decoration: none; white-space: nowrap; display: inline-block;
}
.px-btn:hover { transform: translateY(-1px); }
.px-btn:active { transform: translateY(1px); box-shadow: inset 3px 3px 0 #c9b98f, 0 0 0 3px #000; }
.px-btn.primary { background: var(--gold); box-shadow: inset -3px -3px 0 #c4891b, 0 0 0 3px #000; }
.px-btn.big { font-size: 13px; padding: 16px 18px; width: 100%; }
.px-btn:disabled { opacity: .6; cursor: wait; }

@media (max-width: 900px) {
  :root { --top-h: 104px; }
  .top { flex-wrap: wrap; align-content: center; gap: 8px 12px; padding: 8px 12px; }
  .actions { width: 100%; overflow-x: auto; padding: 3px; }
  .slogan { display: none; }
  .logo { font-size: 14px; }
}

/* ---------- world ---------- */
.world { position: relative; height: calc(100% - var(--top-h)); overflow: hidden; background: #2d6a3a; touch-action: none; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: pointer; }

.find { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 5; }
.find input { font-size: 20px; width: min(300px, 62vw); padding: 5px 10px; background: #1b1530e6; color: var(--cream); border: 3px solid #000; outline: none; }
.find input:focus { border-color: var(--gold); }
.demo-badge { position: absolute; top: 12px; right: 12px; z-index: 5; font-family: "Press Start 2P", monospace; font-size: 9px; background: #c0392b; padding: 6px 8px; border: 3px solid #000; }
.help { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 5; background: #1b1530e6; border: 3px solid #000; padding: 6px 12px; font-size: 19px; white-space: nowrap; transition: opacity .6s; pointer-events: none; }
.help.gone { opacity: 0; }

/* RPG dialog box */
.dialog {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 8;
  width: min(720px, calc(100% - 24px)); min-height: 96px;
  background: #fffdf4; color: #1b1530; border: 4px solid #1b1530;
  box-shadow: inset 0 0 0 4px #fffdf4, inset 0 0 0 7px #7fa7d9, 0 6px 0 #0006;
  padding: 18px 22px; font-size: 26px; line-height: 1.15; white-space: pre-line; cursor: pointer;
}
.dialog .more { position: absolute; right: 16px; bottom: 8px; font-size: 16px; animation: blink .7s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* touch controls */
.pad, .abtn { display: none; }
@media (pointer: coarse) {
  .pad { display: grid; position: absolute; left: 14px; bottom: 18px; z-index: 6;
    grid-template-columns: 52px 52px 52px; grid-template-rows: 52px 52px 52px; }
  .pad button { background: #1b1530cc; color: var(--cream); border: 3px solid #000; font-size: 20px; touch-action: none; }
  .pad button:active, .pad button.on { background: var(--gold); color: var(--ink); }
  .pad [data-dir=up] { grid-column: 2; grid-row: 1; }
  .pad [data-dir=left] { grid-column: 1; grid-row: 2; }
  .pad [data-dir=right] { grid-column: 3; grid-row: 2; }
  .pad [data-dir=down] { grid-column: 2; grid-row: 3; }
  .abtn { display: block; position: absolute; right: 20px; bottom: 40px; z-index: 6; width: 72px; height: 72px; border-radius: 50%;
    background: #e04848; color: #fff; border: 4px solid #000; font-family: "Press Start 2P", monospace; font-size: 18px; touch-action: none; }
  .abtn:active { background: #ff7a6a; }
  .help { display: none; }
  .dialog { bottom: 190px; font-size: 22px; }
}

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: #0009; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.panel { position: relative; background: var(--ink); border: 4px solid #000; box-shadow: 0 0 0 4px var(--gold), 12px 12px 0 #000; padding: 24px; width: min(380px, 100%); max-height: 92vh; overflow-y: auto; text-align: center; }
.panel.wide { width: min(460px, 100%); text-align: left; }
.panel h2 { font-family: "Press Start 2P", monospace; font-size: 15px; color: var(--gold); margin: 8px 0 12px; line-height: 1.5; word-break: break-word; }
.close { position: absolute; top: 8px; right: 8px; background: none; border: 0; color: var(--cream); font-size: 22px; cursor: pointer; }
.big-meme { width: 192px; height: 192px; border: 4px solid #000; background: #ffd98a; object-fit: cover; }
.tagline { font-size: 22px; margin: 0 0 14px; }
.meta { display: flex; justify-content: center; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.meta a { color: var(--cream); opacity: .8; }
.tier-pill { font-family: "Press Start 2P", monospace; font-size: 9px; background: var(--gold); color: var(--ink); padding: 5px 7px; }
.hint { margin: 0 0 10px; opacity: .9; } .hint.small { font-size: 17px; opacity: .7; margin-top: 10px; }
.sizes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.sizes button { font-family: "Press Start 2P", monospace; font-size: 9px; padding: 12px 4px; background: #0004; color: var(--cream); border: 3px solid #000; cursor: pointer; }
.sizes button.sel { background: var(--gold); color: var(--ink); }
#mEdit { margin-left: 8px; }
.tiers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 18px; }
.tiers div { background: #0004; border: 3px solid #000; padding: 8px; text-align: center; font-size: 17px; line-height: 1.1; }
.tiers b { display: block; font-family: "Press Start 2P", monospace; font-size: 9px; color: var(--gold); margin-bottom: 6px; }
form label { display: block; margin: 12px 0 4px; font-size: 19px; }
form input[maxlength] { width: 100%; font-size: 21px; padding: 6px 8px; background: var(--cream); color: var(--ink); border: 3px solid #000; outline: none; }
.wallet-line { font-size: 18px; opacity: .85; }
.colors { display: flex; gap: 8px; flex-wrap: wrap; }
.colors button { width: 32px; height: 32px; border: 3px solid #000; cursor: pointer; }
.colors button.sel { box-shadow: 0 0 0 3px var(--gold); }
.upload { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.upload input { font-size: 16px; flex: 1; min-width: 0; color: var(--cream); }
.upload canvas { width: 96px; height: 96px; border: 3px solid #000; background: #ffd98a; flex: none; }
.msg { min-height: 1.2em; margin: 10px 0 0; font-size: 19px; }
.msg.err { color: #ff8a7a; } .msg.ok { color: #9be38f; }

.toast { position: fixed; left: 50%; top: 140px; transform: translateX(-50%); z-index: 60; background: var(--gold); color: var(--ink); font-family: "Press Start 2P", monospace; font-size: 11px; padding: 12px 16px; border: 3px solid #000; }

@media (max-width: 600px) { .demo-badge { top: 56px; right: 10px; } }

.file-btn { margin: 0; flex: none; }
.file-name { flex: 1; min-width: 0; font-size: 17px; opacity: .8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#shopModal .px-btn { margin: 6px 4px 0; }
.px-btn.danger { background: #e04848; color: #fff; box-shadow: inset -3px -3px 0 #a83232, 0 0 0 3px #000; }
