:root {
  --ro-blue: #002b7f;
  --ro-yellow: #fcd116;
  --ro-red: #ce1126;
  --cream: #fff6e5;
  --ink: #2b1a10;
  --display-font: 'Baloo 2', 'Nunito', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1b2340;
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--ink);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  /* stop iOS from enlarging text when the phone is in landscape */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

button { touch-action: manipulation; }

canvas {
  display: block;
  position: fixed;
  inset: 0;
}

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  /* keep clear of notches, rounded corners and the home indicator */
  padding:
    max(12px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    12px
    max(16px, env(safe-area-inset-left));
  pointer-events: none;
}

.hud-box {
  background: rgba(255, 246, 229, 0.9);
  border-radius: 14px;
  padding: 6px 14px 4px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.2);
  min-width: 0;
  margin-right: 8px;
}

#levelName { font-weight: 800; font-size: 13px; opacity: 0.85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#score { font-family: var(--display-font); font-weight: 800; font-size: 28px; line-height: 1.1; }

.hud-buttons { display: flex; gap: 8px; flex-shrink: 0; pointer-events: auto; }
.hud-buttons button {
  width: 44px; height: 44px;
  border: none;
  border-radius: 12px;
  background: var(--cream);
  font-size: 20px;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
}
.hud-buttons button:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25); }

/* Hints sit at the top, in the sky, so they never cover the slingshot or the targets. */
#hint {
  position: fixed;
  top: calc(max(12px, env(safe-area-inset-top)) + 64px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(43, 26, 16, 0.72);
  transition: opacity 0.5s;
  color: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
  pointer-events: none;
  text-align: center;
  white-space: nowrap;
  max-width: calc(100% - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
}
#hint:empty { display: none; }
#hint.faded { opacity: 0; }
#hint b { color: var(--ro-yellow); }

/* Full-screen "turn your phone" notice for touch devices held upright. */
#rotate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: var(--ro-blue);
  color: #fff;
  font-family: var(--display-font); font-weight: 800;
  font-size: 24px;
  text-align: center;
  padding: 24px;
}
#rotate p { margin: 0; max-width: 260px; }
#rotate .phone {
  width: 54px; height: 92px;
  border: 5px solid #fff;
  border-radius: 12px;
  animation: turn 1.8s ease-in-out infinite;
}
@keyframes turn {
  0%, 20% { transform: rotate(0deg); }
  60%, 100% { transform: rotate(-90deg); }
}
@media (orientation: portrait) and (pointer: coarse) {
  #rotate { display: flex; }
}

/* ---------- Overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 12, 30, 0.55);
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}
.hidden { display: none !important; }

.panel {
  position: relative;
  overflow: auto;
  max-height: 100%;
  width: 100%;
  max-width: 560px;
  background: var(--cream);
  border-radius: 22px;
  padding: 34px 28px 24px;
  text-align: center;
  box-shadow: 0 10px 0 rgba(0, 0, 0, 0.25);
}
.panel::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 10px;
  background: linear-gradient(90deg,
    var(--ro-blue) 0 33.33%, var(--ro-yellow) 33.33% 66.66%, var(--ro-red) 66.66%);
}

h1, h2 {
  font-family: var(--display-font); font-weight: 800;
  color: var(--ro-red);
  margin: 0;
  letter-spacing: 1px;
  text-shadow: 0 3px 0 #7a0a15;
}
h1 { font-size: clamp(38px, 8vw, 60px); line-height: 1; }
h2 { font-size: clamp(30px, 6vw, 44px); }

.subtitle { margin: 6px 0 0; font-weight: 800; color: var(--ro-blue); }
.howto { margin: 0; font-size: 14px; line-height: 1.45; }
kbd {
  font-family: inherit;
  background: #fff;
  border: 1px solid #d8c7a6;
  border-radius: 4px;
  padding: 0 4px;
}

#levels {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 18px 0;
}
.level {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 8px;
  border: none;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 4px 0 #d8c7a6;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink);
  transition: transform 0.1s;
}
.level:hover:not(:disabled) { transform: translateY(-2px); }
.level:disabled { opacity: 0.5; cursor: not-allowed; }
.level .num { font-family: var(--display-font); font-weight: 800; font-size: 28px; color: var(--ro-red); line-height: 1; }
.level .lname { font-weight: 800; font-size: 14px; }
.level .lstars { color: #e8a90c; font-size: 18px; letter-spacing: 2px; }

#endStars { font-size: 52px; color: #e8a90c; letter-spacing: 6px; line-height: 1.2; margin-top: 6px; }
#endStars .off { color: #d8c7a6; }
#endText { font-weight: 700; margin: 8px 0; }
#endScore { font-family: var(--display-font); font-weight: 800; font-size: 30px; margin-bottom: 16px; }

.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.btn {
  font-family: var(--display-font); font-weight: 800;
  font-size: 18px;
  padding: 12px 18px;
  border: none;
  border-radius: 14px;
  background: var(--ro-red);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 0 #7a0a15;
}
.btn.secondary { background: var(--ro-blue); box-shadow: 0 4px 0 #001a4d; }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.3); }

/* ---------- Menus, settings, achievements ---------- */
.panel.narrow { max-width: 420px; }
.panel.wide { max-width: 760px; }
.panel p { line-height: 1.45; }
h3 {
  font-family: var(--display-font);
  font-weight: 800;
  color: var(--ro-blue);
  font-size: 20px;
  margin: 14px 0 4px;
}
.muted { opacity: 0.65; font-weight: 700; margin: 0; }
.small-text { font-size: 13px; margin: 4px 0; }

.btn.small { font-size: 15px; padding: 9px 14px; }
.btn.ghost {
  background: transparent;
  color: var(--ro-red);
  box-shadow: none;
  border: 2px solid currentColor;
}
.stack { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

.menu-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.total-stars { font-family: var(--display-font); font-weight: 800; font-size: 20px; color: #c98a00; }
.level .lbest { font-size: 11px; font-weight: 700; opacity: 0.6; }

.settings-list { text-align: left; margin: 14px 0 18px; }
.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 2px;
  border-bottom: 1px solid #ecdcc0;
  font-weight: 800;
}
.switch {
  position: relative;
  width: 54px; height: 30px;
  flex-shrink: 0;
  border: none;
  border-radius: 999px;
  background: #d8c7a6;
  cursor: pointer;
  transition: background 0.15s;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s;
}
.switch[aria-checked="true"] { background: #2e9d4a; }
.switch[aria-checked="true"]::after { transform: translateX(24px); }
.segmented { display: flex; background: #ecdcc0; border-radius: 12px; padding: 3px; }
.segmented button {
  border: none;
  background: transparent;
  padding: 6px 12px;
  border-radius: 9px;
  font-family: inherit;
  font-weight: 800;
  color: var(--ink);
  cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); }

.ach-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 8px;
  margin: 12px 0 6px;
  text-align: left;
}
.ach {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 2px 0 #e6d6b8;
}
.ach .icon {
  flex-shrink: 0;
  width: 36px; height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--ro-yellow);
  font-size: 18px;
}
.ach.locked { opacity: 0.55; }
.ach.locked .icon { background: #e6d6b8; filter: grayscale(1); }
.ach b { display: block; font-size: 14px; }
.ach .desc { font-size: 12px; line-height: 1.3; }
.stats-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px 14px;
  margin: 6px 0 16px;
  text-align: left;
  font-size: 13px;
}
.stats-list div { display: flex; justify-content: space-between; border-bottom: 1px dashed #e0cfae; padding: 3px 0; }
.stats-list b { font-family: var(--display-font); font-size: 15px; }

.badge {
  display: inline-block;
  background: var(--ro-yellow);
  color: var(--ink);
  font-weight: 800;
  border-radius: 999px;
  padding: 4px 12px;
  margin: -6px 0 12px;
  animation: pop 0.4s ease-out;
}
@keyframes pop { 0% { transform: scale(0.4); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }

#toasts {
  position: fixed;
  top: max(70px, calc(env(safe-area-inset-top) + 60px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 20;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--ink);
  color: #fff;
  padding: 8px 16px 8px 8px;
  border-radius: 999px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  animation: toast-in 0.35s ease-out, toast-out 0.4s ease-in 3.2s forwards;
  white-space: nowrap;
}
.toast .icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; background: var(--ro-yellow); font-size: 18px; }
.toast small { display: block; opacity: 0.75; font-size: 11px; }
@keyframes toast-in { from { transform: translateY(-20px); opacity: 0; } }
@keyframes toast-out { to { transform: translateY(-20px); opacity: 0; } }

/* ---------- Profile, challenges, sharing ---------- */
.hud-left { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; min-width: 0; }
.rival {
  display: flex; align-items: center; gap: 6px;
  background: rgba(43, 26, 16, 0.8); color: #fff;
  border-radius: 999px; padding: 3px 12px 3px 3px;
  font-weight: 800; font-size: 13px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.2);
}
.rival .av, .lrival .av, .end-rival .av, .profile-chip .av { display: inline-flex; flex-shrink: 0; }
.rival .av svg { width: 28px; height: 28px; }
.rival.beaten { background: #2e9d4a; }

.panel { --chip-top: 18px; }
.profile-chip {
  position: absolute; top: var(--chip-top); left: 14px;
  display: flex; align-items: center; gap: 8px;
  border: none; background: #fff; border-radius: 999px;
  padding: 3px 12px 3px 3px; cursor: pointer;
  font-family: inherit; font-weight: 800; font-size: 14px; color: var(--ink);
  box-shadow: 0 3px 0 #d8c7a6; max-width: 46%;
}
.profile-chip .av svg { width: 34px; height: 34px; }
.profile-chip .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.name-row { display: flex; align-items: center; gap: 12px; margin: 14px 0 10px; font-weight: 800; text-align: left; }
.name-row input {
  flex: 1; min-width: 0;
  font: 800 18px 'Nunito', sans-serif; color: var(--ink);
  padding: 10px 14px; border-radius: 12px;
  border: 2px solid #d8c7a6; background: #fff; outline: none;
}
.name-row input:focus { border-color: var(--ro-blue); }
.shake { animation: shake 0.4s; border-color: var(--ro-red) !important; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 8px; margin: 6px 0 16px;
}
.avatar-pick {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  border: 3px solid transparent; border-radius: 16px; background: #fff;
  padding: 6px 4px; cursor: pointer; font-family: inherit;
  box-shadow: 0 2px 0 #e6d6b8;
}
.avatar-pick svg { width: 64px; height: 64px; }
.avatar-pick span { font-size: 11px; font-weight: 800; line-height: 1.15; color: var(--ink); }
.avatar-pick[aria-pressed="true"] { border-color: var(--ro-red); background: #fff1f1; }

.challenge-panel .big-avatar { display: flex; justify-content: center; margin-bottom: 6px; }
.challenge-panel .big-avatar svg { width: 120px; height: 120px; border-radius: 50%; box-shadow: 0 0 0 5px #fff, 0 6px 0 5px #d8c7a6; }
.ch-text { font-family: var(--display-font); font-weight: 800; font-size: 24px; color: var(--ro-blue); margin: 6px 0 0; }
.ch-stars { font-size: 34px; color: #e8a90c; letter-spacing: 4px; }
.ch-stars .off { color: #d8c7a6; }
.ch-question { font-weight: 800; font-size: 18px; margin: 4px 0 14px; }

.lrival {
  display: flex; align-items: center; gap: 4px; margin-top: 3px;
  background: #fff1f1; border-radius: 999px; padding: 2px 8px 2px 2px;
  font-size: 11px; font-weight: 800; color: var(--ro-red); max-width: 100%;
}
.lrival .av svg { width: 20px; height: 20px; }
.lrival .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.end-rival {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin: -4px auto 14px; padding: 6px 14px 6px 6px; width: fit-content; max-width: 100%;
  background: #fff; border-radius: 999px; font-weight: 800; font-size: 15px;
  box-shadow: 0 2px 0 #e6d6b8;
}
.end-rival .av svg { width: 36px; height: 36px; }
.end-rival.won { background: #e3f6e7; color: #1d6b31; }
.share-btn { margin-top: 12px; width: 100%; background: #2e9d4a; box-shadow: 0 4px 0 #1d6b31; }

.share-panel { max-width: 720px; }
.share-body { display: flex; gap: 18px; align-items: center; margin: 12px 0; }
.share-body img { width: 42%; aspect-ratio: 1080 / 1350; border-radius: 14px; background: #002b7f; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25); object-fit: cover; }
.share-actions { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.btn.fb { background: #1877f2; box-shadow: 0 4px 0 #0f4fa8; }
.btn.wa { background: #25a244; box-shadow: 0 4px 0 #1a7331; }
.share-tip { font-size: 12px; margin: 2px 0 0; opacity: 0.75; line-height: 1.35; }

/* ---------- Lobby: the journey map ---------- */
.overlay.lobby, .overlay.onboarding {
  background:
    linear-gradient(0deg, #f3e7cf 0 10px, transparent 10px),
    radial-gradient(120% 100% at 50% 0%, #1458cf 0%, #002b7f 55%, #001a4f 100%);
}
.overlay.lobby {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 10px;
  padding-bottom: max(18px, env(safe-area-inset-bottom));
}
.lobby-top { display: flex; align-items: center; gap: 12px; }
.lobby .profile-chip { position: static; max-width: 34%; }
.lobby-brand {
  flex: 1; text-align: center;
  font-family: var(--display-font); font-weight: 800; font-size: 30px; line-height: 1;
  color: #fff; text-shadow: 0 3px 0 var(--ro-red);
}
.lobby-actions { display: flex; align-items: center; gap: 8px; }
.lobby .total-stars { background: rgba(0, 0, 0, 0.25); color: var(--ro-yellow); border-radius: 999px; padding: 6px 12px; font-size: 18px; }
.icon-btn {
  width: 42px; height: 42px; border: none; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  background: var(--cream); color: var(--ro-blue);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
}
.lobby-main { flex: 1; min-height: 0; display: flex; gap: 14px; align-items: stretch; }
.map-wrap { flex: 1; min-width: 0; min-height: 0; display: flex; align-items: center; justify-content: center; }
.map-wrap svg { width: 100%; height: 100%; overflow: visible; }
.map-sea { fill: #ffffff; opacity: 0.8; font: italic 800 20px 'Nunito', sans-serif; text-anchor: middle; }
.stop { cursor: pointer; outline: none; }
.stop .hit { fill: transparent; }
.stop .dot { fill: #fffaf0; stroke: #7a5a32; stroke-width: 3; transition: stroke-width 0.15s; }
.stop .num { font: 800 17px 'Nunito', sans-serif; text-anchor: middle; fill: #2b1a10; pointer-events: none; }
.stop .label {
  font: 800 21px 'Nunito', sans-serif; fill: #2b1a10;
  paint-order: stroke; stroke: #f6efd9; stroke-width: 5px; stroke-linejoin: round;
}
.stop .mini-stars { font: 14px sans-serif; fill: #e8a90c; text-anchor: middle; paint-order: stroke; stroke: #fff; stroke-width: 3px; }
.stop.done .dot { fill: #2e9d4a; stroke: #1d6b31; }
.stop.done .num, .stop.current .num { fill: #fff; }
.stop.current .dot { fill: var(--ro-red); stroke: #7a0a15; }
.stop.locked .dot { fill: #ddd2bd; stroke: #ab9b7c; }
.stop.locked .label { fill: #8a7a5c; }
.stop.locked .num { font-size: 13px; }
.stop.selected .dot { stroke: var(--ro-yellow); stroke-width: 6; }
.stop .pulse { fill: none; stroke: var(--ro-red); stroke-width: 3; transform-box: fill-box; transform-origin: center; animation: pulse 1.6s ease-out infinite; pointer-events: none; }
@keyframes pulse { from { transform: scale(1); opacity: 0.9; } to { transform: scale(2.1); opacity: 0; } }
.stop .rival-dot { fill: var(--ro-yellow); stroke: #7a0a15; stroke-width: 2; }
#meMarker { filter: drop-shadow(0 4px 3px rgba(0, 0, 0, 0.35)); pointer-events: none; }

.stop-card {
  width: 250px; flex-shrink: 0;
  display: flex; flex-direction: column; justify-content: center; gap: 6px;
  background: var(--cream); border-radius: 20px; padding: 18px 16px;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.25); text-align: center; overflow: auto;
}
.stop-num { font-weight: 800; font-size: 13px; color: var(--ro-blue); text-transform: uppercase; letter-spacing: 0.06em; }
.stop-card h3 { margin: 0; font-size: 24px; color: var(--ro-red); line-height: 1.1; }
.stop-stars { font-size: 28px; color: #e8a90c; letter-spacing: 3px; }
.stop-stars .off { color: #d8c7a6; }
.stop-best { font-weight: 800; font-size: 14px; min-height: 1em; opacity: 0.75; }
.stop-card .end-rival { margin: 2px auto; font-size: 12px; }
.stop-card .end-rival .av svg { width: 28px; height: 28px; }
.stop-locked { font-size: 13px; margin: 0; opacity: 0.75; }
.stop-card .btn { margin-top: 4px; }

/* ---------- First launch ---------- */
.onboarding .panel { text-align: center; }
.steps { display: flex; justify-content: center; gap: 6px; margin-bottom: 10px; }
.steps i { width: 26px; height: 6px; border-radius: 3px; background: #e2d3b4; }
.steps i.on { background: var(--ro-red); }
.steps i.done { background: #2e9d4a; }
.welcome-icon { width: 96px; height: 96px; border-radius: 24px; transform: rotate(-6deg); box-shadow: 0 8px 18px rgba(0, 0, 0, 0.25); }
.welcome-story { font-size: 16px; font-weight: 700; margin: 10px 0; }
.onboarding .howto { opacity: 0.75; margin-bottom: 16px; }
.big-input {
  display: block; width: 100%; margin: 14px 0 16px;
  font: 800 24px 'Nunito', sans-serif; text-align: center; color: var(--ink);
  padding: 12px 16px; border-radius: 14px; border: 3px solid #d8c7a6; background: #fff; outline: none;
}
.big-input:focus { border-color: var(--ro-blue); }
.btn.big { width: 100%; font-size: 20px; padding: 14px 22px; }

/* Avatar pickers: only the grid scrolls, the title and button stay in view */
#onbAvatar .panel, #profile .panel { display: flex; flex-direction: column; }
#onbAvatar .avatar-grid, #profile .avatar-grid { flex: 1; min-height: 0; overflow: auto; padding: 2px; }
#onbAvatar .btn.big, #profile .row { flex-shrink: 0; }

/* ---------- Level end ---------- */
.end-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.end-actions .row { flex-wrap: nowrap; }
.end-actions .row .btn { flex: 1; }
.end-actions .share-btn { margin-top: 0; font-size: 19px; }

/* ---------- Phones in landscape (short screens) ---------- */
@media (max-height: 500px) {
  #hud { padding-top: max(8px, env(safe-area-inset-top)); }
  .hud-box { padding: 4px 10px 2px; border-radius: 10px; }
  #levelName { font-size: 11px; }
  #score { font-size: 20px; }
  .hud-buttons button { width: 38px; height: 38px; font-size: 17px; border-radius: 10px; }
  #hint { font-size: 11px; padding: 5px 12px; top: calc(max(8px, env(safe-area-inset-top)) + 50px); }

  .panel { max-width: 720px; padding: 22px 18px 14px; border-radius: 16px; }
  h1 { font-size: 34px; }
  h2 { font-size: 28px; }
  .subtitle { font-size: 13px; margin-top: 2px; }
  #levels { grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px; margin: 10px 0; }
  .level { padding: 8px 6px; }
  .level .num { font-size: 22px; }
  .level .lname { font-size: 12px; }
  .level .lstars { font-size: 14px; }
  .howto { font-size: 12px; }
  #endStars { font-size: 36px; margin-top: 2px; }
  #endText { margin: 4px 0; font-size: 14px; }
  #endScore { font-size: 22px; margin-bottom: 10px; }
  .btn { font-size: 15px; padding: 9px 14px; }
}

@media (max-height: 500px) {
  .panel.narrow { max-width: 460px; }
  .settings-list { margin: 8px 0 10px; }
  .setting { padding: 6px 2px; font-size: 14px; }
  .stack { gap: 7px; margin-top: 10px; }
  h3 { font-size: 16px; margin: 8px 0 2px; }
  .ach-list { gap: 6px; }
  .ach { padding: 5px 8px; }
  .menu-footer { margin-bottom: 6px; }
  .panel p { font-size: 14px; margin: 6px 0; }
  .overlay.lobby { gap: 6px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .lobby-brand { font-size: 22px; }
  .lobby .total-stars { font-size: 14px; padding: 4px 10px; }
  .icon-btn { width: 34px; height: 34px; }
  .icon-btn svg { width: 17px; height: 17px; }
  .stop-card { width: 196px; padding: 10px 12px; gap: 3px; border-radius: 16px; }
  .stop-card h3 { font-size: 18px; }
  .stop-stars { font-size: 22px; }
  .stop-best { font-size: 12px; }
  .welcome-icon { width: 64px; height: 64px; border-radius: 16px; }
  .welcome-story { font-size: 14px; margin: 6px 0; }
  .onboarding .howto { display: none; }
  .big-input { font-size: 20px; padding: 8px 12px; margin: 8px 0 10px; }
  .btn.big { font-size: 17px; padding: 10px 18px; }
  .steps { margin-bottom: 4px; }
  /* level end: results left, actions right, so everything fits above the fold */
  .end-panel { display: grid; grid-template-columns: 1.15fr 1fr; gap: 18px; align-items: center; max-width: 740px; padding: 22px 18px 16px; }
  .end-panel h2 { font-size: 26px; }
  .end-panel #endStars { font-size: 32px; }
  .end-panel #endText { font-size: 13px; margin: 2px 0; }
  .end-panel #endScore { font-size: 22px; margin-bottom: 6px; }
  .end-panel .badge { margin: 0 0 4px; padding: 2px 10px; font-size: 13px; }
  .end-panel .end-rival { margin: 4px auto 0; font-size: 12px; }
  .end-actions { margin-top: 0; gap: 8px; }
  .end-actions .share-btn { font-size: 16px; }
  .panel { --chip-top: 14px; }
  .profile-chip { font-size: 12px; }
  .profile-chip .av svg { width: 28px; height: 28px; }
  .rival { font-size: 11px; }
  .rival .av svg { width: 22px; height: 22px; }
  .avatar-grid { grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 6px; }
  .avatar-pick svg { width: 50px; height: 50px; }
  .name-row { margin: 8px 0 6px; }
  .name-row input { font-size: 16px; padding: 6px 12px; }
  .challenge-panel .big-avatar svg { width: 84px; height: 84px; }
  .ch-text { font-size: 19px; }
  .ch-stars { font-size: 26px; }
  .share-body { gap: 12px; margin: 6px 0; }
  .share-body img { width: 30%; }
  .share-actions .btn { padding: 7px 12px; font-size: 14px; }
  .ach-list { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
  .total-stars { font-size: 16px; }
}

/* Keyboard hint only makes sense with a keyboard. */
@media (pointer: coarse) {
  .howto kbd, .howto .kbd-only { display: none; }
}
