/* Rolling Rob 3D - page and HUD styles.
   body.mode-2d reproduces the original page's HUD; body.mode-3d is the new HUD. */
:root {
  --gold: #FFD700;
  --ink: #0b0d14;
  --panel: rgba(12, 14, 22, 0.72);
  --accent: #ffb300;
  --ui-font: "Avenir Next", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0; padding: 0; overflow: hidden; background: #000; color: #fff;
  font-family: Arial, sans-serif;
  touch-action: none; user-select: none; -webkit-user-select: none; overscroll-behavior: none;
}
#stage { position: fixed; inset: 0; background: #000; }
#stage canvas { position: absolute; display: block; outline: none; }
#view3d { inset: 0; width: 100%; height: 100%; }
#view2d { left: 50%; top: 50%; transform: translate(-50%, -50%); cursor: crosshair; }
body.mode-3d #view2d { display: none; }
body.mode-2d #view3d { display: none; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud button, #hud select { pointer-events: auto; }

/* ------------------------------------------------------------------ 2D skin (original) */
body.mode-2d #title {
  position: absolute; top: 10px; right: 20px; font-size: 32px; font-weight: bold;
  color: var(--gold); text-shadow: 3px 3px 6px rgba(0,0,0,0.8);
}
body.mode-2d #levelSelect { position: absolute; top: 50px; right: 20px; font-size: 16px; color: #FFF; }
body.mode-2d #levelSelect select {
  font-size: 14px; padding: 5px 10px; margin-left: 8px; background: rgba(0,0,0,0.8); color: #FFF;
  border: 2px solid var(--gold); border-radius: 5px;
}
body.mode-2d #score {
  position: absolute; top: 20px; left: 20px; font-size: 28px; font-weight: bold;
  color: var(--gold); text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
}
body.mode-2d #info {
  position: absolute; bottom: 80px; left: 50%; transform: translateX(-50%); font-size: 28px;
  color: #FFF; text-shadow: 3px 3px 6px rgba(0,0,0,1); max-width: 900px; width: max-content;
  text-align: center; background: rgba(0,0,0,0.6); padding: 15px 30px; border-radius: 10px;
}
body.mode-2d #buttons { position: absolute; bottom: 20px; left: 0; right: 0; display: flex; justify-content: center; gap: 14px; }
body.mode-2d #buttons button {
  padding: 12px 25px; font-size: 18px; cursor: pointer; background: #4CAF50; color: white;
  border: 2px solid var(--gold); border-radius: 5px; box-shadow: 0 4px 8px rgba(0,0,0,0.5);
}
body.mode-2d #buttons button:hover { background: #45a049; transform: scale(1.05); }
body.mode-2d #buttons button:active { transform: translateY(2px) scale(1.05); }
body.mode-2d #progress, body.mode-2d #levelBadge, body.mode-2d #charge, body.mode-2d #levelCard { display: none; }
body.mode-2d #menuBtn { top: calc(84px + var(--safe-t)); }
@media (max-width: 900px) {
  body.mode-2d #title { font-size: 18px; }
  body.mode-2d #score { font-size: 16px; top: 10px; left: 10px; }
  body.mode-2d #info { font-size: 15px; padding: 8px 14px; max-width: 92vw; bottom: 70px; }
  body.mode-2d #levelSelect { top: 34px; font-size: 13px; }
  body.mode-2d #buttons button { padding: 8px 16px; font-size: 15px; }
}

/* ------------------------------------------------------------------ 3D skin */
body.mode-3d #hud { font-family: var(--ui-font); }
body.mode-3d #scoreBox {
  position: absolute; top: calc(14px + var(--safe-t)); left: calc(16px + var(--safe-l));
  padding: 10px 16px 12px; border-radius: 16px; min-width: 250px;
  background: linear-gradient(180deg, rgba(14,16,26,0.78), rgba(14,16,26,0.52));
  border: 1px solid rgba(255,215,0,0.35);
  box-shadow: 0 8px 28px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.12);
  backdrop-filter: blur(10px) saturate(1.3); -webkit-backdrop-filter: blur(10px) saturate(1.3);
}
body.mode-3d #score {
  font-size: 19px; font-weight: 800; letter-spacing: 0.02em; color: var(--gold);
  text-shadow: 0 2px 6px rgba(0,0,0,0.7); font-variant-numeric: tabular-nums; white-space: nowrap;
}
#progress { position: relative; height: 8px; margin-top: 9px; border-radius: 6px; background: rgba(255,255,255,0.16); }
#progressFill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 6px;
  background: linear-gradient(90deg, #ff8a00, #ffd700); box-shadow: 0 0 10px rgba(255,190,0,0.7); }
#progressMarks { position: absolute; inset: 0; }
#progressMarks i { position: absolute; top: -3px; width: 3px; height: 14px; border-radius: 2px; background: #ff5a5a; transform: translateX(-1px); }
#progressMarks i.on { background: #4dff88; box-shadow: 0 0 8px #4dff88; }
#progressRob { position: absolute; top: 50%; left: 0; width: 16px; height: 16px; border-radius: 50%;
  transform: translate(-50%, -50%); background: radial-gradient(circle at 35% 30%, #666, #111 60%);
  border: 2px solid var(--gold); box-shadow: 0 2px 6px rgba(0,0,0,0.6); }

body.mode-3d #titleBox { position: absolute; top: calc(14px + var(--safe-t)); right: calc(76px + var(--safe-r)); text-align: right; }
body.mode-3d #title {
  font-size: 17px; font-weight: 900; letter-spacing: 0.06em; text-transform: uppercase; color: var(--gold);
  text-shadow: 0 2px 8px rgba(0,0,0,0.8), 0 0 18px rgba(255,180,0,0.35);
}
body.mode-3d #levelBadge { margin-top: 3px; font-size: 14px; font-weight: 700; color: #fff; opacity: 0.92; text-shadow: 0 2px 6px rgba(0,0,0,0.85); }
body.mode-3d #levelSelect { display: none; }

#menuBtn {
  position: absolute; top: calc(14px + var(--safe-t)); right: calc(16px + var(--safe-r)); width: 48px; height: 48px;
  border-radius: 14px; border: 1px solid rgba(255,215,0,0.45); background: rgba(14,16,26,0.66); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; padding: 0;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: 0 6px 18px rgba(0,0,0,0.35);
}
#menuBtn span { display: block; width: 20px; height: 3px; border-radius: 2px; background: var(--gold); }
#menuBtn:hover { background: rgba(40,44,66,0.8); }

body.mode-3d #info {
  position: absolute; left: 50%; top: calc(16px + var(--safe-t)); transform: translateX(-50%);
  max-width: min(520px, 36vw); width: max-content; text-align: center;
  font-size: clamp(12px, 1.3vw, 17px); font-weight: 700; color: #fff; padding: 12px 26px; border-radius: 16px;
  background: linear-gradient(180deg, rgba(14,16,26,0.74), rgba(14,16,26,0.5));
  border: 1px solid rgba(255,255,255,0.14);
  text-shadow: 0 2px 6px rgba(0,0,0,0.9);
  backdrop-filter: blur(10px) saturate(1.3); -webkit-backdrop-filter: blur(10px) saturate(1.3);
  transition: opacity 0.6s ease, transform 0.25s cubic-bezier(.2,1.6,.4,1);
}
body.mode-3d #info.quiet { opacity: 0.0; }
body.mode-3d #info.pop { transform: translateX(-50%) scale(1.06); }
/* death and victory messages come forward */
body.mode-3d.state-dead #info, body.mode-3d.state-won #info { top: auto; bottom: calc(92px + var(--safe-b)); max-width: min(900px, 92vw); font-size: clamp(15px, 2.1vw, 24px); }
body.mode-3d #info.bad { border-color: rgba(255,80,60,0.7); box-shadow: 0 0 34px rgba(255,60,30,0.35); }
body.mode-3d #info.good { border-color: rgba(255,215,0,0.8); box-shadow: 0 0 34px rgba(255,200,0,0.35); }

body.mode-3d #buttons { position: absolute; left: 0; right: 0; bottom: calc(22px + var(--safe-b)); display: flex; justify-content: center; gap: 14px; }
body.mode-3d #buttons button {
  font-family: var(--ui-font); font-size: 16px; font-weight: 800; letter-spacing: 0.03em; padding: 12px 24px; cursor: pointer; color: #fff;
  border-radius: 14px; border: 1px solid rgba(255,215,0,0.6);
  background: linear-gradient(180deg, #4fbf58, #2f8f3b); box-shadow: 0 6px 0 #1d5d27, 0 12px 22px rgba(0,0,0,0.4);
  transition: transform 0.08s, box-shadow 0.08s, filter 0.2s;
}
body.mode-3d #buttons button:hover { filter: brightness(1.12); }
body.mode-3d #buttons button:active { transform: translateY(4px); box-shadow: 0 2px 0 #1d5d27, 0 6px 12px rgba(0,0,0,0.4); }
/* while you ride the Reset button waits in the corner; when Rob is dead it comes to the middle */
body.mode-3d.state-run #buttons, body.mode-3d.state-ready #buttons { justify-content: flex-start; padding-left: calc(16px + var(--safe-l)); bottom: calc(14px + var(--safe-b)); }
body.mode-3d #buttons #resetBtn { opacity: 0.6; transform: scale(0.8); transform-origin: 0 100%; }
body.mode-3d.state-dead #buttons #resetBtn { opacity: 1; transform: scale(1.12); transform-origin: 50% 100%; animation: pulse 0.9s ease-in-out infinite; }
body.mode-3d #buttons #nextBtn { background: linear-gradient(180deg, #ffc531, #f08a00); box-shadow: 0 6px 0 #9a5600, 0 12px 22px rgba(0,0,0,0.4); }
@keyframes pulse { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.35); } }

/* charge meter (text is the original's) */
#charge {
  position: absolute; left: 50%; bottom: calc(150px + var(--safe-b)); width: min(300px, 70vw); height: 40px; transform: translateX(-50%) scale(0.9);
  border-radius: 12px; border: 3px solid var(--gold); background: rgba(0,0,0,0.7); overflow: hidden; opacity: 0; visibility: hidden;
  box-shadow: 0 0 24px rgba(255,200,0,0.4);
}
#charge.on { opacity: 1; visibility: visible; transform: translateX(-50%) scale(1); }
#chargeFill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: #f00; }
#chargeLabel { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 18px; letter-spacing: 0.08em; color: #fff; text-shadow: 0 2px 4px #000; }

/* level title card */
#levelCard { position: absolute; left: 0; right: 0; top: 24%; text-align: center; opacity: 0; pointer-events: none; transform: translateY(14px) scale(0.96); }
#levelCard.show { animation: card 3.2s cubic-bezier(.2,.9,.2,1) forwards; }
#levelCardNum { font-family: var(--ui-font); font-size: clamp(14px, 2vw, 22px); font-weight: 800; letter-spacing: 0.5em; text-transform: uppercase; color: var(--gold); text-shadow: 0 2px 10px rgba(0,0,0,0.9); }
#levelCardName { font-family: var(--ui-font); font-size: clamp(34px, 7vw, 92px); font-weight: 900; line-height: 1.05; letter-spacing: 0.01em; color: #fff;
  text-shadow: 0 4px 0 rgba(0,0,0,0.35), 0 10px 40px rgba(0,0,0,0.7), 0 0 60px var(--card-glow, rgba(255,215,0,0.45)); }
@keyframes card {
  0% { opacity: 0; transform: translateY(18px) scale(0.94); }
  12% { opacity: 1; transform: translateY(0) scale(1); }
  78% { opacity: 1; transform: translateY(0) scale(1.02); }
  100% { opacity: 0; transform: translateY(-12px) scale(1.04); }
}

#toast { position: absolute; left: 50%; top: calc(76px + var(--safe-t)); transform: translateX(-50%); font-family: var(--ui-font); font-size: 14px; font-weight: 700;
  padding: 8px 16px; border-radius: 12px; background: rgba(14,16,26,0.8); border: 1px solid rgba(255,255,255,0.18); opacity: 0; transition: opacity 0.3s; white-space: nowrap; }
#toast.show { opacity: 1; }
#fps { position: absolute; left: calc(16px + var(--safe-l)); bottom: calc(10px + var(--safe-b)); font: 12px/1.3 ui-monospace, Menlo, monospace; color: #9f9; text-shadow: 0 1px 2px #000; white-space: pre; display: none; }
body.show-fps #fps { display: block; }

/* ------------------------------------------------------------------ touch controls */
#touch { position: fixed; inset: 0; z-index: 11; pointer-events: none; display: none; }
body.touch #touch { display: block; }
#pad, #act { position: absolute; bottom: calc(18px + var(--safe-b)); display: flex; gap: 12px; align-items: flex-end; }
#pad { left: calc(16px + var(--safe-l)); }
#act { right: calc(16px + var(--safe-r)); }
.tbtn {
  pointer-events: auto; width: 68px; height: 68px; border-radius: 50%; font: 800 20px var(--ui-font); color: #fff;
  border: 2px solid rgba(255,255,255,0.55); background: rgba(20,22,34,0.42); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; touch-action: none; padding: 0;
}
.tbtn.big { width: 92px; height: 92px; font-size: 19px; border-color: var(--gold); color: var(--gold); background: rgba(40,30,0,0.45); }
#tUp { font-size: 12px; letter-spacing: 0.04em; }
#tDown { width: 52px; height: 52px; font-size: 15px; }
.tbtn.down { background: rgba(255,215,0,0.5); transform: scale(0.94); }
body.touch #buttons { bottom: calc(126px + var(--safe-b)); }
/* on a phone the Reset button waits in the corner while you ride and comes forward when needed */
body.touch.mode-3d.state-run #buttons, body.touch.mode-3d.state-ready #buttons { bottom: auto; top: calc(78px + var(--safe-t)); justify-content: flex-start; padding-left: calc(16px + var(--safe-l)); }
body.touch.mode-3d.state-run #buttons #resetBtn, body.touch.mode-3d.state-ready #buttons #resetBtn { transform: scale(0.72); transform-origin: 0 0; }
@media (orientation: portrait) { body.touch.mode-3d.state-run #buttons, body.touch.mode-3d.state-ready #buttons { top: calc(170px + var(--safe-t)); } }
body.touch.mode-3d #info, body.touch.mode-2d #info { bottom: auto; top: calc(78px + var(--safe-t)); font-size: 14px; padding: 8px 14px; max-width: 92vw; }
body.touch #charge { bottom: calc(190px + var(--safe-b)); }
@media (orientation: portrait) {
  .tbtn { width: 62px; height: 62px; }
  .tbtn.big { width: 84px; height: 84px; }
  body.mode-3d #titleBox { top: calc(70px + var(--safe-t)); right: calc(16px + var(--safe-r)); }
  body.mode-3d #title { font-size: 12px; }
  body.mode-3d #scoreBox { min-width: 0; right: calc(76px + var(--safe-r)); }
  body.mode-3d #info { max-width: 92vw; top: calc(118px + var(--safe-t)); }
  body.mode-3d #score { font-size: 15px; }
  body.touch.mode-3d #info, body.touch.mode-2d #info { top: calc(126px + var(--safe-t)); }
}
@media (max-height: 480px) {
  body.mode-3d #title { font-size: 12px; }
  body.mode-3d #score { font-size: 14px; }
  body.mode-3d #scoreBox { padding: 6px 12px 8px; min-width: 200px; }
  .tbtn { width: 58px; height: 58px; }
  .tbtn.big { width: 76px; height: 76px; }
  #levelCard { top: 16%; }
}

/* ------------------------------------------------------------------ pause menu */
#menu { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; font-family: var(--ui-font);
  background: radial-gradient(ellipse at 50% 40%, rgba(10,12,20,0.55), rgba(4,5,10,0.86)); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  padding: calc(10px + var(--safe-t)) calc(10px + var(--safe-r)) calc(10px + var(--safe-b)) calc(10px + var(--safe-l)); }
#menu[hidden] { display: none; }
#menuPanel { width: min(760px, 100%); max-height: 100%; display: flex; flex-direction: column; border-radius: 22px; overflow: hidden;
  background: linear-gradient(180deg, rgba(26,29,46,0.96), rgba(14,16,26,0.96)); border: 1px solid rgba(255,215,0,0.4);
  box-shadow: 0 30px 80px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.1); animation: menuIn 0.18s ease-out; }
@keyframes menuIn { from { transform: translateY(10px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }
#menuHead { padding: 18px 24px 12px; border-bottom: 1px solid rgba(255,255,255,0.08); display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
#menuTitle { font-size: 28px; font-weight: 900; color: var(--gold); letter-spacing: 0.04em; text-transform: uppercase; }
#menuSub { font-size: 13px; font-weight: 700; opacity: 0.6; letter-spacing: 0.08em; text-transform: uppercase; }
#menuBody { padding: 8px 24px 20px; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
#menuBody section { padding: 10px 0; }
#menuBody h3 { margin: 0 0 8px; font-size: 12px; letter-spacing: 0.18em; text-transform: uppercase; color: rgba(255,255,255,0.55); }
.row { display: flex; flex-wrap: wrap; gap: 10px; }
.mbtn { font: 700 15px var(--ui-font); color: #fff; padding: 11px 16px; border-radius: 12px; cursor: pointer; border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.07); transition: background 0.12s, border-color 0.12s, transform 0.06s; flex: 1 1 auto; min-height: 44px; }
.mbtn:hover, .mbtn:focus-visible { background: rgba(255,255,255,0.16); border-color: rgba(255,215,0,0.7); outline: none; }
.mbtn:active { transform: translateY(1px); }
.mbtn.primary { background: linear-gradient(180deg, #ffc531, #f08a00); border-color: #ffe08a; color: #231300; }
.mbtn.sel { background: rgba(255,200,0,0.22); border-color: var(--gold); color: var(--gold); }
.mbtn kbd { font: 700 11px ui-monospace, Menlo, monospace; padding: 2px 6px; margin-left: 6px; border-radius: 5px; background: rgba(0,0,0,0.3); border: 1px solid rgba(255,255,255,0.25); }
.mbtn.primary kbd { color: #fff; }
#mLevels { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.lvl { position: relative; min-height: 64px; padding: 8px 8px 8px 10px; border-radius: 12px; text-align: left; cursor: pointer; color: #fff; font-family: var(--ui-font);
  border: 1px solid rgba(255,255,255,0.2); overflow: hidden; background: #222; transition: transform 0.08s, border-color 0.12s; }
.lvl:hover, .lvl:focus-visible { transform: translateY(-2px); border-color: var(--gold); outline: none; }
.lvl.sel { border: 2px solid var(--gold); box-shadow: 0 0 18px rgba(255,200,0,0.4); }
.lvl b { display: block; font-size: 20px; font-weight: 900; text-shadow: 0 2px 4px rgba(0,0,0,0.6); }
.lvl span { display: block; font-size: 11px; font-weight: 700; line-height: 1.15; text-shadow: 0 1px 3px rgba(0,0,0,0.8); }
.lvl em { display: block; font-size: 10px; font-style: normal; opacity: 0.8; text-transform: uppercase; letter-spacing: 0.1em; text-shadow: 0 1px 3px rgba(0,0,0,0.8); }
.hint { font-size: 13px; line-height: 1.5; color: rgba(255,255,255,0.68); margin-top: 8px; }
.slider { display: flex; align-items: center; gap: 12px; font-size: 14px; font-weight: 600; margin-top: 10px; color: rgba(255,255,255,0.85); }
.slider input { flex: 1; accent-color: var(--gold); height: 28px; }
@media (max-width: 620px) {
  #mLevels { grid-template-columns: repeat(2, 1fr); }
  #menuTitle { font-size: 22px; }
  #menuSub { display: none; }
  #menuBody { padding: 6px 14px 14px; }
}
@media (max-height: 480px) { #menuHead { padding: 8px 18px 6px; } #menuTitle { font-size: 18px; } #mLevels { grid-template-columns: repeat(5, 1fr); } .lvl { min-height: 48px; } }

/* ------------------------------------------------------------------ fade + boot */
#fade { position: fixed; inset: 0; z-index: 20; background: #000; opacity: 0; pointer-events: none; }
#boot { position: fixed; inset: 0; z-index: 40; background: radial-gradient(ellipse at 50% 40%, #1b2340, #05060b 70%); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  font-family: var(--ui-font); transition: opacity 0.5s; }
body:not(.booting) #boot { opacity: 0; pointer-events: none; }
#bootBall { width: 72px; height: 72px; border-radius: 50%; background: radial-gradient(circle at 34% 30%, #6a6a6a, #151515 58%, #000); border: 3px solid var(--gold); animation: roll 1.1s linear infinite; position: relative; }
#bootBall::after { content: ""; position: absolute; left: 18px; top: 22px; width: 12px; height: 12px; border-radius: 50%; background: var(--gold); box-shadow: 22px 0 0 var(--gold); }
@keyframes roll { to { transform: rotate(360deg); } }
#bootText { font-size: 22px; font-weight: 900; letter-spacing: 0.2em; text-transform: uppercase; color: var(--gold); }
#bootBar { width: min(320px, 70vw); height: 6px; border-radius: 4px; background: rgba(255,255,255,0.14); overflow: hidden; }
#bootFill { width: 0; height: 100%; background: linear-gradient(90deg, #ff8a00, #ffd700); transition: width 0.2s; }
