:root {
  --ink: #3b2a20;
  --cream: #fff6df;
  --paper: #fdf0cf;
  --red: #c0453a;
  --rose: #f1b9a8;
  --yellow: #f6d34a;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #6a9a45; color: var(--ink);
  font-family: 'VT323', monospace; font-size: 20px;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
}
#game { position: fixed; inset: 0; display: block; touch-action: none; cursor: pointer; }
.px { image-rendering: pixelated; image-rendering: crisp-edges; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 3px solid var(--red); outline-offset: 2px; }

/* ---------- HUD ---------- */
.hud-top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
  padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
  pointer-events: none;
}
.hud-top > * { pointer-events: auto; }
.brand {
  display: flex; align-items: center; gap: 10px;
  background: var(--cream); border: 3px solid var(--ink); box-shadow: 4px 4px 0 var(--ink);
  padding: 6px 12px 6px 8px;
}
.brand img { width: 33px; height: 30px; }
.brand h1 {
  margin: 0; font: 13px/1.3 'Press Start 2P', monospace;
  color: var(--red); text-shadow: 1px 1px 0 var(--rose);
}
.slogan { margin: 3px 0 0; font-size: 18px; line-height: 1; }
.hud-stats, .hud-btns { display: flex; gap: 6px; align-items: center; }
.hud-stats { margin-left: auto; }
.pill {
  display: flex; align-items: center; gap: 7px; height: 38px; padding: 2px 10px;
  background: var(--cream); border: 3px solid var(--ink); box-shadow: 3px 3px 0 var(--ink);
  font-size: 20px; white-space: nowrap;
}
.pill img { width: 12px; height: 14px; }
.dot { width: 9px; height: 9px; background: #59b84f; box-shadow: inset 0 0 0 2px #2e6b30; }
.pill.off .dot { background: var(--red); box-shadow: inset 0 0 0 2px #7a2a22; }
.icon-btn {
  width: 38px; height: 38px; padding: 0; display: grid; place-items: center;
  background: var(--cream); border: 3px solid var(--ink); box-shadow: 3px 3px 0 var(--ink);
}
.icon-btn img { width: 18px; height: 18px; }
.icon-btn.txt { font: 10px 'Press Start 2P', monospace; }
button:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }

/* ---------- Actions ---------- */
.actions {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 5;
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex; gap: 8px;
}
.actions[hidden] { display: none; }
.actions button {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px;
  min-width: 70px; padding: 8px 8px 6px;
  background: var(--cream); border: 3px solid var(--ink); box-shadow: 4px 4px 0 var(--ink);
  font: 8px 'Press Start 2P', monospace;
}
.actions button img { width: 22px; height: 22px; }
.actions button[aria-expanded="true"] { background: var(--yellow); }
.actions kbd {
  position: absolute; top: -10px; right: -8px; padding: 2px 3px;
  background: var(--yellow); border: 2px solid var(--ink); font: 8px 'Press Start 2P', monospace;
}
@media (hover: none) { .actions kbd { display: none; } }

.phrases {
  position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%); z-index: 6;
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; padding: 8px;
  background: var(--paper); border: 3px solid var(--ink); box-shadow: 4px 4px 0 var(--ink);
}
.phrases[hidden] { display: none; }
.phrases button { background: #fff; border: 2px solid var(--ink); padding: 6px 12px; font-size: 21px; text-align: left; }

.toasts {
  position: fixed; left: 50%; bottom: 108px; transform: translateX(-50%); z-index: 7;
  width: min(92vw, 430px); display: flex; flex-direction: column; align-items: center; gap: 6px;
  pointer-events: none;
}
.toast {
  background: var(--cream); border: 3px solid var(--ink); box-shadow: 4px 4px 0 var(--ink);
  padding: 6px 12px; font-size: 21px; line-height: 1.05; text-align: center;
  animation: pop .25s steps(3);
}
.toast.gold { background: #fff1b8; }
.toast b { display: block; font: 10px 'Press Start 2P', monospace; color: var(--red); margin-bottom: 5px; }
.toast.out { opacity: 0; transition: opacity .4s; }
@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 10; padding: 16px;
  display: grid; place-items: center; background: rgba(40, 30, 20, .35);
}
.modal[hidden] { display: none; }
.card {
  width: min(470px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  background: var(--paper); border: 4px solid var(--ink); box-shadow: 6px 6px 0 var(--ink);
  padding: 20px 22px; text-align: center;
}
.logo-big { display: flex; align-items: center; justify-content: center; gap: 12px; }
.logo-big img { width: 44px; height: 40px; }
.logo-big h2 { margin: 0; font: 18px/1.3 'Press Start 2P', monospace; color: var(--red); text-shadow: 2px 2px 0 var(--rose); }
.slogan-big { font-size: 25px; margin: 8px 0 14px; }
.maker {
  display: flex; gap: 16px; align-items: center; justify-content: center; text-align: left;
  background: #fff8e6; border: 3px solid var(--ink); padding: 12px;
}
#preview { width: 99px; height: 90px; image-rendering: pixelated; background: #8cc05a; border: 3px solid var(--ink); flex: none; }
.maker label { display: block; font: 9px 'Press Start 2P', monospace; margin: 2px 0 6px; }
.namebox { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.namebox span { font-size: 25px; line-height: 1; }
.small-btn {
  background: var(--yellow); border: 2px solid var(--ink); box-shadow: 2px 2px 0 var(--ink);
  font: 8px 'Press Start 2P', monospace; padding: 7px 8px;
}
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatches button { width: 24px; height: 24px; padding: 0; border: 3px solid var(--ink); }
.swatches button[aria-pressed="true"] { outline: 3px solid var(--red); outline-offset: 1px; }
.howto { font-size: 21px; line-height: 1.12; margin: 14px 0; }
.howto.small { font-size: 18px; opacity: .85; }
.big-btn {
  width: 100%; padding: 14px 18px;
  background: var(--red); color: #fff; border: 3px solid var(--ink); box-shadow: 4px 4px 0 var(--ink);
  font: 12px/1.4 'Press Start 2P', monospace;
}
.note { font-size: 18px; opacity: .8; margin: 10px 0 2px; }
.link-btn { background: none; border: none; text-decoration: underline; font-size: 19px; padding: 4px; }
.link-btn:active { transform: none; box-shadow: none; }
.about-stats { background: #fff8e6; border: 3px solid var(--ink); padding: 8px; margin: 12px 0; font-size: 21px; }
.about-btns { display: flex; gap: 10px; align-items: center; }
.about-btns .small-btn { flex: none; padding: 12px 10px; }

@media (max-width: 680px) {
  .hud-top { padding: 8px; padding-top: max(8px, env(safe-area-inset-top)); }
  .brand { padding: 4px 8px 4px 6px; gap: 6px; }
  .brand img { width: 22px; height: 20px; }
  .brand h1 { font-size: 9px; }
  .slogan { display: none; }
  .hud-top { flex-wrap: wrap; gap: 6px; }
  .hud-btns { order: 2; gap: 5px; margin-left: auto; }
  .hud-stats { order: 3; width: 100%; margin-left: 0; gap: 5px; }
  .pill { height: 32px; font-size: 18px; padding: 2px 6px; gap: 5px; }
  .icon-btn { width: 32px; height: 32px; }
  .icon-btn img { width: 16px; height: 16px; }
  .actions { gap: 6px; }
  .actions button { min-width: 0; width: 62px; font-size: 7px; padding: 7px 2px 5px; }
  .phrases { bottom: 92px; }
  .toasts { bottom: 98px; }
  .logo-big h2 { font-size: 14px; }
  .maker { gap: 12px; padding: 10px; }
  #preview { width: 77px; height: 70px; }
  .card { padding: 14px 14px; }
  .slogan-big { font-size: 21px; margin: 6px 0 10px; }
  .howto { font-size: 18px; margin: 10px 0; }
  .namebox span { font-size: 21px; }
  .note { font-size: 16px; }
}
