* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --ink: #e8ddcc;
  --dark: #0c0b0a;
  --dim: #8d8578;
  --line: #3a3630;
  --cell: 40px;
  --px: 'Silkscreen', monospace;
  --mono: 'DM Mono', monospace;
}

html, body {
  background: var(--dark);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  font-family: var(--px);
  font-size: 12px;
  color: var(--ink);
  background: var(--dark);
  border: 1px solid var(--ink);
  padding: 8px 12px;
  cursor: pointer;
  text-transform: lowercase;
}
button:hover:not(:disabled) { background: var(--ink); color: var(--dark); }
button:disabled { opacity: 0.35; cursor: default; }

.hidden { display: none !important; }

/* ---------- menu screens ---------- */

#menu {
  max-width: 560px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

.g-head h1 {
  font-family: var(--px);
  font-weight: 400;
  font-size: 26px;
  line-height: 1.1;
  margin: 0 0 10px;
}
.g-stats { display: flex; gap: 18px; flex-wrap: wrap; align-items: baseline; color: var(--dim); }
.g-stats .link { margin: 0; margin-left: auto; }
.g-stats b { color: var(--ink); font-weight: 500; }

.notice {
  margin: 18px 0 4px;
  padding: 10px 12px;
  border: 1px dashed var(--line);
  color: var(--ink);
}

.g-sec { margin-top: 26px; }
.g-sec h2 {
  font-family: var(--px);
  font-weight: 400;
  font-size: 13px;
  color: var(--dim);
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
  margin-bottom: 10px;
}
.meta { color: var(--dim); margin-bottom: 8px; }

.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

.gear-list { display: grid; gap: 8px; }
.gear {
  border: 1px solid var(--line);
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  align-items: center;
}
.gear .slot { font-family: var(--px); font-size: 10px; color: var(--dim); }
.gear .name { font-weight: 500; }
.gear .stat { color: var(--ink); }
.gear .aff { color: var(--dim); font-size: 12px; }
.gear .better { color: var(--ink); }
.gear .worse { color: var(--dim); text-decoration: line-through; }
.gear .side { grid-row: 1 / span 8; grid-column: 2; text-align: right; }
.gear > :not(.side) { grid-column: 1; }
.gear .price { font-family: var(--px); margin-bottom: 6px; }

.descend {
  display: block;
  width: 100%;
  margin-top: 18px;
  padding: 16px;
  font-size: 18px;
}

details { margin-top: 26px; color: var(--dim); }
details summary { cursor: pointer; font-family: var(--px); font-size: 12px; }
details ul { margin: 10px 0 0 18px; }
details li { margin-bottom: 4px; }

.link {
  border: none;
  background: none;
  color: var(--dim);
  padding: 0;
  margin-top: 20px;
  font-family: var(--mono);
  text-decoration: underline;
}
.link:hover:not(:disabled) { background: none; color: var(--ink); }

/* ---------- pack grid ---------- */

.pack-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-template-rows: repeat(var(--rows), var(--cell));
  gap: 2px;
  width: max-content;
}
.pack-grid .cell {
  border: 1px dotted var(--line);
  cursor: pointer;
}
.pack-grid .item {
  z-index: 1;
  border: 1px solid var(--ink);
  background: var(--dark);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
}
.pack-grid .item img {
  width: 78%;
  height: 78%;
  object-fit: contain;
  image-rendering: pixelated;
}
.pack-grid .item.sel { background: var(--ink); }
.pack-grid .item.sel img { filter: invert(1); }
.grid-wrap { overflow-x: auto; padding-bottom: 2px; display: flex; justify-content: center; }
#menu .info, #menu .meta { text-align: center; }
#menu .info .row, .row.center { justify-content: center; }

.info { margin-top: 8px; min-height: 20px; color: var(--dim); }
.info b { color: var(--ink); font-weight: 500; }

/* ---------- stage ---------- */

#stage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#frame { position: relative; }
#view { display: block; image-rendering: pixelated; touch-action: none; }

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  font-family: var(--px);
  font-size: 11px;
}
.hud-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.meters { display: grid; gap: 5px; }
.meter { display: flex; align-items: center; gap: 6px; text-shadow: 0 0 3px var(--dark); }
.meter .lbl { width: 18px; color: var(--dim); }
.bar { width: 70px; height: 7px; border: 1px solid var(--ink); background: var(--dark); }
.bar i { display: block; height: 100%; background: var(--ink); width: 0; }

.flag {
  background: var(--ink);
  color: var(--dark);
  padding: 4px 10px 6px 16px;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 8px 50%);
  font-size: 16px;
  text-align: right;
  line-height: 1.1;
}
.flag small { display: block; font-size: 9px; }

#hint {
  align-self: center;
  margin: auto 0 10px;
  text-align: center;
  max-width: 260px;
  font-size: 10px;
  line-height: 1.6;
  color: var(--ink);
  background: rgba(12, 11, 10, 0.75);
  padding: 6px 10px;
  transition: opacity 0.4s;
}
#hint:empty { opacity: 0; }

.hud-bottom { display: flex; justify-content: space-between; gap: 8px; }
.hud-bottom button { pointer-events: auto; font-size: 11px; padding: 8px 10px; }

.panel {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  background: var(--dark);
  border: 1px solid var(--ink);
  padding: 12px;
  z-index: 5;
  max-height: calc(100% - 16px);
  overflow-y: auto;
}
.panel-head { display: flex; align-items: center; gap: 10px; }
.panel-head .title { font-family: var(--px); font-size: 14px; }
.panel-head #ppWeight { flex: 1; color: var(--dim); font-size: 11px; }
.panel-head .x { padding: 2px 10px; font-size: 16px; }
.panel .warn { color: var(--dim); font-size: 11px; margin: 4px 0 10px; font-style: italic; }

#modal {
  top: 50%;
  bottom: auto;
  transform: translateY(-50%);
  text-align: center;
  padding: 22px 16px;
}
#modal h2 { font-family: var(--px); font-weight: 400; font-size: 22px; margin-bottom: 10px; }
#modal p { color: var(--dim); margin-bottom: 16px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--dark);
  font-family: var(--px);
  font-size: 11px;
  padding: 6px 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  z-index: 20;
}
#toast.show { opacity: 1; }

/* ---------- main menu / pause ---------- */

.title-screen {
  min-height: calc(100vh - 88px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 6px;
}
.logo { font-family: var(--px); font-weight: 400; font-size: 64px; line-height: 1; letter-spacing: 2px; }
.tag { color: var(--dim); max-width: 280px; }
.tag.dim, .dim { color: var(--dim); }
@keyframes bob { 50% { transform: translateY(5px); } }

.menu {
  display: grid;
  gap: 10px;
  width: 100%;
  max-width: 320px;
  margin: 26px auto 8px;
}
.menu button { padding: 13px 16px; font-size: 14px; }
.menu button.big { padding: 18px 16px; font-size: 20px; }
.menu button small { font-size: 10px; opacity: 0.7; }


.howto { margin: 16px 0 0 18px; color: var(--dim); display: grid; gap: 8px; text-align: left; }
.howto b { color: var(--ink); font-weight: 500; }

.opts { display: grid; gap: 8px; margin-top: 16px; }
.opt {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 14px;
  font-size: 13px;
}
.opt b { font-weight: 400; min-width: 34px; text-align: right; }
.danger { margin-top: 28px; }

.g-head h1 { margin-top: 0; }

#pause {
  top: 8px;
  background: rgba(12, 11, 10, 0.9);
  text-align: center;
  display: flex;
  flex-direction: column;
  padding: 24px 18px;
}
/* centre short views (paused, abandon) with auto margins: unlike
   justify-content: center, these fall back to top-aligned when the content
   is taller than the panel, so long pages like how to play scroll from the top */
#pause > :first-child { margin-top: auto; }
#pause > :last-child { margin-bottom: auto; }
#pause h2 { font-family: var(--px); font-weight: 400; font-size: 24px; margin-bottom: 6px; }
#pause .back { align-self: flex-start; }
#pause .menu { margin-top: 18px; }

#pauseBtn { padding: 8px 12px; letter-spacing: -2px; }

/* ---------- game-style menus ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--line);
}
.topbar h1 {
  flex: 1;
  font-family: var(--px);
  font-weight: 400;
  font-size: 18px;
  line-height: 1.2;
  margin: 0;
}
.back {
  border: 2px solid var(--ink);
  padding: 7px 12px;
  margin: 0;
  color: var(--ink);
  font-size: 12px;
  box-shadow: 3px 3px 0 var(--line);
}
.back:hover:not(:disabled) { background: var(--ink); color: var(--dark); }
.back:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--line); }
.chip {
  font-family: var(--px);
  font-size: 13px;
  padding: 5px 10px;
  background: var(--ink);
  color: var(--dark);
}

.menu button {
  position: relative;
  border-width: 2px;
  font-family: var(--px);
  text-transform: uppercase;
  letter-spacing: 1px;
  box-shadow: 4px 4px 0 var(--line);
}
.menu button::before {
  content: '▶';
  position: absolute;
  left: 14px;
  opacity: 0;
  transition: opacity 0.1s;
}
.menu button:hover:not(:disabled)::before,
.menu button:focus-visible::before { opacity: 1; }
.menu button:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--line); }

.g-sec h2 { display: flex; justify-content: space-between; align-items: baseline; }
.h2-note { font-family: var(--mono); font-size: 11px; }

.gear .side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.gear .side button { min-width: 72px; }
.gear.locked { border: 2px dashed var(--ink); }
.lock { font-size: 10px; padding: 5px 8px; color: var(--dim); border-color: var(--line); }
.lock.on { color: var(--dark); background: var(--ink); border-color: var(--ink); }

.howto { margin: 0; display: block; color: var(--dim); }
.howto h3 {
  font-family: var(--px);
  font-weight: 400;
  font-size: 12px;
  color: var(--ink);
  margin: 18px 0 6px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.howto h3:first-child { margin-top: 4px; }
.howto p { margin-bottom: 8px; }

.about p { color: var(--dim); margin-bottom: 12px; }
.about i { color: var(--ink); }
#pause .topbar { text-align: left; }
#pause .howto { text-align: left; }
