:root {
  --bg: #fdf8f3;
  --ink: #4a4458;
  --ink-soft: #8a83a0;
  --card: rgba(255, 255, 255, 0.82);
  --pill: #ffffff;
  --accent: #ffb38a;
  --accent-dark: #f39a6b;
  --lavender: #e9e1ff;
  --shadow: 0 10px 30px rgba(120, 100, 160, 0.15);
  --radius: 24px;
}

* { box-sizing: border-box; }

/* Anything hidden stays hidden, whatever display style it normally has. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Fredoka', ui-rounded, 'SF Pro Rounded', system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* Pull-to-refresh works on the menus, but not during a game, where a swipe
   down to steer mustn't reload the page. */
html.in-game, html.in-game body { overscroll-behavior: none; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: none;
  -webkit-user-select: none;
  user-select: none;
}

.app {
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* --- HUD --------------------------------------------------------------- */

/* Wide screens: one row. Portrait phones: title on its own row (see below). */
.hud {
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  grid-template-areas: "score title lives best controls";
  align-items: center;
  gap: 8px;
}

.hud .title { grid-area: title; justify-self: center; }
.hud .score-pill { grid-area: score; justify-self: start; }
.hud .best-pill { grid-area: best; }
.hud .controls { grid-area: controls; }

.hud h1 {
  margin: 0;
  font-size: clamp(1.1rem, 4vw, 1.6rem);
  font-weight: 600;
  color: #a78bfa;
  text-align: center;
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud h1 .logo { width: 1.6em; height: 1.6em; }

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

/* Portrait phones: title row, then a stats row; the board stays square and
   any spare height is shared out evenly instead of pooling round the board. */
@media (max-width: 600px) and (orientation: portrait) {
  .app { justify-content: space-evenly; }
  .hud {
    grid-template-columns: auto auto 1fr auto;
    grid-template-areas:
      "title title title title"
      "score best . controls";
    row-gap: 12px;
  }
  .hud h1 { font-size: 1.6rem; }
  .board-wrap { flex: 1 1 0; max-height: calc(100vw - 32px); }
}

.pill {
  white-space: nowrap;
  background: var(--pill);
  border-radius: 999px;
  padding: 6px 14px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-weight: 600;
  font-size: 1.15rem;
}

.pill .label {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.bump { animation: bump 0.3s ease; }
#score.bump { display: inline-block; }
@keyframes bump {
  50% { transform: scale(1.4); color: #ff8fa3; }
}

.icon-button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--pill);
  box-shadow: var(--shadow);
  color: #8b74e0;
  display: grid;
  place-items: center;
}

.icon-button svg { width: 22px; height: 22px; }

.icon-button:active { transform: scale(0.92); }

/* Keep the slot so the title doesn't shift when the button appears. */
/* A button that isn't usable yet (pause, before a game starts): the button
   stays solid so the top bar looks complete; only its symbol is faded. */
.icon-button:disabled { cursor: default; }
.icon-button:disabled .icon { opacity: 0.3; }
.icon-button:disabled:active { transform: none; }

/* --- Board ------------------------------------------------------------- */

.board-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
}

.board {
  container-type: size; /* lets the game card shrink to fit small boards */
  position: absolute;
  inset: 0;
  margin: auto;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  touch-action: none;
}

.board canvas { display: block; }

.stomp { animation: stomp 0.35s ease; }
@keyframes stomp {
  25% { transform: translateY(5px); }
  50% { transform: translateY(-3px); }
  75% { transform: translateY(2px); }
}

.wobble { animation: wobble 0.5s ease; }
@keyframes wobble {
  20% { transform: rotate(-2deg); }
  40% { transform: rotate(2deg); }
  60% { transform: rotate(-1deg); }
  80% { transform: rotate(1deg); }
}

.toast {
  position: absolute;
  top: 16px;
  left: 50%;
  translate: -50% 0;
  background: var(--card);
  color: #a78bfa;
  font-weight: 600;
  font-size: 1.1rem;
  padding: 8px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  white-space: nowrap;
  pointer-events: none;
}

.toast[hidden] { display: none; }

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow-y: auto; /* never cut off: scroll if the card is taller than the board */
  padding: 16px;
  background: rgba(253, 248, 243, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.overlay[hidden] { display: none; }

.card {
  width: min(340px, 100%);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 28px;
  text-align: center;
  animation: pop-in 0.25s ease;
}

@keyframes pop-in {
  from { transform: scale(0.9); opacity: 0; }
}


.card h2 { margin: 0; font-size: 2rem; line-height: 1.15; color: #a78bfa; }
.card-subtitle { margin: 2px 0 0; font-weight: 600; color: var(--ink-soft); letter-spacing: 0.04em; }
.card-body { margin: 16px 0 20px; color: var(--ink-soft); line-height: 1.45; }
.card h2, .card-body p, .card-hint { text-wrap: balance; } /* no single words left alone on a line */
.card-body p { margin: 0 0 4px; }
.card-body .new-best { color: #ff8fa3; font-weight: 600; margin-top: 6px; }
.card-hint { margin: 14px 0 0; font-size: 0.85rem; color: var(--ink-soft); opacity: 0.85; }

/* The level goal as short icon rows. */
.goals { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; text-align: left; }
.goals li { display: flex; align-items: center; gap: 12px; }
.goals .icon { width: 34px; height: 34px; flex: none; vertical-align: 0; }
.goals strong { display: block; color: var(--ink); font-size: 1.05rem; }
.goals span { line-height: 1.3; font-size: 0.95rem; text-wrap: balance; } /* even lines, so no word sits alone on the last one */

.primary {
  background: var(--accent);
  color: white;
  font-size: 1.25rem;
  font-weight: 600;
  padding: 14px 36px;
  border-radius: 999px;
  box-shadow: 0 6px 0 var(--accent-dark);
  transition: transform 0.1s, box-shadow 0.1s;
}

.primary:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--accent-dark);
}

/* --- D-pad (touch devices only) ----------------------------------------- */

.dpad {
  display: none;
  grid-template-areas:
    ". up ."
    "left . right"
    ". down .";
  grid-template-columns: repeat(3, 72px);
  grid-template-rows: repeat(3, 64px);
  gap: 6px;
  justify-content: center;
  touch-action: none;
}

.dpad button {
  border-radius: 20px;
  background: var(--lavender);
  color: #8b74e0;
  font-size: 1.5rem;
  box-shadow: 0 4px 0 #d4c8f7;
}

.dpad button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #d4c8f7;
}

.dpad [data-dir="up"] { grid-area: up; }
.dpad [data-dir="down"] { grid-area: down; }
.dpad [data-dir="left"] { grid-area: left; }
.dpad [data-dir="right"] { grid-area: right; }

@media (pointer: coarse) {
  .dpad { display: grid; }
}

/* --- Menu screens: who's playing, home, leaderboard ------------------------ */

.screen[hidden] { display: none !important; }

.menu {
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
}

.menu h2 { margin: 0; color: var(--ink); font-size: 1.4rem; font-weight: 600; }

.menu-title { display: flex; flex-direction: column; align-items: center; gap: 2px; margin-top: 8px; }
.menu-title h1 { margin: 0; color: #a78bfa; font-size: 2.2rem; font-weight: 600; }
.menu-logo { width: 120px; height: 120px; }

a { color: inherit; text-decoration: none; }

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--avatar);
  color: #fff;
  font-weight: 600;
  font-size: 1.15rem;
  display: inline-grid;
  place-items: center;
  flex: none;
}

.small-button {
  background: var(--pill);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.95rem;
  color: #8b74e0;
  box-shadow: var(--shadow);
}

.secondary-button {
  background: var(--lavender);
  color: #7c63d8;
  font-size: 1.15rem;
  font-weight: 600;
  padding: 12px 28px;
  border-radius: 999px;
  box-shadow: 0 5px 0 #d4c8f7;
}

.secondary-button:active, .player-chip:active, a.row:active, .round-button:active { transform: translateY(2px); }

/* Who's playing? */
.player-grid { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }

.player-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--pill);
  border-radius: 999px;
  padding: 8px 20px 8px 8px;
  font-size: 1.2rem;
  font-weight: 600;
  box-shadow: var(--shadow);
}

.new-player { display: flex; gap: 8px; width: 100%; max-width: 360px; }

.new-player input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 1.15rem;
  padding: 12px 18px;
  border: 2px solid var(--lavender);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

.new-player input:focus { border-color: #a78bfa; }
.new-player .primary { padding: 12px 22px; font-size: 1.1rem; }
.form-error { margin: -8px 0 0; min-height: 1.2em; color: #ff8fa3; }

/* Leaderboard */
.menu-bar { width: 100%; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; }
.menu-bar::after { content: ''; width: 80px; } /* balances the back button so the title centres */

.tabs { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.tab { padding: 6px 16px; border-radius: 999px; background: rgba(255, 255, 255, 0.6); color: var(--ink-soft); }
.tab.active { background: #a78bfa; color: #fff; font-weight: 600; }

.scoreboard { list-style: none; margin: 0; padding: 0; width: 100%; display: flex; flex-direction: column; gap: 10px; }

.scoreboard li {
  display: grid;
  grid-template-columns: 2.2em auto 1fr auto;
  grid-template-areas: "rank avatar name pears" "rank avatar date pears";
  align-items: center;
  column-gap: 10px;
  background: var(--pill);
  border-radius: 18px;
  padding: 10px 16px;
  box-shadow: var(--shadow);
  text-align: left;
}

.scoreboard li.me { outline: 3px solid #e9e1ff; background: #faf7ff; }
.scoreboard .rank { grid-area: rank; font-size: 1.4rem; text-align: center; color: var(--ink-soft); font-weight: 600; }
.scoreboard .avatar { grid-area: avatar; }
.scoreboard .name { grid-area: name; font-weight: 600; font-size: 1.1rem; display: flex; align-items: center; }
.scoreboard .date { grid-area: date; color: var(--ink-soft); font-size: 0.8rem; }
.scoreboard .pears { grid-area: pears; font-weight: 600; font-size: 1.15rem; white-space: nowrap; }
.empty, .legend { color: var(--ink-soft); margin: 0; }
.legend { font-size: 0.9rem; }

/* Game card buttons */
/* Round Home button on the left, the main action filling the rest. */
.card-actions { display: flex; align-items: center; gap: 10px; }
.card-actions .primary { flex: 1 1 0; min-width: 0; white-space: nowrap; padding: 14px 18px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.card-actions .primary.soft { background: var(--lavender); color: #7c63d8; box-shadow: 0 6px 0 #d4c8f7; }
.card-home { width: 52px; height: 52px; box-shadow: 0 6px 0 #d4c8f7; }
.card-home:active { transform: translateY(4px); box-shadow: 0 2px 0 #d4c8f7; }

/* --- Icons (src/icons.js) ---------------------------------------------------- */

.icon { width: 1.25em; height: 1.25em; vertical-align: -0.28em; flex: none; display: inline-block; }
.icon-button .icon { width: 22px; height: 22px; vertical-align: 0; }
/* The score pill holds an icon, so centre it rather than line up text baselines. */
.score-pill { align-items: center; gap: 4px; }
.score-pill .label { display: flex; line-height: 0; }
.score-pill .label .icon { width: 22px; height: 22px; vertical-align: 0; }
#score { display: inline-flex; align-items: center; gap: 4px; line-height: 1; }
#score .icon { width: 1em; height: 1em; vertical-align: 0; }
/* Time trials: the Best pill becomes a countdown clock that hurries at the end. */
.clock-pill { align-items: center; gap: 4px; font-variant-numeric: tabular-nums; }
.clock-pill .label { display: flex; line-height: 0; }
.clock-pill .label .icon { width: 22px; height: 22px; vertical-align: 0; }
.clock-pill.hurry { background: #ffe1e8; color: #d0566f; animation: hurry 1s ease-in-out infinite; }
@keyframes hurry { 50% { transform: scale(1.08); } }
.dpad .icon { width: 30px; height: 30px; }
.card-icon { margin: 0 auto 6px; line-height: 0; }
.card-icon .icon { width: 52px; height: 52px; vertical-align: 0; }
.toast { display: inline-flex; align-items: center; gap: 6px; }
.toast[hidden] { display: none; }
.menu-bar h2 .icon, .secondary-button .icon { width: 1.3em; height: 1.3em; }
.secondary-button, .small-button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.scoreboard .rank .icon { width: 1.9rem; height: 1.9rem; }
.scoreboard .pears { display: inline-flex; align-items: center; gap: 4px; }
.empty { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty-logo { width: 72px; height: 72px; }

/* --- My snake (profile) -------------------------------------------------------- */


.profile-preview { display: flex; align-items: center; gap: 14px; }
.profile-preview .avatar { width: 64px; height: 64px; font-size: 1.8rem; }
.snake-preview { height: 34px; width: auto; }

.picker { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.picker h3 { margin: 0; font-size: 1.05rem; color: var(--ink-soft); font-weight: 600; }

.swatches { display: grid; grid-template-columns: repeat(4, 48px); gap: 12px; justify-content: center; }
.swatch {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: var(--shadow);
  outline: 3px solid transparent;
  outline-offset: 3px;
}
.swatch.selected { outline-color: #a78bfa; }

.snake-styles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; width: 100%; max-width: 420px; }
.snake-style {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--pill);
  border-radius: 18px;
  box-shadow: var(--shadow);
  outline: 3px solid transparent;
  font-weight: 600;
}
.snake-style .snake-preview { height: 20px; }
.snake-style.selected { outline-color: #a78bfa; background: #faf7ff; }

.danger-zone { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 8px; }
.small-button.delete, .confirm-yes { color: #e07070; }
.confirm p { margin: 0 0 10px; }
.confirm-actions { display: flex; gap: 10px; justify-content: center; align-items: center; }
.confirm-actions .primary { padding: 10px 26px; font-size: 1.05rem; }

/* --- Home: one column of sections ------------------------------------------------ */

.home-title { display: flex; flex-direction: column; align-items: center; gap: 0; margin-top: 4px; }
.home-title h1 { margin: 0; color: #a78bfa; font-size: 2rem; font-weight: 600; }
.home-logo { width: 84px; height: 84px; }

.home-stack { width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 22px; text-align: left; }

.profile-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--pill);
  border-radius: var(--radius);
  padding: 12px 12px 12px 14px;
  box-shadow: var(--shadow);
}
.profile-me { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; }
.profile-me .avatar { width: 52px; height: 52px; font-size: 1.5rem; }
.profile-row { display: flex; align-items: center; gap: 10px; }
.profile-name { font-size: 1.3rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Drawn like the game board (frame, rounded board, dots); sized by pet.js. */
.garden-wrap { display: flex; justify-content: center; }
.garden { display: block; height: 84px; border-radius: 12px; }

.round-button {
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 50%;
  background: var(--lavender);
  color: #8b74e0;
  display: grid;
  place-items: center;
}
.round-button .icon { width: 22px; height: 22px; vertical-align: 0; }

/* Small heading above a group of rows, lined up with the rows' contents. */
.menu .section-title {
  margin: 0 0 10px 18px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.row-group {
  display: flex;
  flex-direction: column;
  background: var(--pill);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.row { display: flex; align-items: center; gap: 14px; padding: 14px 16px; min-height: 68px; }
.row + .row { border-top: 2px solid #f3eefc; }
.row-badge {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 14px;
  background: var(--lavender);
  color: #7c63d8;
  font-weight: 600;
  font-size: 1.2rem;
  display: grid;
  place-items: center;
}
.row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-name { font-weight: 600; font-size: 1.15rem; color: var(--ink); }
.row-detail { color: var(--ink-soft); font-size: 0.95rem; }
.row-end { flex: none; color: #8b74e0; display: grid; place-items: center; }
.row-end .icon { width: 30px; height: 30px; vertical-align: 0; }
.row.locked .row-badge { background: #f1eef6; color: var(--ink-soft); }
.row.locked .row-name { color: var(--ink-soft); }
.row.locked .row-end .icon { width: 24px; height: 24px; opacity: 0.8; }

.leaderboard-row { flex-direction: row; }
.row-icon { width: 40px; height: 40px; flex: none; display: grid; place-items: center; }
.row-icon .icon { width: 30px; height: 30px; vertical-align: 0; }

/* Small boards (small phones): a more compact game card so it fits. */
@container (max-height: 420px) {
  .card { padding: 16px 18px; }
  .card h2 { font-size: 1.5rem; }
  .card-icon .icon { width: 38px; height: 38px; }
  .card-subtitle { font-size: 0.9rem; }
  .card-body { margin: 10px 0 14px; font-size: 0.95rem; }
  .goals { gap: 8px; }
  .goals .icon { width: 26px; height: 26px; }
  .goals strong { font-size: 0.95rem; }
  .goals span { font-size: 0.85rem; }
  .card-actions .primary { padding: 10px 14px; font-size: 1.1rem; }
  .card-home { width: 44px; height: 44px; }
  .card-hint { margin-top: 10px; font-size: 0.78rem; }
}

/* --- Leaderboard: level names and the boss teaser --------------------------------- */

.tab { display: inline-flex; align-items: center; gap: 6px; }
.tab-number {
  width: 22px;
  height: 22px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 600;
  background: rgba(167, 139, 250, 0.18);
}
.tab.active .tab-number { background: rgba(255, 255, 255, 0.3); }

.level-hero {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--pill);
  border-radius: var(--radius);
  padding: 12px 20px 12px 12px;
  box-shadow: var(--shadow);
  text-align: left;
}
.hero-boss { flex: none; animation: hero-bob 2.4s ease-in-out infinite; }
@keyframes hero-bob { 50% { transform: translateY(-5px); } }
@media (prefers-reduced-motion: reduce) { .hero-boss { animation: none; } }
.hero-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.hero-level { font-size: 0.8rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); }
.hero-name { font-size: 1.6rem; font-weight: 600; color: #a78bfa; line-height: 1.1; }
.hero-detail { color: var(--ink-soft); }

/* --- Difficulty ---------------------------------------------------------------------- */

.difficulties { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; width: 100%; max-width: 420px; }
.difficulty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 8px;
  background: var(--pill);
  border-radius: 18px;
  box-shadow: var(--shadow);
  outline: 3px solid transparent;
}
.difficulty strong { font-size: 1.1rem; color: var(--ink); }
.difficulty span { font-size: 0.8rem; color: var(--ink-soft); line-height: 1.2; }

/* Same colours as the Easy / Hardcore tags; Normal uses the game's lavender. */
.difficulty.easy { background: #f3fbf5; }
.difficulty.easy strong { color: #3f9a5e; }
.difficulty.easy.selected { outline-color: #7ccf95; background: #e3f5e9; }
.difficulty.normal { background: #faf8ff; }
.difficulty.normal strong { color: #7c63d8; }
.difficulty.normal.selected { outline-color: #a78bfa; background: #efe9ff; }
.difficulty.hard { background: #fff6f6; }
.difficulty.hard strong { color: #d05f5f; }
.difficulty.hard.selected { outline-color: #f59e9e; background: #ffe4e4; }

/* Sized to the name's letter height and centred on its letters (the extra
   pixel of rounding goes downward so it reads as centred, not high). */
.difficulty-tag {
  display: inline-flex;
  align-items: center;
  height: 1.7em;
  margin-left: 8px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.02em;
  vertical-align: middle;
  position: relative;
  top: 1px;
}
.difficulty-tag.easy { background: #e3f5e9; color: #3f9a5e; }
.difficulty-tag.normal { background: #efe9ff; color: #7c63d8; }
.difficulty-tag.hard { background: #ffe4e4; color: #d05f5f; }

/* Boss heads in place of level numbers on Home. */
.row-head { background: #f6f3fb; }
.row-head .icon { width: 32px; height: 32px; vertical-align: 0; }
.row.locked .row-head { background: #f6f4f9; }

/* --- Spare lives: hearts in the top bar, never over the board ------------------------- */

.hud { position: relative; }
.hud .lives { grid-area: lives; gap: 2px; padding: 5px 10px; }
.lives .icon { width: 24px; height: 24px; vertical-align: 0; }

/* Portrait phones: at the right end of the title row. With hearts showing,
   the title moves to the left of its row so the two never overlap. */
@media (max-width: 600px) and (orientation: portrait) {
  /* grid-area: auto so it's placed against the top bar itself in every
     browser (the phone layout has no 'lives' slot). */
  .hud .lives { grid-area: auto; position: absolute; top: 2px; right: 0; padding: 4px 8px; }
  .hud.has-lives .title { justify-self: start; }
}


/* Smaller boards: tighten the game card further so Play always fits. */
@container (max-height: 360px) {
  .card { padding: 12px 16px; }
  .card h2 { font-size: 1.35rem; }
  .card-body { margin: 8px 0 10px; }
  .goals { gap: 5px; }
  .goals .icon { width: 22px; height: 22px; }
  .goals strong { font-size: 0.9rem; }
  .goals span { font-size: 0.8rem; line-height: 1.2; }
  .card-actions .primary { padding: 8px 12px; font-size: 1rem; }
  .card-home { width: 40px; height: 40px; }
  .card-hint { margin-top: 6px; }
}

/* --- Big D-pad on touch screens -------------------------------------------------------
   One pad split along its two diagonals into four equal triangles (up, right,
   down, left), so every direction gets exactly a quarter of the area and there
   are no dead corners. Each button covers the whole pad, clipped to its
   triangle, and taps only count inside that triangle. */
@media (pointer: coarse) {
  .dpad {
    position: relative;
    display: block;
    border-radius: 26px;
    background:
      url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3Cpath d='M0 0 L100 100 M100 0 L0 100' stroke='white' stroke-width='3' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E") center / 100% 100% no-repeat,
      var(--lavender);
    box-shadow: 0 6px 0 #d4c8f7;
    overflow: hidden;
  }
  .dpad button {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    display: flex;
    padding: 14px 18px;
  }
  .dpad button:active { transform: none; box-shadow: none; background: rgba(124, 99, 216, 0.16); }
  .dpad [data-dir="up"] { clip-path: polygon(0 0, 100% 0, 50% 50%); align-items: flex-start; justify-content: center; }
  .dpad [data-dir="right"] { clip-path: polygon(100% 0, 100% 100%, 50% 50%); align-items: center; justify-content: flex-end; }
  .dpad [data-dir="down"] { clip-path: polygon(0 100%, 100% 100%, 50% 50%); align-items: flex-end; justify-content: center; }
  .dpad [data-dir="left"] { clip-path: polygon(0 0, 0 100%, 50% 50%); align-items: center; justify-content: flex-start; }
  .dpad .icon { width: 36px; height: 36px; }
}

/* Portrait phones: the board keeps priority (it grows three times as eagerly,
   up to its square size); the pad takes whatever height is left under it. */
@media (pointer: coarse) and (orientation: portrait) {
  .board-wrap { flex: 3 1 0; }
  .dpad { flex: 1 1 0; min-height: 205px; max-height: 340px; width: 100%; justify-content: stretch; }
}

/* --- Portrait only on phones --------------------------------------------------------
   Websites can't lock a phone's orientation, so a phone held sideways gets a
   full-screen "turn your phone upright" message instead (laptops and tablets
   are unaffected). The game pauses itself when this shows (see main.js). */
.rotate-notice { display: none; }

@media (pointer: coarse) and (orientation: landscape) and (max-height: 600px) {
  /* Only the message shows, so there's nothing underneath to scroll. */
  body > :not(.rotate-notice) { display: none !important; }
  html, body { overflow: hidden; overscroll-behavior: none; }

  .rotate-notice {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 24px;
    background: var(--bg);
    text-align: center;
  }
  .rotate-notice .icon { width: 96px; height: 96px; color: #a78bfa; animation: rotate-hint 2.4s ease-in-out infinite; }
  .rotate-notice h2 { margin: 0; color: #a78bfa; font-size: 1.6rem; font-weight: 600; }
  .rotate-notice p { margin: 0; color: var(--ink-soft); }
}

@keyframes rotate-hint {
  0%, 20% { transform: rotate(-90deg); }
  50%, 100% { transform: rotate(0deg); }
}
@media (prefers-reduced-motion: reduce) { .rotate-notice .icon { animation: none; } }

/* The credit at the bottom of Home. */
.credits { margin: 4px 0 0; text-align: center; font-size: 0.85rem; color: var(--ink-soft); }
