@font-face {
  font-family: 'Press Start 2P';
  src: url('/fonts/PressStart2P-Regular.ttf') format('truetype');
  font-display: swap;
}

:root {
  --bg: #1b1410;
  --ink: #fff6d8;
  --gold: #ffd640;
  --ember: #ff8a2e;
  --flame: #e2531c;
  --shadow: #7a1e08;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
}

body {
  font-family: 'Press Start 2P', ui-monospace, monospace;
  color: var(--ink);
  -webkit-font-smoothing: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#stage {
  position: fixed;
  inset: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  background: radial-gradient(120% 80% at 50% 110%, #4a1f0e 0%, var(--bg) 60%);
}

canvas {
  display: block;
  flex: none;
  touch-action: none;
  outline: none;
}

/* portrait phones in LANDSCAPE mode: the game sits in a wide band with the title above */
.band-only { display: none; }
body.band .band-only { display: block; }

.title {
  margin: 0;
  font-size: clamp(22px, 8vw, 44px);
  font-weight: normal;
  color: var(--gold);
  text-shadow: 4px 4px 0 var(--shadow);
  letter-spacing: 2px;
}

/* the game band: taps and swipes above and below it play too (app.js) */
body.band #stage { touch-action: none; }

#chip {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 14px);
  transform: translateX(-50%);
  padding: 10px 14px;
  font: inherit;
  font-size: 10px;
  line-height: 1.4;
  color: var(--gold);
  background: rgba(27, 20, 16, 0.85);
  border: 3px solid var(--gold);
  box-shadow: 0 4px 0 #000;
  cursor: pointer;
  white-space: nowrap;
}

#chip:active { transform: translate(-50%, 2px); box-shadow: 0 2px 0 #000; }
#chip[hidden] { display: none; }

/* ─── menu: docked right in landscape, on top in portrait, so the dino stays in view ─── */
#menu {
  position: fixed;
  z-index: 5;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(460px, 52vw);
  padding: calc(env(safe-area-inset-top) + 14px) calc(env(safe-area-inset-right) + 14px) calc(env(safe-area-inset-bottom) + 14px) 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: rgba(27, 20, 16, 0.94);
  border-left: 4px solid var(--gold);
  box-shadow: -6px 0 0 rgba(0, 0, 0, 0.35);
  user-select: none;
  -webkit-user-select: none;
}

#menu[hidden] { display: none; }

body.upright #menu {
  left: 0;
  bottom: auto;
  width: auto;
  max-height: 56%;
  padding: calc(env(safe-area-inset-top) + 12px) calc(env(safe-area-inset-right) + 12px) 12px calc(env(safe-area-inset-left) + 12px);
  border-left: 0;
  border-bottom: 4px solid var(--gold);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.35);
}

.menu-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.menu-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: normal;
  color: var(--gold);
  text-shadow: 3px 3px 0 var(--shadow);
}

.btn, .tabs button, .seg button, .swatches button {
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn {
  padding: 9px 12px;
  font-size: 10px;
  background: #3a2418;
  border: 3px solid var(--ink);
  box-shadow: 0 3px 0 #000;
}

.btn.gold { color: #1b1410; background: var(--gold); border-color: #fff3b0; }
.btn:active, .seg button:active { transform: translateY(2px); box-shadow: 0 1px 0 #000; }

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}

.tabs button {
  flex: 1;
  padding: 9px 0;
  font-size: 11px;
  background: transparent;
  border: 3px solid rgba(255, 246, 216, 0.35);
}

.tabs button[aria-selected="true"] { color: #1b1410; background: var(--ink); border-color: var(--ink); }

.picker {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.wheel-wrap {
  position: relative;
  flex: none;
  width: clamp(120px, min(30vh, 22vw), 220px);
  aspect-ratio: 1;
  touch-action: none;
}

body.upright .wheel-wrap { width: clamp(130px, 40vw, 220px); }

#wheel {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  box-shadow: 0 0 0 3px #000, 0 0 0 6px var(--ink);
  cursor: crosshair;
  touch-action: none;
}

#knob {
  position: absolute;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 2px #000;
  pointer-events: none;
}

.picker-side {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 9px;
  letter-spacing: 1px;
  opacity: 0.95;
}

.hex-row { display: flex; gap: 8px; align-items: center; }

#swatch {
  flex: none;
  width: 30px;
  height: 30px;
  border: 3px solid var(--ink);
  background: #94e502;
}

#hex {
  width: 100%;
  min-width: 0;
  padding: 7px 8px;
  font: inherit;
  font-size: 16px; /* 16px keeps iPhones from zooming in */
  color: var(--ink);
  background: #000;
  border: 3px solid var(--ink);
  border-radius: 0;
  outline: none;
  text-transform: uppercase;
  user-select: text;
  -webkit-user-select: text;
}

#hex:focus { border-color: var(--gold); }
#hex.bad { border-color: #ff5a3c; }

.swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(26px, 1fr));
  gap: 6px;
}

.swatches button {
  aspect-ratio: 1;
  padding: 0;
  border: 3px solid rgba(255, 246, 216, 0.5);
}

.swatches button[aria-pressed="true"] { border-color: #fff; box-shadow: 0 0 0 2px #000, 0 0 0 4px var(--gold); }

.note {
  margin: 12px 0 0;
  font-size: 8px;
  line-height: 1.9;
  opacity: 0.75;
}

.note:empty { display: none; }

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 12px;
  margin-bottom: 12px;
  font-size: 10px;
}

.seg { display: flex; }

.seg button {
  padding: 9px 10px;
  font-size: 9px;
  background: transparent;
  border: 3px solid rgba(255, 246, 216, 0.4);
}

.seg button + button { border-left: 0; }
.seg button[aria-pressed="true"] { color: #1b1410; background: var(--gold); border-color: var(--gold); }

body:not(.touch) .touch-only { display: none; }

/* ─── profile: picture + name ─── */
.id-card {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}

.avatar {
  flex: none;
  width: 72px;
  height: 72px;
  padding: 4px;
  image-rendering: pixelated;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 120%, #ff9d4a 0%, #e2531c 45%, #4a1f0e 100%);
  box-shadow: 0 4px 0 #000;
}

.id-text { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.id-label { font-size: 8px; letter-spacing: 2px; opacity: 0.7; }
.id-name { font-size: 18px; color: var(--gold); text-shadow: 3px 3px 0 var(--shadow); overflow-wrap: anywhere; }
.id-name.empty { opacity: 0.4; }

#name {
  width: 100%;
  padding: 9px 10px;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  text-transform: uppercase;
  background: #000;
  border: 3px solid var(--ink);
  border-radius: 0;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}

#name:focus { border-color: var(--gold); }
#name.bad { border-color: #ff5a3c; }
.note.warn { color: #ff8a6a; opacity: 1; margin: -4px 0 10px; }
.label-gap { margin: 6px 0 8px; }

/* ─── first visit: the profile screen fills the page ─── */
.welcome-only { display: none; }
body.welcome .welcome-only { display: block; }
body.welcome #settings-tabs, body.welcome #menu-close { display: none; }

body.welcome #menu {
  inset: 0;
  width: auto;
  max-height: none;
  border: 0;
  box-shadow: none;
  background: radial-gradient(120% 80% at 50% 110%, #4a1f0e 0%, var(--bg) 60%);
}

body.welcome .menu-inner { max-width: 560px; margin: 0 auto; }
body.welcome .menu-head h2 { font-size: 20px; }
.lead { margin: -2px 0 16px; font-size: 10px; line-height: 1.8; opacity: 0.85; }
body.welcome .avatar { width: 96px; height: 96px; }
body.welcome .id-name { font-size: 22px; }

.btn.big { width: 100%; margin-top: 18px; padding: 14px; font-size: 14px; }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }

/* ─── shop ─── */
.purse { display: flex; align-items: center; gap: 10px; margin: 0 0 6px; font-size: 14px; color: var(--gold); }
.coin {
  width: 22px;
  height: 22px;
  border: 3px solid #a86a00;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff3a0, #ffc81e 55%, #d89400);
}

.shelf-title { margin: 16px 0 8px; font-size: 10px; font-weight: normal; letter-spacing: 2px; opacity: 0.8; }
.shelf-title .sub { font-size: 7px; opacity: 0.7; letter-spacing: 1px; }

.shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.shelf.powers { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }

.shelf li {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 10px 8px;
  font-size: 8px;
  line-height: 1.6;
  text-align: center;
  border: 3px solid rgba(255, 246, 216, 0.3);
  background: rgba(0, 0, 0, 0.25);
}

.shelf .thumb { display: grid; place-items: center; width: 64px; height: 56px; }
.shelf .thumb img { max-width: 64px; max-height: 56px; image-rendering: pixelated; }
.shelf .iname, .shelf .pname { font-size: 9px; color: var(--ink); }
.shelf .slot { font-size: 7px; opacity: 0.6; letter-spacing: 1px; }
.shelf .dots { display: flex; gap: 8px; align-items: center; justify-content: center; height: 30px; }
.shelf .dots img { height: 26px; width: auto; image-rendering: pixelated; }
.shelf .dots img.off { opacity: 0.45; filter: grayscale(1); }
.shelf .pdesc { min-height: 4.8em; opacity: 0.85; }
.shelf.powers li > button { margin-top: auto; }   /* every card's button on one line */
.shelf .afford { border-color: rgba(255, 214, 64, 0.7); }
.shelf .worn { border-color: #7ce0ff; background: rgba(124, 224, 255, 0.12); }
.shelf .soon { opacity: 0.5; }
.btn.small { padding: 7px 8px; font-size: 8px; width: 100%; }

/* ─── leaderboard ─── */
.board { margin: 0; padding: 0; list-style: none; }

.board li, .board.me-row {
  display: grid;
  grid-template-columns: 34px 36px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  font-size: 11px;
  border-bottom: 2px solid rgba(255, 246, 216, 0.12);
}

.board .rank { text-align: right; opacity: 0.75; }
.board .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .pts { color: var(--gold); }
.board .mini { width: 36px; height: 36px; padding: 2px; border-radius: 50%; image-rendering: pixelated;
  background: radial-gradient(circle at 50% 120%, #ff9d4a 0%, #e2531c 45%, #4a1f0e 100%); }
.board li:nth-child(1) .rank { color: #ffd640; opacity: 1; }
.board li:nth-child(2) .rank { color: #dfe6ee; opacity: 1; }
.board li:nth-child(3) .rank { color: #e0a070; opacity: 1; }
.board .you { background: rgba(255, 214, 64, 0.14); }
.board.me-row { margin-top: 8px; border: 2px dashed rgba(255, 214, 64, 0.6); }

.btn:focus-visible, .tabs button:focus-visible, .seg button:focus-visible, .swatches button:focus-visible, #chip:focus-visible, #name:focus-visible {
  outline: 3px solid #7ce0ff;
  outline-offset: 2px;
}

#loader {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: linear-gradient(#2b160d, var(--bg));
  transition: opacity 0.4s ease;
}

#loader.done { opacity: 0; pointer-events: none; }
body.welcome #loader:not(.failed) { display: none; }   /* the profile screen shows the progress */

.panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 24px;
  text-align: center;
}

.dino {
  width: 96px;
  height: 96px;
  image-rendering: pixelated;
  border: 4px solid #000;
  box-shadow: 0 6px 0 #000;
  animation: bob 0.9s steps(2) infinite;
}

@keyframes bob {
  50% { transform: translateY(-6px); }
}

.panel .title { font-size: 28px; margin-top: 6px; }

.bar {
  width: min(320px, 72vw);
  height: 20px;
  padding: 3px;
  background: #000;
  border: 3px solid var(--ink);
}

#fill {
  width: 0;
  height: 100%;
  background: repeating-linear-gradient(90deg, var(--ember) 0 10px, var(--flame) 10px 12px);
  transition: width 0.15s linear;
}

#msg {
  margin: 0;
  min-height: 1em;
  font-size: 10px;
  line-height: 1.8;
  letter-spacing: 1px;
}

#loader.failed .bar, #loader.failed .dino { display: none; }
#loader.failed #msg { max-width: 34em; color: var(--gold); }

.nojs {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 24px;
  font-size: 12px;
  text-align: center;
  background: var(--bg);
}

@media (prefers-reduced-motion: reduce) {
  .dino { animation: none; }
  #loader { transition: none; }
}
