/* Momo Run: shared page styles. All text uses Silkscreen. */
:root {
  --bg: #f6efe4; --ink: #5a4a3e; --soft: #8a7a6c; --line: #e6dccd; --accent: #e2574c; --pink: #d6457f;
  --font: 'Silkscreen', ui-monospace, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #2d3566; --ink: #d9d6f0; --soft: #9da2cc; --line: #3d4678; --accent: #ff8f8f; --pink: #ff8fc3; }
}
:root[data-theme="dark"] { --bg: #2d3566; --ink: #d9d6f0; --soft: #9da2cc; --line: #3d4678; --accent: #ff8f8f; --pink: #ff8fc3; }
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 400 14px/1.6 var(--font);
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}
a { color: var(--ink); text-decoration-thickness: 2px; text-underline-offset: 3px; }
a:hover { color: var(--accent); }
button {
  font: inherit; color: var(--ink); background: var(--line);
  border: 0; border-radius: 8px; padding: 8px 14px; cursor: pointer;
}
button:disabled { opacity: .45; cursor: default; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- the game page: icons on top, game in the middle, links at the bottom ---------- */
body.play {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}
/* the bar at the top of the screen: sound top left, best and score in the middle, pause top right */
.top {
  width: 100%;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
}
.side { display: flex; gap: 8px; }
.side.right { justify-content: flex-end; }
.mid { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center; }
.score { display: flex; gap: 18px; justify-content: center; font-size: 12px; color: var(--soft); white-space: nowrap; }
.donate {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  color: var(--pink); font-size: 12px; font-weight: 700;
  text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px;
}
.donate:hover { color: var(--pink); filter: brightness(1.12); }
.donate svg { width: 14px; height: 14px; display: block; }
.score b { color: var(--ink); font-weight: 700; }
.score.flash #score { visibility: hidden; }
.icon {
  width: 44px; height: 44px; padding: 10px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon svg { width: 24px; height: 24px; display: block; }
#mute .when-off, #mute.off .when-on { display: none; }
#mute.off .when-off { display: block; }
#pause .when-paused, #pause.paused .when-run { display: none; }
#pause.paused .when-paused { display: block; }
.game {
  flex: 1; width: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: 8px 0;
}
.bottom { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 8px; }
/* footer row: About / Privacy / Terms / version, centered */
.foot { width: 100%; display: flex; justify-content: center; align-items: center; gap: 8px 16px; flex-wrap: wrap; }
.foot .links { width: auto; max-width: none; justify-content: center; }
.bottom .keys { margin: 0; font-size: 11px; color: var(--soft); text-align: center; }
#stage {
  width: 100%; max-width: 900px; cursor: pointer;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
canvas { display: block; width: 100%; border-radius: 10px; }

/* big touch buttons, only on touch screens */
.pad { width: 100%; max-width: 900px; display: none; gap: 12px; }
.pad button {
  flex: 1; padding: 18px 12px; font-size: 16px; font-weight: 700; border-radius: 14px;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
.pad button:active, .pad button.on { background: var(--ink); color: var(--bg); }
@media (pointer: coarse) {
  .pad { display: flex; }
  .keys { display: none; }
}

.links {
  width: 100%; max-width: 900px; margin: 0; padding: 0; list-style: none;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 18px; font-size: 11px; color: var(--soft);
}
.links a { color: var(--soft); }

/* phones held upright: the game grows tall (more sky) and fills the screen, ground near the thumbs */
@media (orientation: portrait) {
  .game { justify-content: flex-start; gap: 16px; padding: 4px 0 12px; }
  #stage { flex: 1; position: relative; min-height: 180px; }
  #stage canvas { position: absolute; left: 0; bottom: 0; }
  .pad button { padding: 24px 12px; font-size: 18px; }
  .bottom { gap: 12px; padding-top: 4px; }
}

/* short landscape phones: keep everything on one screen */
@media (max-height: 460px) and (orientation: landscape) {
  .game { gap: 8px; padding: 0; }
  #stage, .pad { max-width: min(900px, 150vh); }
  #stage, .pad { max-width: min(900px, 150vh); }
  .icon { width: 38px; height: 38px; padding: 8px; }
  .pad button { padding: 10px; }
}

/* ---------- Ko-fi donation popup ---------- */
dialog.kofi {
  width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  padding: 0; border: 0; border-radius: 16px; background: var(--bg); color: var(--ink);
  display: none; flex-direction: column; overflow: hidden;
}
dialog.kofi[open] { display: flex; }
dialog.kofi::backdrop { background: rgba(20, 18, 30, .6); }
.kofi-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 10px 6px 16px; }
.kofi-title { margin: 0; font-weight: 700; font-size: 14px; color: var(--pink); }
.kofi-body { flex: 1; min-height: 0; overflow: auto; padding: 0 8px; }
.kofi-body iframe { display: block; width: 100%; height: 640px; max-height: calc(100dvh - 130px); border: 0; border-radius: 10px; background: #fff; }
.kofi-offline { margin: 12px 8px; font-size: 13px; }
.kofi-foot { margin: 0; padding: 8px 16px 12px; text-align: center; font-size: 11px; }
.kofi-foot a { color: var(--soft); }

/* ---------- text pages: about, privacy, terms ---------- */
.page {
  max-width: 640px; margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(32px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}
.page header { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.page header img { width: 48px; height: 48px; image-rendering: pixelated; }
.page h1 { font-size: 24px; line-height: 1.2; margin: 0; font-weight: 700; }
.page h2 { font-size: 15px; margin: 28px 0 6px; font-weight: 700; }
.page p, .page li { font-size: 13px; }
.page ul { padding-left: 20px; }
.page .back { display: inline-block; margin-top: 28px; }
.page .updated { color: var(--soft); font-size: 11px; }
.page .version h2 { margin-bottom: 0; }
.page .version .updated { margin: 2px 0 6px; }

/* ---------- embedded (embed.html in someone else's page): compact, fills the frame ---------- */
body.embed { padding: 8px; }
body.embed .game { gap: 8px; padding: 6px 0; }
body.embed #stage { flex: 1; position: relative; min-height: 90px; max-width: none; }
body.embed #stage canvas { position: absolute; left: 0; bottom: 0; }
body.embed .icon { width: 36px; height: 36px; padding: 7px; }
body.embed .score { font-size: 11px; }
body.embed .pad { max-width: none; }
body.embed .pad button { padding: 12px; font-size: 14px; }
body.embed .play-full { color: var(--soft); font-size: 11px; }
/* a very short embed (a strip): no footer, and the top bar sits over the sky */
@media (max-height: 280px) {
  body.embed { padding: 0; position: relative; }
  body.embed .bottom { display: none; }
  body.embed .top { position: absolute; top: 6px; left: 6px; right: 6px; width: auto; z-index: 1; }
  body.embed .game { padding: 0; }
  body.embed #stage canvas { border-radius: 0; }
}

/* phones and tablets held upright: the game page is drawn turned sideways (always landscape).
   The body is rotated a quarter turn; its width is the screen's height and the other way round. */
body.play.turned {
  position: fixed; top: 0; left: 100vw; margin: 0;
  width: 100vh; width: 100dvh; height: 100vw; min-height: 0;
  transform-origin: top left; transform: rotate(90deg);
  overflow: hidden;
}
body.turned .game { gap: 8px; padding: 0; justify-content: center; }
body.turned #stage { flex: none; position: static; min-height: 0; max-width: min(900px, 150vw); }
body.turned #stage canvas { position: static; }
body.turned .pad { max-width: min(900px, 150vw); }
body.turned .pad button { padding: 10px; font-size: 16px; }
body.turned .bottom { gap: 6px; padding-top: 0; }

/* phones and tablets: the game fills the screen, the top bar sits over the sky, only the links below */
body.play.touchfull { padding: 0; position: relative; }
body.touchfull .pad, body.touchfull .keys { display: none !important; }
body.touchfull .game { flex: 1; padding: 0; gap: 0; min-height: 0; justify-content: stretch; }
body.touchfull #stage { flex: 1; position: relative; width: 100%; max-width: none; min-height: 0; }
body.touchfull #stage canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; border-radius: 0; }
body.touchfull .top {
  position: absolute; top: 0; left: 0; right: 0; width: auto; z-index: 2;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
}
body.touchfull .bottom { padding: 6px 10px max(6px, env(safe-area-inset-bottom)); }
body.touchfull.turned .bottom { padding-bottom: 6px; }

/* text pages (about, privacy, terms, changelog) on upright phones and tablets: turned sideways, scrolling */
/* the window must not take over the body's scrolling, or the turned body can't scroll at all */
html.turned { overflow: hidden; height: 100%; }
html.turned body:not(.play) {
  position: fixed; top: 0; left: 100vw; margin: 0;
  width: 100vh; width: 100dvh; height: 100vw; min-height: 0; max-height: 100vw;
  transform-origin: top left; transform: rotate(90deg);
  overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch;
}
/* the Ko-fi popup sits above the page, so it turns on its own */
body.turned dialog.kofi, html.turned dialog.kofi {
  transform: rotate(90deg);
  width: min(440px, calc(100vh - 24px)); width: min(440px, calc(100dvh - 24px));
  max-height: calc(100vw - 24px);
}
body.turned .kofi-body iframe, html.turned .kofi-body iframe { max-height: calc(100vw - 130px); }
