/* Three colours only: ink (black), paper (white), gold (accent).
   Everything else is paper at reduced opacity. */
@font-face { font-family: 'Pixelify Sans'; font-weight: 400; font-display: swap; src: url(fonts/pixelify-sans-latin-400-normal.woff2) format('woff2'); }
@font-face { font-family: 'Pixelify Sans'; font-weight: 700; font-display: swap; src: url(fonts/pixelify-sans-latin-700-normal.woff2) format('woff2'); }
:root {
  --ink: #000;
  --paper: #fff;
  --gold: #ffd21f;
  --dim: rgb(255 255 255 / 0.5);
  --faint: rgb(255 255 255 / 0.14);
  --font: 'Pixelify Sans', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --b: 3px; /* box border */
  --panel-w: 64px;
  --top-h: 44px;
  /* Pixel heart ("soul"), used as a mask so it takes currentColor. */
  --heart: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 9 8' shape-rendering='crispEdges'%3E%3Cpath d='M1 0h3v1h1V0h3v1h1v3H8v1H7v1H6v1H5v1H4V7H3V6H2V5H1V4H0V1h1z'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font);
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: none;
  touch-action: manipulation; /* no double-tap zoom */
}
button { font: inherit; color: inherit; letter-spacing: inherit; text-transform: inherit; cursor: pointer; }
button:focus-visible { outline: var(--b) solid var(--gold); outline-offset: 3px; }
[hidden] { display: none !important; }

/* Boxes are square, Undertale-style; .notch is kept as a hook but no longer clips. */
.notch { border-radius: 0; }


/* ---- layout ------------------------------------------------------------- */
#app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: var(--top-h) minmax(0, 1fr) auto;
  grid-template-areas:
    'top'
    'stage'
    'under';
  padding-bottom: env(safe-area-inset-bottom);
}
#topbar { grid-area: top; }
#stage  { grid-area: stage; }
#under  { grid-area: under; }

/* ---- top bar: reads like a battle HUD ----------------------------------- */
#topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  background: transparent;
  border-bottom: var(--b) solid transparent;
}
#title {
  flex: 0 1 34%;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-weight: 700;
  color: var(--paper);
}
#bar-wrap { flex: 1; display: flex; align-items: center; position: relative; }
#bar {
  flex: 1;
  height: 14px;
  background: var(--faint);
  position: relative;
}
#bar-fill {
  position: absolute; inset: 0 auto 0 0;
  width: 100%;
  background: var(--gold);
}
#bar-wrap.gain #bar-fill { transition: width 0.45s cubic-bezier(.2,.8,.2,1); background: var(--paper); animation: surge 0.7s steps(2) 1; }
@keyframes surge { 50% { background: var(--gold); } }
.bonus-chip {
  position: absolute; top: 100%; margin-top: 4px; transform: translateX(-50%);
  padding: 2px 6px; background: var(--gold); color: var(--ink);
  font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; pointer-events: none;
  animation: bonus-rise 1.1s ease-out forwards; z-index: 5;
}
@keyframes bonus-rise {
  0% { opacity: 0; transform: translate(-50%, -6px) scale(0.6); }
  20% { opacity: 1; transform: translate(-50%, 0) scale(1.15); }
  70% { opacity: 1; transform: translate(-50%, 4px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, 10px) scale(1); }
}
@media (prefers-reduced-motion: reduce) { .bonus-chip { animation-duration: 1.4s; } }
#app[data-low] #bar-fill { background: var(--paper); animation: blink 0.5s steps(2) infinite; }
#time { min-width: 4ch; text-align: right; color: var(--dim); font-variant-numeric: tabular-nums; }
#score { min-width: 3ch; text-align: right; color: var(--gold); font-weight: 700; font-size: 20px; font-variant-numeric: tabular-nums; }
#score.pop { animation: pop 0.2s steps(3); }
@keyframes pop { 50% { transform: translateY(-3px) scale(1.2); } }

/* ---- stage / play area -------------------------------------------------- */
#stage { display: flex; background: var(--ink); min-height: 0; }
/* left-edge gutter so an edge swipe doesn't trigger browser back */
#app[data-ui='touch'] #stage::before { content: ''; flex: 0 0 8px; }
#play {
  position: relative;
  flex: 1;
  min-width: 0;
  background: var(--ink);
  overflow: hidden;
  touch-action: none;
}
.game-frame {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  border: 0;
  background: var(--ink);
  z-index: 1;
  animation: enter 0.24s steps(6) both;
}
.game-frame.released { pointer-events: none; }
@keyframes enter { from { transform: translateY(var(--from, 100%)); } to { transform: none; } }

.overlay { position: absolute; inset: 0; z-index: 2; pointer-events: none; } /* above the game iframe */
.center { display: flex; align-items: center; justify-content: center; }
#loading { background: var(--ink); color: var(--dim); gap: 10px; flex-direction: column; }
#loading .lbar { flex: none; width: min(220px, 60%); height: 14px; margin-top: 6px; border: var(--b) solid var(--paper); padding: 2px; position: relative; overflow: hidden; }
#loading .lbar i { display: block; height: 100%; width: var(--p, 0%); background: var(--gold); transition: width .2s steps(6); }
/* unknown progress: a block sweeps back and forth */
#loading:not([data-p]) .lbar i { width: 30%; position: absolute; animation: sweep 1.1s steps(10) infinite alternate; }
@keyframes sweep { from { left: 2px; } to { left: calc(70% - 2px); } }
#loading::before {
  content: '';
  width: 18px; height: 16px;
  background: var(--gold);
  -webkit-mask: var(--heart) center / contain no-repeat;
  mask: var(--heart) center / contain no-repeat;
  animation: beat 0.9s steps(2) infinite;
}
@keyframes beat { 50% { transform: scale(0.75); } }
#loading span::after { content: ''; animation: dots 0.9s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
#app:not([data-state='loading']) #loading { display: none; }

/* ---- cards: the classic white-bordered dialogue box ---------------------- */
.card {
  background: var(--ink);
  border: var(--b) solid var(--paper);
  padding: 22px 24px;
  text-align: center;
  max-width: min(320px, 86%);
}
.card.bad { border-color: var(--paper); }
.card-title { font-size: 22px; font-weight: 700; color: var(--paper); margin-bottom: 16px; }
.card.bad .card-title { color: var(--gold); }
.card-label { color: var(--dim); }
.card-score { font-size: 44px; font-weight: 700; color: var(--gold); margin: 4px 0 14px; line-height: 1; }
.card-msg { margin-bottom: 16px; line-height: 1.6; text-align: left; text-transform: none; }
.card-msg::before { content: '* '; }
.card-cue { color: var(--gold); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.2; } }

#gameover { background: rgb(0 0 0 / 0.6); }
#gameover[data-phase='hidden'] { display: none; }
#gameover[data-phase='card'] .card { animation: card-in 0.24s steps(4) both; }
@keyframes card-in { from { transform: scaleY(0.1); opacity: 0; } }
#gameover .card { pointer-events: auto; width: min(320px, 90%); }
.go-score { display: flex; align-items: baseline; justify-content: center; gap: 12px; margin-bottom: 16px; }
.go-score .card-score { margin: 0; }
.info {
  margin: 0 0 18px; padding-top: 14px;
  border-top: 2px dashed var(--faint);
  display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; text-align: left;
}
.info dt { color: var(--dim); }
.info dd a { color: inherit; }
.info dd { margin: 0; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.info dd:has(.badges, .icons) { overflow: visible; white-space: normal; display: flex; justify-content: flex-end; align-items: center; }
.badges { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.badge { padding: 2px 6px; border: 2px solid var(--faint); color: var(--dim); font-size: 0.8em; text-transform: uppercase; white-space: nowrap; }
.icons { display: inline-flex; align-items: center; gap: 8px; }
.icons > span:not(.ico) { margin-left: -2px; }
.ico { display: inline-flex; position: relative; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.card-actions { display: flex; gap: 12px; }
.card-actions .btn { flex: 1; }
@media (max-height: 480px) {
  #gameover .card { padding: 12px 18px; }
  .card-title { font-size: 16px; margin-bottom: 8px; }
  .go-score { margin-bottom: 8px; }
  .info { gap: 4px 12px; margin-bottom: 10px; padding-top: 8px; font-size: 11px; }
}

/* ---- under the play area: pad strip (touch) / key hint (desktop) -------- */
#under { display: none; background: transparent; min-width: 0; border-top: var(--b) solid transparent; }
#hint { display: none; }
#app[data-ui='desktop']:is([data-controls='gestures'], [data-controls='pad']) #under { display: block; }
#app[data-ui='desktop'] #hint { display: flex; }

#hint {
  gap: 20px;
  justify-content: center;
  flex-wrap: wrap;
  padding: 12px 10px;
  color: var(--dim);
  font-size: 11px;
}
.hint b { color: var(--paper); padding: 2px 6px; border: 2px solid var(--paper); margin-right: 6px; }

/* ---- floating joystick overlay (pad games, touch + mouse) -------------- */
#joy { display: none; position: absolute; inset: 0; z-index: 2; pointer-events: none; touch-action: none; user-select: none; -webkit-user-select: none; }
#app[data-controls='pad']:not([data-state='loading'], [data-state='error']) #joy { display: block; }
/* bottom third only: taps higher up reach the game frame, which keeps its audio unlocked */
.fj-zone { position: absolute; left: 0; top: 66.6%; bottom: 0; width: 58%; pointer-events: auto; touch-action: none; cursor: grab; }
.fj-base {
  position: absolute; left: 80px; bottom: 88px; width: 112px; height: 112px; margin: -56px 0 0 -56px;
  border-radius: 50%; border: var(--b) solid var(--paper); background: rgb(0 0 0 / 0.35);
  opacity: .4; pointer-events: none; transition: opacity .12s;
}
#joy.active .fj-base { opacity: 1; }
/* the knob is the player's soul */
.fj-knob {
  position: absolute; left: 50%; top: 50%; width: 40px; height: 36px; margin: -18px 0 0 -20px;
  background: var(--gold);
  -webkit-mask: var(--heart) center / contain no-repeat;
  mask: var(--heart) center / contain no-repeat;
}
.pad-btns { position: absolute; inset: 0; pointer-events: none; }
.pad-btn {
  position: absolute; pointer-events: auto; width: 64px; height: 64px; border-radius: 50%; opacity: .85;
  border: var(--b) solid var(--gold); background: rgb(0 0 0 / 0.45);
  color: var(--gold); font-weight: 700; font-size: 20px; font-family: inherit;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.pad-btn.alt { border-color: var(--paper); color: var(--paper); }
.pad-btn.long { font-size: 11px; letter-spacing: -.02em; }
.pad-btn.held { opacity: 1; background: var(--gold); color: var(--ink); transform: scale(0.94); }
.pad-btn.alt.held { background: var(--paper); }
/* a controller is plugged in: the touch pad is only a fallback, so fade it right back */
/* touch pad held back until the first tap lands in the game frame (unlocks audio on iOS) */
.fj-tap { display: none; position: absolute; left: 0; right: 0; top: 38%; text-align: center; color: var(--paper); font-weight: 700; letter-spacing: .12em; pointer-events: none; animation: blink 1s steps(2) infinite; }
#joy.locked .fj-tap { display: block; }
#joy.locked .fj-zone, #joy.locked .fj-base, #joy.locked .pad-btns { display: none; }
#play:has(#intro:not([hidden])) .fj-tap { display: none; }
#joy.gp .fj-base { opacity: .15; }
#joy.gp.active .fj-base { opacity: .7; }
#joy.gp .pad-btn { opacity: .22; background: rgb(0 0 0 / 0.15); }
#joy.gp .pad-btn.held { opacity: .8; }

/* ---- side panel --------------------------------------------------------- */
#panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: var(--panel-w);
  z-index: 8;
  transform: translateX(100%);
  transition: transform 0.16s steps(4);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 14px 0 12px;
  background: var(--ink);
  border-left: var(--b) solid var(--paper);
  touch-action: none;
}
/* the menu stays out of the way while playing; the edge tab (or game over) brings it in */
#app[data-panel='open'] #panel { transform: none; }
#panel-tab {
  position: fixed; right: 0; top: calc(var(--top-h) + 10px); z-index: 9;
  width: 22px; height: 52px; padding: 0;
  display: grid; place-items: center;
  background: var(--ink); color: var(--paper);
  border: var(--b) solid var(--paper); border-right: 0;
  opacity: 0.4;
  transition: right 0.16s steps(4);
}
#panel-tab:hover, #panel-tab:focus-visible { opacity: 1; color: var(--gold); border-color: var(--gold); }
#app[data-panel='open'] #panel-tab { right: var(--panel-w); opacity: 1; }
#app[data-panel='open'] #panel-tab .px-icon { transform: scaleX(-1); }
#app[data-state='loading'] #panel-tab { display: none; }
/* skip/next: overlaid on the game directly under the menu tab; hidden while the menu is open (it has its own NEXT) */
#skip-tab {
  position: fixed; right: 0; top: calc(var(--top-h) + 10px + 52px + 8px); z-index: 9;
  width: 22px; height: 52px; padding: 0;
  display: grid; place-items: center;
  background: var(--gold); color: var(--ink);
  border: var(--b) solid var(--gold); border-right: 0;
  opacity: 0.7;
  transition: right 0.16s steps(4);
}
#skip-tab:hover, #skip-tab:focus-visible, #skip-tab:active { opacity: 1; }
#app[data-panel='open'] #skip-tab { display: none; }
#app[data-state='loading'] #skip-tab { display: none; }
.pbtn {
  position: relative;
  width: 46px; height: 46px;
  border: var(--b) solid var(--paper);
  padding: 0;
  display: grid; place-items: center;
  background: var(--ink);
  color: var(--paper);
}
.pbtn:hover { border-color: var(--gold); color: var(--gold); }
.pbtn:active { background: var(--gold); border-color: var(--gold); color: var(--ink); }
.pbtn.on[data-act='like'],
.pbtn.on[data-act='save'] { color: var(--gold); border-color: var(--gold); }
.pbtn.spacer { margin-top: auto; }
#panel .pbtn[data-act='next'] { background: var(--gold); border-color: var(--gold); color: var(--ink); }

.avatar {
  position: relative;
  width: 46px; height: 46px;
  border: var(--b) solid var(--paper); padding: 0;
  display: grid; place-items: center;
  color: var(--paper);
  overflow: hidden;
  background: var(--ink); /* creator colour (--c) intentionally ignored: 3-colour palette */
}
.avatar img { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: cover; background: var(--ink); }
.avatar-wrap { position: relative; margin-bottom: 8px; }
.follow {
  position: absolute; left: 50%; bottom: -10px; margin-left: -10px;
  width: 20px; height: 20px;
  border: 0; padding: 0;
  display: grid; place-items: center;
  background: var(--gold);
  color: var(--ink);
  box-shadow: 0 0 0 3px var(--ink);
}
.follow.on { background: var(--paper); }
.px-icon { display: block; }

/* ---- shared buttons: menu options with a soul cursor -------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: var(--b) solid var(--paper);
  padding: 10px 14px;
  min-height: 44px;
  background: var(--ink);
  color: var(--paper);
}
.btn::before {
  content: '';
  width: 0; height: 14px;
  background: currentColor;
  -webkit-mask: var(--heart) center / contain no-repeat;
  mask: var(--heart) center / contain no-repeat;
  transition: width 0.08s steps(2);
}
.btn:hover, .btn:focus-visible, .btn.primary { border-color: var(--gold); color: var(--gold); }
.btn:hover::before, .btn:focus-visible::before { width: 16px; }
.btn.primary { font-weight: 700; }
.btn:active { background: var(--gold); color: var(--ink); }

#sheet {
  position: fixed; inset: 0;
  z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: rgb(0 0 0 / 0.85);
}
#sheet-card { width: min(340px, 90vw); text-align: left; }
#sheet-card .card-title { text-align: center; }
#sheet-info { margin-bottom: 18px; }
.sheet-actions { display: flex; gap: 12px; }
.sheet-actions .btn { flex: 1; }

#toast {
  position: fixed;
  top: calc(var(--top-h) + 14px);
  left: calc((100vw - var(--panel-w)) / 2);
  transform: translateX(-50%);
  z-index: 20;
  padding: 10px 16px;
  background: var(--ink);
  border: var(--b) solid var(--paper);
  color: var(--paper);
  font-weight: 700;
  pointer-events: none;
  opacity: 0;
  white-space: nowrap;
}
#toast::before { content: '* '; color: var(--gold); }
#toast.show { opacity: 1; animation: toast 0.2s steps(3); }
@keyframes toast { from { transform: translate(-50%, -12px); } }


/* ---- narrow / short screens --------------------------------------------- */
@media (max-height: 560px) {
  #panel { gap: 6px; padding-top: 8px; }
  .pbtn, .avatar { width: 40px; height: 40px; }
}
@media (min-width: 900px) {
  :root { --top-h: 52px; --panel-w: 80px; font-size: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ?debug -> live readout of what the pad is sending */
#joy-debug { position: absolute; left: 8px; top: 8px; z-index: 6; padding: 4px 6px; background: rgb(0 0 0 / 0.7); color: var(--gold); font-size: 10px; pointer-events: none; }

.sheet-links { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; margin: 12px 0 4px; font-size: 13px; letter-spacing: .06em; }
.sheet-links a { color: var(--dim); text-decoration: none; }
.sheet-links a:hover { color: var(--paper); }

.pbtn.make { text-decoration: none; }
#panel .pbtn[data-act='make'] { font-weight: 700; font-size: 11px; line-height: 1.05; letter-spacing: 0; text-align: center; border-color: var(--gold); color: var(--gold); }
#panel .pbtn[data-act='make']:hover { background: var(--gold); color: var(--ink); }

/* game over: keep the card clear of the menu that slides out beside it */
#app[data-panel='open'] #gameover { right: var(--panel-w); }
#toast { left: 50vw; }

/* ---- intro card (author-written, optional) ------------------------------ */
#intro { background: rgb(0 0 0 / 0.72); }
#intro .card { pointer-events: auto; width: min(340px, 90%); animation: card-in 0.24s steps(4) both; }
#intro .card-msg { white-space: pre-line; }
#intro .card-msg::before { content: none; }

/* ---- welcome (first landing) --------------------------------------------- */
#welcome {
  position: fixed; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background: var(--ink);
  padding: 16px;
  overflow-y: auto;
}
#welcome[hidden], #welcome.gone { display: none; }
#welcome-card { width: min(380px, 100%); margin: auto; animation: card-in 0.24s steps(4) both; }
.welcome-logo {
  width: 54px; height: 48px; margin: 0 auto 14px; background: var(--gold);
  -webkit-mask: var(--heart) center / contain no-repeat; mask: var(--heart) center / contain no-repeat;
  animation: beat 0.9s steps(2) infinite;
}
#welcome .card-title { font-size: 32px; margin-bottom: 12px; color: var(--gold); }
.welcome-msg { margin: 0 0 12px; line-height: 1.5; text-transform: none; font-size: 1.1em; }
.welcome-pad { display: flex; justify-content: center; color: var(--gold); margin: 6px 0 8px; }
.welcome-msg.dim { color: var(--dim); font-size: 1em; }
.welcome-actions { display: flex; flex-direction: column; gap: 12px; margin: 18px 0 6px; }
.welcome-actions .btn { text-decoration: none; }
.welcome-actions .btn:disabled { opacity: 0.5; }

/* gamepad cursor for touch-scheme games (a stick-driven virtual mouse) */
#gp-cursor { position: absolute; left: 0; top: 0; z-index: 5; width: 18px; height: 18px; margin: -9px 0 0 -9px; border: 2px solid var(--gold, #ffd93d); border-radius: 50%; background: rgb(0 0 0 / 0.35); box-shadow: 0 0 0 1px rgb(0 0 0 / 0.6); pointer-events: none; }
#gp-cursor.down { background: var(--gold, #ffd93d); transform-origin: center; }
#gp-cursor[hidden] { display: none; }
