:root {
  --ro-blue: #002b7f;
  --ro-yellow: #fcd116;
  --ro-red: #ce1126;
  --cream: #fff6e5;
  --ink: #2b1a10;
  --display-font: 'Baloo 2', 'Nunito', sans-serif;
  --safe-top: env(safe-area-inset-top);
  --safe-right: env(safe-area-inset-right);
  --safe-bottom: env(safe-area-inset-bottom);
  --safe-left: env(safe-area-inset-left);
}

* { 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%;
}

/* the short-screen layout below asks the body's height, which stays right when the page is turned sideways */
body { container-type: size; }

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, var(--safe-top))
    max(16px, var(--safe-right))
    12px
    max(16px, var(--safe-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); }
/* behind an open panel the HUD would only peek out around its corners */
body:has(> .overlay:not(.hidden)) #hud { visibility: hidden; }

/* Hints sit at the top, in the sky, so they never cover the slingshot or the targets. */
#hint {
  position: fixed;
  top: calc(max(12px, var(--safe-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); }

/* Phones held upright, or kept upright by the rotation lock: game.js adds .rotated and the whole page
   is turned a quarter turn, so the game is always landscape (the web can't lock the screen on iPhone). */
html.rotated body {
  position: fixed;
  top: 0; left: 0;
  width: var(--rot-w); height: var(--rot-h);
  transform-origin: 0 0;
  transform: translateX(var(--rot-h)) rotate(90deg);
  /* turned sideways, the notch ends up on the left and the home indicator on the right */
  --safe-top: env(safe-area-inset-right);
  --safe-right: env(safe-area-inset-bottom);
  --safe-bottom: env(safe-area-inset-left);
  --safe-left: env(safe-area-inset-top);
}

/* iPhone browsers: the page scrolls so a swipe up makes the browser hide its toolbars (see game.js).
   The body stays exactly one screen tall, because it sizes the compact phone layout (@container below);
   an invisible strip makes the scroll room. The turned page (html.rotated) keeps its own size and doesn't scroll. */
html.ios-scroll:not(.rotated) { height: auto; overflow-y: auto; }
html.ios-scroll:not(.rotated) body { height: 100vh; height: 100dvh; overflow: visible; }
html.ios-scroll:not(.rotated) body::after {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 1px; height: 200vh;
  pointer-events: none;
}
html.ios-swipe, html.ios-swipe body { touch-action: pan-y; }
#swipeFull {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 30;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(0, 43, 127, 0.88);
  color: #fff;
  text-align: center;
  padding: 16px;
  touch-action: pan-y;
}
#swipeFull.show { display: flex; }
#swipeFull .hand {
  width: 34px; height: 54px;
  border: 4px solid #fff;
  border-radius: 17px;
  position: relative;
  animation: swipeUp 1.4s ease-in-out infinite;
}
#swipeFull .hand::after {
  content: '';
  position: absolute;
  left: 50%; top: 9px;
  width: 6px; height: 12px;
  margin-left: -3px;
  border-radius: 3px;
  background: #fff;
}
@keyframes swipeUp {
  0% { transform: translateY(24px); opacity: 0; }
  30% { opacity: 1; }
  100% { transform: translateY(-24px); opacity: 0; }
}
#swipeFull p { margin: 0; }
#swipeFull .big { font-family: var(--display-font); font-weight: 800; font-size: 24px; }
#swipeFull .small { font-weight: 700; font-size: 13px; opacity: 0.8; max-width: 360px; }
#swipeFull button {
  margin-top: 6px;
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-radius: 999px;
  background: transparent;
  color: #fff;
  font: inherit;
  font-weight: 800;
  font-size: 14px;
  padding: 6px 18px;
}

/* ---------- Overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 12, 30, 0.55);
  padding:
    max(16px, var(--safe-top))
    max(16px, var(--safe-right))
    max(16px, var(--safe-bottom))
    max(16px, var(--safe-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(var(--safe-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, var(--safe-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; }

/* ---------- Tall panels: pinned buttons + "more below" cue (scroll-hints.js) ---------- */
.panel { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
/* overlays cover only what the browser actually shows, so its toolbars can't hide the pinned buttons
   (--vv-* come from visualViewport; the turned page in html.rotated sizes itself) */
html:not(.rotated) .overlay { top: var(--vv-top, 0px); bottom: auto; height: var(--vv-h, 100%); }
/* an always-visible scrollbar beside panels that scroll (iPhones hide the native one) */
.scroll-track {
  position: absolute;
  width: 6px;
  border-radius: 3px;
  background: rgba(255, 246, 229, 0.35);
  pointer-events: none;
  z-index: 3;
}
.scroll-track i {
  position: absolute;
  left: 0; right: 0;
  border-radius: 3px;
  background: var(--ro-yellow);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
}
.panel.has-foot { padding-bottom: 0; }
.panel-foot {
  position: sticky;
  bottom: 0;
  z-index: 2;
  margin: 12px -28px 0;
  padding: 12px 28px 24px;
  background: var(--cream);
  transition: box-shadow 0.2s;
}
.panel-foot.bare { margin-top: 0; padding-top: 0; }
.panel.more-below .panel-foot:not(.bare) { box-shadow: 0 -1px 0 #e6d6b8, 0 -8px 14px -10px rgba(43, 26, 16, 0.35); }
/* fade the content into the footer so a half-hidden row reads as "keeps going" */
.panel-foot::before {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 100%;
  height: 40px;
  background: linear-gradient(rgba(255, 246, 229, 0), var(--cream) 85%);
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.panel.more-below .panel-foot::before { opacity: 1; }
.scroll-cue {
  position: absolute;
  left: 50%; bottom: calc(100% + 6px);
  width: 36px; height: 36px;
  margin-left: -18px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--ro-blue);
  color: #fff;
  box-shadow: 0 3px 0 #001a4d;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.panel.more-below .scroll-cue { opacity: 1; pointer-events: auto; animation: cue-bob 1.2s ease-in-out infinite; }
@keyframes cue-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) { .panel.more-below .scroll-cue { animation: none; } }
/* a lone big button keeps full width inside its footer */
.panel-foot > .btn.big { margin: 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) ---------- */
@container (max-height: 500px) {
  #hud { padding-top: max(8px, var(--safe-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, var(--safe-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; }
}

@container (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; }
  .menu-footer { margin-bottom: 6px; }
  .panel p { font-size: 14px; margin: 6px 0; }
  .overlay.lobby { gap: 6px; padding-bottom: max(12px, var(--safe-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; }
  .name-row { margin: 8px 0 6px; }
  /* 16px or more, or iPhones zoom the page in when the field gets focus */
  .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-actions .btn { padding: 7px 12px; font-size: 14px; }
  .total-stars { font-size: 16px; }
  .panel-foot { margin: 6px -18px 0; padding: 6px 18px 12px; }
  .scroll-cue { width: 32px; height: 32px; margin-left: -16px; }
  /* settings in two columns, so the whole list fits without scrolling */
  #settings .panel { max-width: 640px; }
  #settings .settings-list { display: grid; grid-template-columns: 1fr 1fr; column-gap: 24px; }

  /* Phones in landscape have width to spare and little height: spread panels sideways so they fit without scrolling. */
  h1, h2 { line-height: 1.15; }

  /* a title and a short line beside it share one row */
  #achievements .panel, #profile .panel { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; column-gap: 14px; }
  #achievements .panel > *, #profile .panel > * { flex: 0 0 100%; }
  #achievements .panel > h2, #achievements .panel > .subtitle, #profile .panel > h2 { flex: 0 1 auto; }
  #achievements .subtitle { margin: 4px 0 0; }
  #profile .panel > .name-row { flex: 1 1 260px; margin: 0; }

  .ach-list { grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 5px; margin: 6px 0 0; }
  .ach { padding: 3px 8px 3px 4px; gap: 7px; border-radius: 10px; }
  .ach .icon { width: 28px; height: 28px; font-size: 15px; }
  .ach b { font-size: 12.5px; line-height: 1.2; }
  .ach .desc { display: block; font-size: 11px; line-height: 1.2; }
  /* "Statistici" sits beside its numbers */
  #achievements .panel > h3 { flex: 0 0 auto; align-self: flex-start; margin: 7px 0 0; font-size: 15px; }
  #achievements .panel > .stats-list { flex: 1 1 0; min-width: 0; margin-top: 6px; }
  .stats-list { grid-template-columns: repeat(auto-fill, minmax(135px, 1fr)); gap: 0 12px; margin: 0; font-size: 12px; }
  .stats-list div { padding: 1px 0; }
  .stats-list b { font-size: 13px; }

  /* the 30 avatars become a strip that scrolls sideways, so the title, name and button stay in view */
  .avatar-grid {
    grid-template-columns: none;
    grid-template-rows: repeat(2, auto);
    grid-auto-flow: column;
    grid-auto-columns: 68px;
    gap: 6px;
    margin: 8px 0 0;
    padding: 2px 2px 4px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }
  .avatar-grid::-webkit-scrollbar { display: none; }
  .avatar-pick { padding: 4px 2px; border-width: 2px; border-radius: 12px; gap: 2px; justify-content: flex-start; }
  .avatar-pick svg { width: 44px; height: 44px; flex-shrink: 0; }
  .avatar-pick span { font-size: 10px; line-height: 1.1; }

  /* About: the text in two columns */
  #about .panel { max-width: 640px; }
  .about-body { columns: 2; column-gap: 28px; text-align: left; margin-top: 4px; }
  .about-body > :first-child { margin-top: 0; }
  .about-body p { margin: 0 0 6px; break-inside: avoid; }
  .about-body h3 { margin: 6px 0 2px; break-after: avoid; }

  /* Share: a smaller card beside the buttons, laid out two by two */
  .share-body { gap: 14px; align-items: stretch; margin: 8px 0 0; }
  .share-body img { width: auto; height: 190px; flex-shrink: 0; }
  .share-actions { display: grid; grid-template-columns: 1fr 1fr; align-content: center; gap: 8px; }
  .share-actions > .btn:first-child, .share-actions .share-tip { grid-column: 1 / -1; }
  /* in the apps "Copy link" is the only button left on its row */
  #shareCopy:has(+ .btn.hidden) { grid-column: 1 / -1; }

  /* achievement toasts: below the hint while playing, in the free strip above an open panel otherwise */
  #toasts { top: calc(max(8px, var(--safe-top)) + 86px); }
  /* a friend's score sits under the HUD: the hint and toasts move down past it, so narrow phones don't overlap them */
  body:where(:has(#rival:not(.hidden))) #hint { top: calc(max(8px, var(--safe-top)) + 80px); }
  body:where(:has(#rival:not(.hidden))) #toasts { top: calc(max(8px, var(--safe-top)) + 112px); }
  body:has(> .overlay:not(.hidden)) #toasts { top: max(6px, var(--safe-top)); }
  .toast { padding: 4px 14px 4px 4px; gap: 8px; font-size: 14px; }
  .toast .icon { width: 28px; height: 28px; font-size: 15px; }
}

/* Phones in landscape with the browser's toolbars showing (about 290px tall): tighter still. */
@container (max-height: 340px) {
  .panel { padding: 16px 16px 8px; }
  .panel-foot { margin: 4px -16px 0; padding: 4px 16px 8px; }
  h1 { font-size: 28px; }
  h2 { font-size: 23px; }
  .btn { font-size: 14px; padding: 7px 12px; }
  .btn.big { font-size: 15px; padding: 8px 16px; }
  .panel p { font-size: 13px; margin: 4px 0; }
  .steps { margin-bottom: 2px; }
  .steps i { height: 5px; }
  .welcome-icon { width: 44px; height: 44px; border-radius: 12px; }
  .welcome-story { font-size: 13px; margin: 4px 0; }
  .big-input { font-size: 18px; padding: 6px 12px; margin: 6px 0 8px; }
  /* pause: the four buttons two by two */
  .stack { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
  .settings-list { margin: 4px 0 6px; }
  .setting { padding: 4px 2px; }
  .challenge-panel .big-avatar svg { width: 60px; height: 60px; box-shadow: 0 0 0 3px #fff, 0 4px 0 3px #d8c7a6; }
  .ch-text { font-size: 16px; margin-top: 2px; }
  .ch-stars { font-size: 22px; line-height: 1.1; }
  .ch-question { font-size: 15px; margin: 2px 0 8px; }
  .avatar-grid { grid-template-rows: auto; margin-top: 6px; }
  .end-panel { padding: 16px 16px 12px; gap: 14px; }
  .end-panel #endStars { font-size: 26px; }
  .end-panel #endScore { font-size: 19px; margin-bottom: 2px; }
  .end-actions { gap: 6px; }
  .share-body img { height: 120px; }
  .share-actions { gap: 6px; }
  .share-tip { display: none; }
}

/* Typing a name on a phone held sideways: the on-screen keyboard leaves about 100px,
   so the panel shrinks to the field and its button, side by side. */
@media (pointer: coarse) {
  @container (max-height: 500px) {
    html:not(.rotated) .overlay:has(input:focus) { padding-top: 6px; padding-bottom: 6px; }
    html:not(.rotated) .overlay:has(input:focus) .panel {
      display: flex; flex-wrap: nowrap; align-items: center; gap: 10px;
      padding: 16px 12px 8px; overflow: hidden;
    }
    html:not(.rotated) .overlay:has(input:focus) .panel > :is(.steps, h2, p, .avatar-grid) { display: none; }
    html:not(.rotated) .overlay:has(input:focus) .panel > :is(.big-input, .name-row) { flex: 1 1 0; min-width: 0; margin: 0; }
    html:not(.rotated) .overlay:has(input:focus) .panel > .panel-foot { position: static; flex: none; margin: 0; padding: 0; background: none; box-shadow: none; }
    html:not(.rotated) .overlay:has(input:focus) .panel-foot::before,
    html:not(.rotated) .overlay:has(input:focus) .scroll-cue,
    html:not(.rotated) .overlay:has(input:focus) .scroll-track { display: none; }
    html:not(.rotated) .overlay:has(input:focus) .btn.big { width: auto; }
  }
}

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