:root {
  --bg: #1b1526;
  --bg-2: #241c33;
  --paper: #f7eed8;
  --paper-2: #efe2c3;
  --ink: #2b1d2a;
  --muted: #7d6a64;
  --line: #d9c7a0;
  --green: #4f9d5a;
  --green-d: #3b7f45;
  --pink: #e2506a;
  --gold: #e8a93a;
  --sky: #b9b0d6;
  --edge: #0f0b16;
  --shadow: 0 4px 0 var(--edge);
  --font: "Pixelify Sans", ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--paper); font-family: var(--font); font-size: 16px; min-height: 100vh;
  background-image: radial-gradient(#2e2542 1px, transparent 1px); background-size: 14px 14px; }
a { color: #c9f29b; }
button, input, select, textarea { font: inherit; color: inherit; }
code { background: rgba(255,255,255,.08); padding: 1px 5px; border-radius: 4px; }
[hidden] { display: none !important; }

.bar { display: flex; align-items: center; gap: 18px; padding: 10px 18px; background: var(--bg-2); border-bottom: 3px solid var(--edge); flex-wrap: wrap; position: sticky; top: 0; z-index: 10; }
.logo img { image-rendering: pixelated; margin-right: 8px; vertical-align: -6px; }
.logo { font-weight: 700; font-size: 26px; letter-spacing: 2px; color: #c9f29b; text-decoration: none; text-shadow: 3px 3px 0 #3b7f45; }
.nav { display: flex; gap: 4px; }
.nav a { color: var(--sky); text-decoration: none; padding: 5px 10px; border-radius: 6px; }
.nav a.on, .nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.bar-right { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chip { background: rgba(255,255,255,.07); border: 2px solid #3a3050; border-radius: 999px; padding: 4px 11px; font-size: 14px; color: var(--paper); white-space: nowrap; cursor: default; }
button.chip { cursor: pointer; }
.chip.pool { color: var(--gold); border-color: #5a4520; font-weight: 600; }
.userchip { display: flex; align-items: center; gap: 8px; }
.userchip canvas { width: 28px; height: 28px; image-rendering: pixelated; }

.btn { border: 2px solid var(--edge); background: var(--paper-2); color: var(--ink); border-radius: 8px; padding: 7px 14px; cursor: pointer; box-shadow: var(--shadow); font-weight: 600; transition: transform .05s; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--edge); }
.btn.go { background: var(--green); color: #fff; }
.btn.red { background: var(--pink); color: #fff; }
.btn.x { background: #0f0f10; color: #fff; }
.btn.gold { background: var(--gold); color: var(--ink); }
.btn.small { padding: 4px 9px; font-size: 14px; box-shadow: 0 3px 0 var(--edge); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

main { max-width: 1320px; margin: 0 auto; padding: 18px; }
.card { background: var(--paper); color: var(--ink); border: 3px solid var(--edge); border-radius: 12px; box-shadow: 0 6px 0 var(--edge); padding: 16px; }
.card h2, .card h3 { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 18px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
@media (max-width: 960px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

/* landing */
.hero { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 26px; align-items: center; margin: 10px 0 26px; }
@media (max-width: 960px) { .hero { grid-template-columns: 1fr; } }
.hero h1 { font-size: clamp(34px, 6vw, 58px); margin: 0 0 10px; line-height: 1; color: #fff; }
.hero h1 em { font-style: normal; color: #c9f29b; }
.hero p.lead { color: var(--sky); font-size: 18px; line-height: 1.45; margin: 0 0 18px; }
.steps { display: grid; gap: 10px; margin: 0 0 20px; padding: 0; list-style: none; }
.steps li { background: rgba(255,255,255,.05); border: 2px solid #3a3050; border-radius: 10px; padding: 10px 14px; line-height: 1.4; }
.steps b { color: #c9f29b; }
.tweet { font-family: var(--font); background: #0f0f10; color: #fff; border-radius: 8px; padding: 2px 8px; white-space: nowrap; }
.tweet .at { color: #1d9bf0; }
.cta { display: flex; gap: 10px; flex-wrap: wrap; }
.herocard { width: 100%; border: 3px solid var(--edge); border-radius: 14px; box-shadow: 0 6px 0 var(--edge); image-rendering: pixelated; background: #15111f; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.list li:last-child { border-bottom: 0; }
.list canvas { width: 30px; height: 30px; image-rendering: pixelated; flex: none; }
.list .grow { flex: 1; min-width: 0; }
.list .r { font-weight: 700; }
.stars { color: #d9a400; letter-spacing: 1px; }
.stars .off { color: #cdbfa0; }
.townbar { display: grid; gap: 8px; }
.townrow { display: grid; grid-template-columns: 110px 1fr 50px; gap: 10px; align-items: center; }
.townrow .meter { height: 16px; border: 2px solid var(--edge); border-radius: 5px; background: #fff; overflow: hidden; }
.townrow .meter i { display: block; height: 100%; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; border: 1px solid var(--edge); }
.feed li { font-size: 14px; }
.tag { font-size: 11px; background: #0f0f10; color: #fff; border-radius: 4px; padding: 1px 5px; }

/* base */
.basewrap { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: start; }
@media (max-width: 1000px) { .basewrap { grid-template-columns: 1fr; } }
.stage { position: relative; }
.canvas { display: block; width: 100%; height: auto; image-rendering: pixelated; border: 3px solid var(--edge); border-radius: 12px; box-shadow: 0 6px 0 var(--edge); background: #78b454; }
.resbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.res { background: var(--paper); color: var(--ink); border: 2px solid var(--edge); border-radius: 8px; padding: 5px 10px; font-weight: 600; display: flex; gap: 6px; align-items: center; box-shadow: 0 3px 0 var(--edge); }
.res small { color: var(--muted); font-weight: 400; }
.res .ic { width: 12px; height: 12px; border-radius: 3px; border: 2px solid var(--edge); }
.side { display: grid; gap: 14px; }
.tabs { display: flex; gap: 4px; margin-bottom: 10px; flex-wrap: wrap; }
.tabs button { flex: 1; border: 2px solid var(--line); background: var(--paper-2); border-radius: 8px; padding: 6px 4px; cursor: pointer; font-weight: 600; color: var(--ink); }
.tabs button.on { border-color: var(--green-d); background: #dff5d4; }
.shop { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.shop button { text-align: left; border: 2px solid var(--line); background: #fff; border-radius: 8px; padding: 7px 8px; cursor: pointer; color: var(--ink); }
.shop button:hover:not(:disabled) { border-color: var(--green-d); }
.shop button.on { border-color: var(--green-d); background: #dff5d4; }
.shop button:disabled { opacity: .5; cursor: not-allowed; }
.shop b { display: block; }
.cost { font-size: 12px; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row input, .row select { padding: 6px 9px; border: 2px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); min-width: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 14px; margin: 8px 0; }
.kv span:nth-child(odd) { color: var(--muted); }
.progress { height: 10px; border: 2px solid var(--edge); border-radius: 4px; background: #fff; overflow: hidden; margin: 6px 0; }
.progress i { display: block; height: 100%; background: var(--gold); }
.pill { font-size: 12px; padding: 2px 7px; border-radius: 999px; border: 2px solid var(--edge); background: #fff; }
.pill.shield { background: #d6e6ff; }

/* egg */
.egg { text-align: center; max-width: 560px; margin: 20px auto; }
.egg canvas { width: 240px; height: 240px; image-rendering: pixelated; cursor: pointer; }
.egg .towns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 12px 0; }
.egg .towns label { border: 2px solid var(--line); border-radius: 8px; padding: 6px 4px; cursor: pointer; background: #fff; font-size: 14px; }
.egg .towns label:has(input:checked) { border-color: var(--edge); background: #dff5d4; }
.egg .towns input { display: none; }
@keyframes shake { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-8deg); } 75% { transform: rotate(8deg); } }
.shaking { animation: shake .18s linear infinite; }

/* replay */
.replay-controls { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.replay-controls input[type=range] { flex: 1; min-width: 120px; }
.result { text-align: center; }
.result .big { font-size: 46px; font-weight: 700; }
.result .stars { font-size: 34px; }

dialog { border: 3px solid var(--edge); border-radius: 12px; background: var(--paper); color: var(--ink); padding: 0; box-shadow: 0 8px 0 var(--edge); width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10, 6, 18, .6); }
dialog form { padding: 18px; display: grid; gap: 10px; }
dialog h2 { margin: 0; }
dialog label { display: grid; gap: 4px; font-size: 14px; }
dialog input { padding: 7px 9px; border: 2px solid var(--line); border-radius: 6px; background: #fff; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 50; max-width: calc(100vw - 32px); }
.toast { background: var(--paper); color: var(--ink); border: 3px solid var(--edge); border-radius: 10px; padding: 10px 14px; box-shadow: var(--shadow); font-size: 14px; max-width: 380px; }
.toast.err { background: #ffd9de; }
.toast.ok { background: #dff5d4; }
.empty { color: var(--muted); padding: 14px 0; text-align: center; }
.stage .canvas { max-width: min(100%, calc(100vh - 170px)); margin: 0 auto; }
.card a { color: var(--green-d); }
.card a.btn { color: inherit; }
.card a.btn.x { color: #fff; }
