:root {
  --k: #1a1c2c; --plum: #5d275d; --red: #b13e53; --orange: #ef7d57;
  --gold: #ffcd75; --lime: #a7f070; --green: #38b764; --teal: #257179;
  --navy: #29366f; --royal: #3b5dc9; --blue: #41a6f6; --cyan: #73eff7;
  --white: #f4f4f4; --fog: #94b0c2; --steel: #566c86; --slate: #333c57;
  --head: 'Press Start 2P', 'Courier New', monospace;
  --body: 'VT323', 'Courier New', monospace;
  /* stepped corners: every box is cut on the 4px grid, never rounded */
  --notch: polygon(0 4px, 4px 4px, 4px 0, calc(100% - 4px) 0, calc(100% - 4px) 4px, 100% 4px,
    100% calc(100% - 4px), calc(100% - 4px) calc(100% - 4px), calc(100% - 4px) 100%,
    4px 100%, 4px calc(100% - 4px), 0 calc(100% - 4px));
}

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

html, body { height: 100%; }

body {
  background-color: var(--k);
  /* 2-colour dither, drawn on the 4px grid */
  background-image:
    linear-gradient(45deg, #20233a 25%, transparent 25%, transparent 75%, #20233a 75%),
    linear-gradient(45deg, #20233a 25%, transparent 25%, transparent 75%, #20233a 75%);
  background-size: 8px 8px;
  background-position: 0 0, 4px 4px;
  color: var(--white);
  font-family: var(--body);
  font-size: 22px;
  line-height: 1;
  -webkit-font-smoothing: none;
  font-smooth: never;
  text-rendering: optimizeSpeed;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

canvas, .px-img { image-rendering: pixelated; image-rendering: crisp-edges; display: block; }

.app {
  width: 100%;
  max-width: 480px;
  min-height: 100%;
  margin: 0 auto;
  padding: 16px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------- header ---------- */
.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
#logo canvas { width: 192px; height: 27px; }
.sub { margin-top: 8px; font-family: var(--head); font-size: 8px; color: var(--fog); display: flex; gap: 8px; align-items: center; }
.tag { background: var(--navy); color: var(--cyan); padding: 4px 6px; }
.tag.d-hard { background: var(--plum); color: var(--gold); }
.tag.d-brutal { background: var(--red); color: var(--white); }
.nav { display: flex; gap: 8px; }

/* ---------- buttons ---------- */
.btn {
  font-family: var(--head);
  font-size: 12px;
  color: var(--k);
  background: var(--gold);
  border: 0;
  padding: 14px 18px 16px;
  clip-path: var(--notch);
  box-shadow: inset 0 -4px 0 var(--orange), inset 0 4px 0 #fff2c9;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active, .btn.down { padding: 16px 18px 14px; box-shadow: inset 0 4px 0 var(--orange); }
.btn:focus-visible { outline: 4px solid var(--cyan); outline-offset: 0; clip-path: none; }
.btn.alt { background: var(--blue); box-shadow: inset 0 -4px 0 var(--royal), inset 0 4px 0 var(--cyan); }
.btn.alt:active { box-shadow: inset 0 4px 0 var(--royal); }
.btn.ghost { background: var(--slate); color: var(--fog); box-shadow: inset 0 -4px 0 #262b44, inset 0 4px 0 var(--steel); }
.btn.ghost:active { box-shadow: inset 0 4px 0 #262b44; }
.btn.ghost.off { color: var(--steel); text-decoration: line-through; }
.btn.small { font-size: 8px; padding: 10px 10px 12px; }
.btn.small:active { padding: 12px 10px 10px; }

/* ---------- hud ---------- */
.hud {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1.6fr;
  background: var(--k);
  border: 4px solid var(--slate);
  clip-path: var(--notch);
}
.hud .cell { padding: 8px 4px 8px 10px; display: flex; flex-direction: column; gap: 8px; border-left: 4px solid var(--slate); min-width: 0; }
.hud .cell:first-child { border-left: 0; }
.k { font-family: var(--head); font-size: 8px; color: var(--steel); }
.v { font-family: var(--head); font-size: 16px; color: var(--white); height: 16px; display: flex; gap: 2px; align-items: center; }
.v.gold { color: var(--gold); }
.v.over { color: var(--orange); }

/* ---------- board ---------- */
.stage { display: flex; justify-content: center; touch-action: none; }
#board { touch-action: none; cursor: pointer; }

.msg { font-family: var(--head); font-size: 8px; line-height: 1.6; text-align: center; color: var(--fog); min-height: 14px; }
.msg.warn { color: var(--orange); animation: blink 0.5s steps(1) 3; }
.msg.good { color: var(--lime); }
@keyframes blink { 50% { visibility: hidden; } }

.actions { display: flex; justify-content: center; gap: 12px; min-height: 48px; }
.actions .btn { min-width: 132px; }

.foot { margin-top: auto; padding-top: 6px; text-align: center; font-family: var(--head); font-size: 8px; color: var(--steel); }
.foot span { color: var(--fog); }

/* ---------- modal ---------- */
.veil {
  position: fixed; inset: 0; z-index: 10;
  background-color: rgba(26, 28, 44, 0.86);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.veil[hidden] { display: none; }
.modal {
  width: 100%; max-width: 400px; max-height: 100%;
  overflow-y: auto;
  background: var(--slate);
  border: 4px solid var(--k);
  outline: 4px solid var(--fog);
  outline-offset: -8px;
  padding: 26px 22px 22px;
  clip-path: var(--notch);
  animation: drop 0.18s steps(3);
}
@keyframes drop { from { transform: translateY(-24px); } to { transform: none; } }
.modal h2 { font-family: var(--head); font-size: 16px; line-height: 1.4; color: var(--gold); text-align: center; text-shadow: 2px 2px 0 var(--k); margin-bottom: 16px; }
.modal h2.big { font-size: 20px; color: var(--lime); }
.modal p { font-size: 22px; line-height: 1.05; color: var(--white); }
.modal .dim { color: var(--fog); }
.modal .row { display: flex; justify-content: center; gap: 12px; margin-top: 20px; flex-wrap: wrap; }

.rules { list-style: none; display: grid; gap: 12px; }
.rules li { display: grid; grid-template-columns: 40px 1fr; gap: 12px; align-items: center; font-size: 22px; line-height: 1.05; }
.rules .pic { width: 40px; height: 40px; background: var(--navy); border: 4px solid var(--k); display: flex; align-items: center; justify-content: center; font-family: var(--head); font-size: 12px; color: var(--cyan); }
.note { margin-top: 16px; padding-top: 14px; border-top: 4px dotted var(--steel); }

.stars { display: flex; justify-content: center; gap: 8px; margin-bottom: 16px; }
.modal p.line { font-family: var(--head); font-size: 8px; line-height: 2.2; text-align: center; color: var(--fog); }
.modal p.line b { color: var(--gold); font-weight: normal; }
.pips { display: flex; justify-content: center; flex-wrap: wrap; gap: 4px; margin: 14px 0; }
.pips i { width: 12px; height: 12px; background: var(--blue); box-shadow: inset -4px -4px 0 var(--royal); }
.pips i.over { background: var(--orange); box-shadow: inset -4px -4px 0 var(--red); }

.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 18px; }
.grid3 div { background: var(--k); padding: 10px 4px; text-align: center; clip-path: var(--notch); }
.grid3 b { display: block; font-family: var(--head); font-size: 16px; font-weight: normal; color: var(--white); margin-bottom: 8px; }
.grid3 span { font-family: var(--head); font-size: 6px; color: var(--fog); }
.hist { display: grid; gap: 6px; }
.hist .bar { display: grid; grid-template-columns: 44px 1fr; gap: 8px; align-items: center; font-family: var(--head); font-size: 8px; color: var(--fog); }
.hist .fill { height: 16px; min-width: 20px; background: var(--steel); color: var(--k); display: flex; align-items: center; justify-content: flex-end; padding-right: 4px; }
.hist .fill.me { background: var(--lime); }

@media (max-width: 460px) {
  .nav { display: grid; grid-template-columns: auto auto; gap: 6px; }
}
@media (max-width: 380px) {
  .app { padding: 12px 10px; gap: 10px; }
  #logo canvas { width: 128px; height: 18px; }
  .btn.small { padding: 10px 8px 12px; }
  .v { font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .modal, .msg.warn { animation: none; }
}

/* ---------- in-game panels: friends, reminders, install ---------- */
.field {
  width: 100%; font-family: var(--body); font-size: 24px; color: var(--white);
  background: var(--k); border: 4px solid var(--steel); padding: 6px 10px; outline: 0;
  user-select: text; -webkit-user-select: text;
}
.field:focus { border-color: var(--cyan); }
.modal .field { margin: 8px 0 4px; }
.promo { margin-top: 18px; padding: 14px; background: var(--k); clip-path: var(--notch); text-align: center; }
.promo .k { display: block; margin-bottom: 10px; color: var(--gold); line-height: 1.6; }
.promo p { font-size: 20px; margin-bottom: 10px; color: var(--fog); }
.promo .row { margin-top: 6px; }
.grp { margin-bottom: 16px; }
.grp h3 { font-family: var(--head); font-size: 10px; color: var(--cyan); margin-bottom: 8px; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.lb { list-style: none; display: grid; gap: 4px; }
.lb li { display: grid; grid-template-columns: 24px 1fr auto auto; gap: 8px; align-items: center; background: var(--k); padding: 6px 8px; font-size: 22px; }
.lb li.me { box-shadow: inset 4px 0 0 var(--lime); }
.lb .pos { font-family: var(--head); font-size: 8px; color: var(--steel); }
.lb .mv { font-family: var(--head); font-size: 10px; color: var(--white); }
.lb .mv.par { color: var(--gold); }
.lb .tr { font-size: 18px; color: var(--steel); }
.lb .empty { grid-template-columns: 1fr; color: var(--steel); }
.btn.tiny { font-size: 6px; padding: 7px 8px 9px; }
.btn.tiny:active { padding: 9px 8px 7px; }
.modal .msgline { font-family: var(--head); font-size: 8px; line-height: 1.8; text-align: center; color: var(--fog); margin-top: 10px; min-height: 14px; }
.modal .msgline.warn { color: var(--orange); }
.foot nav { display: flex; justify-content: center; gap: 14px; margin-top: 10px; }
.foot nav a { color: var(--steel); text-decoration: none; }
.foot nav a:hover, .foot nav a:focus-visible { color: var(--cyan); }

/* ---------- content pages (how to play, archive, puzzle pages) ---------- */
body.doc { user-select: auto; -webkit-user-select: auto; }
.page { max-width: 640px; margin: 0 auto; padding: 16px 16px 32px; }
.pagehead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 28px; gap: 12px; }
.pagehead img { width: 192px; height: 27px; }
.page h1 { font-family: var(--head); font-size: 20px; line-height: 1.4; color: var(--gold); text-shadow: 3px 3px 0 var(--navy); margin-bottom: 12px; }
.page h2 { font-family: var(--head); font-size: 12px; color: var(--cyan); margin: 30px 0 14px; }
.page p, .page li, .page dd, .page td { font-size: 24px; line-height: 1.1; }
.page p { margin-bottom: 14px; }
.page a { color: var(--cyan); }
.page a.btn { color: var(--k); text-decoration: none; display: inline-block; }
.page b { color: var(--white); font-weight: normal; text-decoration: underline 2px var(--steel); text-underline-offset: 4px; }
.page .dim, .doc .dim { color: var(--fog); }
.kicker { font-family: var(--head); font-size: 9px !important; line-height: 1.8 !important; color: var(--fog); }
.lvl { color: var(--cyan); }
.lvl.l-hard { color: var(--gold); }
.lvl.l-brutal { color: var(--orange); }
.boardimg { width: 100%; max-width: 540px; height: auto; margin: 6px auto 14px; display: block; }
.cta { text-align: center; margin: 18px 0 !important; }
.rules.big li { grid-template-columns: 48px 1fr; gap: 14px; margin-bottom: 6px; }
.rules.big img { width: 48px; height: 48px; }
.week { width: 100%; border-collapse: collapse; }
.week th { font-family: var(--head); font-size: 9px; color: var(--gold); text-align: left; padding: 8px 12px 8px 0; vertical-align: top; width: 56px; }
.week td { padding: 6px 0; border-bottom: 2px dotted var(--slate); }
.faq dt { font-family: var(--head); font-size: 10px; line-height: 1.6; color: var(--white); margin-top: 18px; }
.faq dd { color: var(--fog); margin-top: 6px; }
.steps { padding-left: 28px; }
.steps li { margin-bottom: 8px; }
.hookform { margin: 20px 0; display: grid; gap: 10px; }
.hookform .btn { justify-self: start; }
.formout { font-family: var(--head); font-size: 8px !important; line-height: 1.8 !important; min-height: 14px; color: var(--fog); }
.formout.good { color: var(--lime); }
.formout.warn { color: var(--orange); }
.spoiler { margin: 20px 0; background: var(--slate); padding: 0; clip-path: var(--notch); }
.spoiler summary { font-family: var(--head); font-size: 10px; padding: 16px; cursor: pointer; color: var(--gold); list-style: none; }
.spoiler summary::-webkit-details-marker { display: none; }
.spoiler summary::before { content: '+ '; }
.spoiler[open] summary::before { content: '- '; }
.spoiler > p, .spoiler > ol { padding: 0 16px; }
.route { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 16px !important; counter-reset: mv; }
.route li { counter-increment: mv; display: flex; align-items: center; gap: 8px; background: var(--k); padding: 8px 10px; font-family: var(--head); font-size: 8px !important; }
.route li::before { content: counter(mv); color: var(--steel); }
.arr { width: 21px; height: 21px; fill: var(--cyan); display: block; }
.arr.r1 { transform: rotate(90deg); } .arr.r2 { transform: rotate(180deg); } .arr.r3 { transform: rotate(270deg); }
.pager { display: flex; justify-content: space-between; font-family: var(--head); font-size: 9px; margin-top: 24px; }
.daylist { list-style: none; display: grid; gap: 6px; }
.daylist a { display: grid; grid-template-columns: 56px 1fr 72px 64px; gap: 8px; align-items: center; padding: 10px 12px; background: var(--slate); color: var(--white); text-decoration: none; font-family: var(--head); font-size: 8px; }
.daylist a:hover, .daylist a:focus-visible { background: var(--navy); }
.daylist b { color: var(--gold); font-weight: normal; text-decoration: none; }
.sitefoot { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; margin-top: 40px; padding-top: 18px; border-top: 4px dotted var(--slate); font-family: var(--head); font-size: 8px; }
.sitefoot a { color: var(--steel); text-decoration: none; }
.sitefoot a:hover { color: var(--cyan); }
@media (max-width: 420px) {
  .daylist a { grid-template-columns: 44px 1fr 60px; }
  .daylist a span:last-child { display: none; }
  .page h1 { font-size: 16px; }
}

/* ---------- quick links under the board ---------- */
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.quick .btn { font-size: 10px; text-decoration: none; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 14px 10px 16px; color: var(--white); }
.quick .btn:active { padding: 16px 10px 14px; }
.qi { width: 14px; height: 14px; flex: none; background: var(--gold);
  -webkit-mask: var(--m) center / contain no-repeat; mask: var(--m) center / contain no-repeat; image-rendering: pixelated; }
.qi-help { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 7 7' shape-rendering='crispEdges'%3E%3Cpath d='M1 0h5v1h1v2h-1v1h-2v1h-2v-2h2v-1h1v-1h-3v1h-2v-1h1zM2 6h2v1h-2z'/%3E%3C/svg%3E"); }
.qi-arch { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 7 7' shape-rendering='crispEdges'%3E%3Cpath d='M0 0h7v2h-7zM1 3h5v4h-5zM2 4v1h3v-1z' fill-rule='evenodd'/%3E%3C/svg%3E"); background: var(--cyan); }
.modal .row a.btn { text-decoration: none; display: inline-block; }
@media (max-width: 380px) { .quick .btn { font-size: 8px; gap: 6px; } }
