* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: #14161c;
  color: #e8e8e8;
  font-family: "Segoe UI", Verdana, sans-serif;
  display: flex;
  justify-content: center;
  padding: 12px;
}

#game-wrap { width: 960px; max-width: 100%; }

/* Stick RPG-style transparent HUD strip */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 14px;
  pointer-events: none;
  z-index: 4;
}

.hud-vital { display: flex; align-items: center; gap: 7px; }
.heart { font-size: 28px; filter: drop-shadow(2px 2px 1px rgba(0,0,0,.55)); }
.vbars { display: flex; flex-direction: column; gap: 3px; }
.hptrack {
  position: relative;
  width: 250px; height: 17px;
  background: #4a0d0a;
  border: 2px solid #151515;
  transform: skewX(-30deg);
  overflow: hidden;
  box-shadow: 2px 2px 2px rgba(0,0,0,.4);
}
.hpfill { position: absolute; top: 0; left: 0; bottom: 0; background: linear-gradient(#ff5040 0 55%, #cc1408 55%); transition: width .25s; }
.hpnum { position: absolute; inset: 0; text-align: center; transform: skewX(30deg); color: #fff; font-weight: 900; font-size: 12px; line-height: 14px; text-shadow: 1px 1px 0 #000; }
.entrack {
  position: relative;
  width: 180px; height: 8px;
  background: #0a2038;
  border: 2px solid #151515;
  transform: skewX(-30deg);
  overflow: hidden;
}
.enfill { position: absolute; top: 0; left: 0; bottom: 0; background: linear-gradient(#5ee0ff, #1e78d0); transition: width .25s; }

.money {
  font-family: 'Arial Black', Arial, sans-serif;
  font-weight: 900;
  font-size: 26px;
  color: #ffcf4a;
  text-shadow: 2px 2px 0 #7a4a00, 3px 3px 3px rgba(0,0,0,.45);
  letter-spacing: 1px;
  white-space: nowrap;
}
.money .dollar { font-size: 32px; color: #f0b232; margin-right: 3px; }

.daytime { display: flex; align-items: center; gap: 10px; }
#clock {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 3px solid #8a8a8a;
  box-shadow: 2px 2px 3px rgba(0,0,0,.4), inset 0 0 4px rgba(0,0,0,.35);
  background: conic-gradient(#2a2ae0 0deg 120deg, #f2f2f2 120deg 360deg);
}
/* late night: the clock burns red as the midnight blackout closes in */
#clock.late {
  border-color: #ff5040;
  animation: latepulse 1s ease-in-out infinite;
}
@keyframes latepulse {
  0%, 100% { box-shadow: 2px 2px 3px rgba(0,0,0,.4), 0 0 6px rgba(255,64,48,.6); }
  50% { box-shadow: 2px 2px 3px rgba(0,0,0,.4), 0 0 16px rgba(255,64,48,1); }
}
.daycol #st-time.late { color: #ff7a68; font-weight: 900; }
.daycol { display: flex; flex-direction: column; line-height: 1.05; }
.daylabel {
  font-family: 'Arial Black', Arial, sans-serif;
  font-style: italic;
  font-weight: 900;
  font-size: 22px;
  color: #2853e8;
  text-shadow: 2px 2px 0 rgba(255,255,255,.5), 3px 3px 2px rgba(0,0,0,.35);
  white-space: nowrap;
}
.daycol #st-time { font-size: 10.5px; color: #fff; text-shadow: 1px 1px 1px #000; font-weight: 700; }

.hud-right { display: flex; align-items: center; gap: 10px; pointer-events: auto; }
#msg-alert {
  font-size: 15px;
  font-weight: 900;
  color: #fff;
  background: linear-gradient(#ff5a4d, #d61f12);
  border: 2px solid #fff;
  border-radius: 20px;
  padding: 2px 10px 3px;
  box-shadow: 0 2px 6px rgba(0,0,0,.5);
  white-space: nowrap;
  cursor: pointer; /* it's tappable — plays your voicemail */
  animation: msgpulse 1.1s ease-in-out infinite;
}
#msg-alert:active { filter: brightness(1.15); }
@keyframes msgpulse { 0%,100% { transform: scale(1); box-shadow: 0 2px 6px rgba(0,0,0,.5); } 50% { transform: scale(1.09); box-shadow: 0 2px 14px rgba(255,80,70,.9); } }
.vmail-from { display: block; font-weight: 900; color: #071233; margin-bottom: 6px; font-size: 15px; }
.hud-right button {
  background: none;
  border: none;
  font-size: 30px;
  cursor: pointer;
  padding: 0;
  filter: drop-shadow(2px 2px 2px rgba(0,0,0,.5));
  transition: transform .1s;
}
#btn-stats { font-size: 24px; }
.hud-right button:hover { transform: scale(1.15); }

/* level-up announcement — a celebratory splash that flashes above everything,
   with a dark scrim so it stays legible even over an open dialog */
#levelup {
  position: absolute;
  top: 26%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  z-index: 9;
  padding: 14px 30px;
  border-radius: 18px;
  background: radial-gradient(120% 120% at 50% 40%, rgba(8,12,30,.82), rgba(8,12,30,.4) 75%, rgba(8,12,30,0));
  animation: lvlfade 1.5s ease-out forwards;
}
#levelup.hidden { display: none; }
@keyframes lvlfade { 0%, 72% { opacity: 1; } 100% { opacity: 0; } }
#levelup-room { font-weight: 900; color: #dbe8ff; font-size: 15px; letter-spacing: 2px; text-shadow: 1px 1px 0 #2d4fae, 2px 2px 3px rgba(0,0,0,.6); }
#levelup-text {
  font-family: 'Arial Black', Arial, sans-serif;
  font-size: 30px; font-weight: 900; color: #fff;
  text-shadow: 2px 2px 0 #2d4fae, 4px 4px 6px rgba(0,0,0,.55);
  animation: lvlpop .5s cubic-bezier(.2, 1.6, .4, 1);
}
#levelup-val { font-size: 26px; font-weight: 900; color: #ffd75e; text-shadow: 2px 2px 2px #000; animation: lvlval 1.3s; }
@keyframes lvlpop { from { transform: scale(.2); opacity: 0; } }
@keyframes lvlval { 0% { transform: scale(1); } 30% { transform: scale(1.9); } 65% { transform: scale(1); } }

#panel button {
  background: linear-gradient(#ffffff, #dbe7ff);
  color: #12276e;
  border: 2px solid rgba(255, 255, 255, .95);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 3px 0 #2c4aa0, 0 6px 10px rgba(3, 10, 40, .28);
  transition: transform .08s ease, box-shadow .08s ease, filter .08s ease;
}
#panel button:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.04); box-shadow: 0 5px 0 #2c4aa0, 0 9px 15px rgba(3, 10, 40, .35); }
#panel button:active:not(:disabled) { transform: translateY(1px); box-shadow: 0 2px 0 #2c4aa0, 0 4px 7px rgba(3, 10, 40, .28); }
#panel button:disabled { opacity: .5; cursor: default; box-shadow: 0 2px 0 rgba(44, 74, 160, .5); }

/* character creator */
.cc-row { display: flex; align-items: center; gap: 12px; font-weight: 800; font-size: 18px; color: #0d2a8f; margin: 8px 0; }
.cc-row .cc-label { width: 175px; color: #dbe8ff; text-shadow: 1px 1px 0 #2d4fae; font-size: 17px; letter-spacing: .5px; }
.cc-row .cc-val { min-width: 34px; text-align: center; font-size: 22px; color: #08103a; }
.cc-arrow { font-size: 15px !important; padding: 4px 10px !important; border-radius: 9px !important; background: rgba(255,255,255,.3) !important; border: 2px solid rgba(255,255,255,.6) !important; color: #0d2a8f !important; font-weight: 900; }
#cc-name {
  font-size: 17px; font-weight: 800; padding: 5px 10px;
  border: 2px solid #111; border-radius: 4px; width: 240px;
  font-family: inherit;
}

#canvas-holder { position: relative; }
canvas {
  display: block;
  background: #222;
  border: 1px solid #343a48;
  border-radius: 8px;
  width: 100%;
}

#panel {
  position: absolute;
  inset: 0;
  z-index: 3;
  background: rgba(6, 10, 24, .18);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  border-radius: 0 0 8px 8px;
}
#panel.hidden { display: none; }

/* Stick RPG-style dialog, dressed up like a proper game panel */
#panel-inner {
  position: relative;
  background:
    radial-gradient(140% 90% at 50% -10%, rgba(255, 255, 255, .35), rgba(255, 255, 255, 0) 55%),
    linear-gradient(165deg, #6fa8f6 0%, #517fe2 52%, #3f63c6 100%);
  border: 2px solid rgba(255, 255, 255, .6);
  border-radius: 22px;
  padding: 22px 24px 24px;
  width: 560px;
  max-width: 92%;
  max-height: 88%;
  overflow-y: auto;
  margin-right: 26px;
  color: #08103a;
  box-shadow:
    0 20px 60px rgba(3, 8, 32, .6),
    0 0 0 5px rgba(28, 54, 132, .35),
    inset 0 2px 0 rgba(255, 255, 255, .5),
    inset 0 -18px 40px rgba(20, 40, 110, .35);
}
#panel-inner h2 {
  color: #fff;
  text-shadow: 0 2px 0 #2a49a4, 0 4px 10px rgba(0, 8, 40, .5);
  margin-bottom: 12px;
  padding-bottom: 10px;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: .5px;
  border-bottom: 2px solid rgba(255, 255, 255, .35);
}
#panel-inner p { margin: 7px 0; font-size: 14px; color: #0c1c4a; line-height: 1.55; font-weight: 600; }
#panel-inner p.speech { font-size: 16px; font-weight: 800; color: #071233; line-height: 1.55; }
#panel-inner .menu {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 9px;
  margin-top: 12px;
}
#panel-inner .menu button {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  padding: 10px 14px;
  font-size: 14px;
  background: linear-gradient(#ffffff, #dbe7ff);
  border: 2px solid rgba(255, 255, 255, .95);
  border-radius: 14px;
  color: #12276e;
  font-weight: 800;
  box-shadow: 0 4px 0 #2c4aa0, 0 7px 12px rgba(3, 10, 40, .3);
  transition: transform .08s ease, box-shadow .08s ease, filter .08s ease;
}
#panel-inner .menu button:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.04);
  box-shadow: 0 6px 0 #2c4aa0, 0 11px 18px rgba(3, 10, 40, .38);
}
#panel-inner .menu button:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #2c4aa0, 0 4px 8px rgba(3, 10, 40, .3);
}
#panel-inner .menu button:disabled { opacity: .5; box-shadow: 0 3px 0 rgba(44, 74, 160, .5); }
/* the "Leave / Back / cancel" action reads as secondary */
#panel-inner .menu button.cancel {
  background: linear-gradient(#eef2fb, #c3ceea);
  color: #33406a;
  box-shadow: 0 4px 0 #6577a8, 0 7px 12px rgba(3, 10, 40, .25);
}
#panel-inner .menu button.cancel:hover:not(:disabled) { box-shadow: 0 6px 0 #6577a8, 0 11px 18px rgba(3, 10, 40, .32); }
#panel-inner .menu button.cancel:active:not(:disabled) { box-shadow: 0 2px 0 #6577a8, 0 4px 8px rgba(3, 10, 40, .25); }
#panel-inner button .ico {
  flex: 0 0 46px;
  height: 46px;
  background: linear-gradient(#ffffff, #cfe2ff);
  border: 2px solid #8fb0e6;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 25px;
  box-shadow: inset 0 2px 2px rgba(255, 255, 255, .9), inset 0 -3px 5px rgba(80, 120, 200, .3);
}
#panel-inner button .lbl { flex: 1; }
#panel-inner .menu button .sub { display: block; font-size: 11.5px; color: #4a5b86; font-weight: 600; margin-top: 1px; }
/* the "why is this locked" line on disabled options */
#panel-inner .menu button .sub.lock-why { color: #8f1610; font-weight: 800; }
#panel-inner .menu button:disabled { opacity: .62; }
/* leaderboard table */
table.lb { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 13.5px; }
table.lb td { padding: 5px 7px; font-weight: 700; color: #0c1c4a; border-bottom: 1px solid rgba(255,255,255,.28); white-space: nowrap; }
table.lb tr:first-child td { background: rgba(255,255,255,.22); }
table.lb .lb-pos { width: 34px; text-align: center; font-size: 15px; }
table.lb .lb-name { max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
table.lb .lb-name .lb-day { display: block; font-size: 10.5px; font-weight: 600; color: #3f5387; }
table.lb .lb-score { text-align: right; font-size: 15px; color: #071233; }
table.lb .lb-rank { font-size: 11px; color: #2c3f74; }

/* character sheet: built to be read at a glance */
.stat-row { display: flex; align-items: center; gap: 11px; margin: 10px 0; font-weight: 800; color: #0c1c4a; }
.stat-ico { flex: 0 0 28px; text-align: center; font-size: 21px; filter: drop-shadow(1px 1px 1px rgba(0,10,40,.3)); }
.stat-name { flex: 0 0 118px; font-size: 16.5px; }
.stat-track {
  flex: 1;
  height: 16px;
  background: rgba(8, 16, 58, .42);
  border-radius: 9px;
  overflow: hidden;
  box-shadow: inset 0 2px 3px rgba(0, 6, 30, .45);
}
.stat-fill { display: block; height: 100%; border-radius: 9px; box-shadow: inset 0 -4px 5px rgba(0, 10, 40, .25); transition: width .3s; }
.stat-val { flex: 0 0 40px; text-align: right; font-size: 21px; color: #071233; }
.sheet-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 9px; margin-top: 14px; }
.sheet-tile {
  background: rgba(255, 255, 255, .24);
  border: 1.5px solid rgba(255, 255, 255, .45);
  border-radius: 12px;
  padding: 7px 12px 8px;
  min-width: 0;
}
.sheet-tile .t-head { display: block; font-size: 11px; font-weight: 800; color: #2c3f74; text-transform: uppercase; letter-spacing: .6px; margin-bottom: 2px; }
.sheet-tile .t-val { display: block; font-size: 17px; font-weight: 800; color: #071233; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-tile .t-val.bank-val { font-size: 22px; }

#panel-inner .fight-hp { margin: 8px 0; font-size: 14px; font-weight: 800; }
#panel-inner .fight-hp .bar { width: 100%; margin-top: 3px; background: rgba(8, 16, 58, .55); }
#panel-inner #fight-menu button {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  padding: 10px 14px;
  background: linear-gradient(#ffffff, #dbe7ff);
  border: 2px solid rgba(255, 255, 255, .95);
  border-radius: 14px;
  color: #12276e;
  font-weight: 800;
  box-shadow: 0 4px 0 #2c4aa0, 0 7px 12px rgba(3, 10, 40, .3);
}
#panel-inner .kbd { background: #fff; color: #0d2a8f; border-radius: 5px; padding: 1px 7px; font-family: monospace; font-weight: 700; box-shadow: 0 2px 0 rgba(45, 79, 174, .6); }

#log {
  position: absolute;
  bottom: 56px; /* lower-center, above the "Press E" hint pill */
  left: 50%;
  transform: translateX(-50%);
  width: 430px;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  z-index: 7; /* above dialogs so messages are never hidden mid-menu */
}
#log .msg { max-width: 100%; }
#log .msg {
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(100deg, rgba(10, 14, 28, .95), rgba(20, 30, 58, .88));
  border: 1px solid rgba(255, 255, 255, .16);
  border-left: 4px solid #ffd75e;
  padding: 8px 14px 8px 9px;
  font-size: 14px;
  font-weight: 600;
  color: #f2f4fa;
  border-radius: 12px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .4), inset 0 1px 0 rgba(255, 255, 255, .08);
  animation: toastin .32s cubic-bezier(.2, 1.5, .4, 1);
}
#log .micon {
  flex: 0 0 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: #1a1a06;
  background: radial-gradient(circle at 35% 30%, #ffe9a0, #f0b232);
  box-shadow: 0 2px 5px rgba(0, 0, 0, .4);
}
#log .mcount { font-weight: 900; color: #ffd75e; margin-left: 2px; white-space: nowrap; }
#log .mcount:empty { display: none; }
#log .msg.good { border-left-color: #57d977; }
#log .msg.good .micon { background: radial-gradient(circle at 35% 30%, #a7f0b9, #2eaf52); color: #06250f; }
#log .msg.bad { border-left-color: #e0483e; }
#log .msg.bad .micon { background: radial-gradient(circle at 35% 30%, #ffb3aa, #cc2c22); color: #fff; }
#log .msg.out { animation: toastout .45s ease forwards; }
@keyframes toastin { from { opacity: 0; transform: translateY(14px) scale(.94); } }
@keyframes toastout { to { opacity: 0; transform: translateY(10px) scale(.96); } }
/* fullscreen: toasts scale up with the rest of the UI */
#canvas-holder:fullscreen #log,
#canvas-holder:-webkit-full-screen #log {
  bottom: calc(76px + var(--stage-y, 0px));
  transform: translateX(-50%) scale(var(--ui-scale, 1));
  transform-origin: bottom center;
}

#hint {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(12, 14, 20, .85);
  border: 1px solid #4a5468;
  padding: 5px 14px;
  border-radius: 16px;
  font-size: 13px;
  pointer-events: none;
}
#hint:empty { display: none; }

/* release stamp so players can tell when a new build landed */
#version {
  position: absolute;
  top: 62px;
  right: 12px;
  font-family: 'Arial Black', Arial, sans-serif;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 1px;
  color: #ffd75e;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, .75), 0 0 8px rgba(0, 0, 0, .5);
  pointer-events: none;
  z-index: 4;
}

/* gamepad focus highlight */
#panel button.gp-focus {
  outline: 3px solid #ffd75e;
  outline-offset: 2px;
  transform: translateY(-2px);
  filter: brightness(1.05);
  box-shadow: 0 6px 0 #2c4aa0, 0 0 16px rgba(255, 215, 94, .7);
}

/* fullscreen: fill the whole display (tiny top/bottom crop beats black
   pillars) and scale the UI overlays up with it via --ui-scale */
#canvas-holder:fullscreen,
#canvas-holder:-webkit-full-screen {
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
#canvas-holder:fullscreen canvas,
#canvas-holder:-webkit-full-screen canvas {
  width: 100vw;
  height: 100vh;
  /* cover by default; game.js flips this to contain (inline style) on
     screens so wide/tall that covering would crop off real scenery */
  object-fit: cover;
  background: #000;
  border: none;
  border-radius: 0;
}
/* when the canvas is letterboxed (contain), --stage-x/--stage-y hold the
   bar sizes; pin every overlay to the visible game area, not the screen */
#canvas-holder:fullscreen #panel,
#canvas-holder:-webkit-full-screen #panel {
  left: var(--stage-x, 0px);
  right: var(--stage-x, 0px);
  top: var(--stage-y, 0px);
  bottom: var(--stage-y, 0px);
}
#canvas-holder:fullscreen #hud,
#canvas-holder:-webkit-full-screen #hud {
  left: var(--stage-x, 0px);
  right: var(--stage-x, 0px);
  top: var(--stage-y, 0px);
}
#canvas-holder:fullscreen #version,
#canvas-holder:-webkit-full-screen #version {
  right: calc(12px + var(--stage-x, 0px));
  top: calc(62px + var(--stage-y, 0px));
}
#canvas-holder:fullscreen #panel-inner,
#canvas-holder:-webkit-full-screen #panel-inner {
  transform: scale(var(--ui-scale, 1));
  transform-origin: right center;
}
#canvas-holder:fullscreen #panel.title-menu #panel-inner,
#canvas-holder:-webkit-full-screen #panel.title-menu #panel-inner {
  transform-origin: right bottom;
}
#canvas-holder:fullscreen #hint,
#canvas-holder:-webkit-full-screen #hint {
  transform: translateX(-50%) scale(var(--ui-scale, 1));
  transform-origin: center bottom;
  bottom: calc(18px + var(--stage-y, 0px));
}
#btn-fs { font-size: 26px; color: #fff; text-shadow: 1px 1px 2px #000; }

/* title screens: a compact card tucked bottom-right so the logo, moon,
   skyline, and hero stickman all stay in view */
#panel.title-menu { justify-content: flex-end; align-items: flex-end; background: none; }
#panel.title-menu #panel-inner {
  width: 440px;
  margin: 0 20px 18px 0;
  padding: 14px 16px 16px;
  background:
    radial-gradient(140% 90% at 50% -10%, rgba(255, 255, 255, .3), rgba(255, 255, 255, 0) 55%),
    linear-gradient(165deg, rgba(111, 168, 246, .92) 0%, rgba(81, 127, 226, .92) 52%, rgba(63, 99, 198, .93) 100%);
}
#panel.title-menu #panel-inner h2 { font-size: 19px; margin-bottom: 8px; padding-bottom: 7px; }
#panel.title-menu #panel-inner p { font-size: 12.5px; margin: 4px 0; }
#panel.title-menu #panel-inner .menu { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 7px; margin-top: 10px; }
#panel.title-menu #panel-inner .menu button { padding: 6px 9px; font-size: 13px; }
#panel.title-menu #panel-inner button .ico { flex: 0 0 34px; height: 34px; font-size: 19px; border-radius: 9px; }

/* ============================ touch / mobile ============================ */
/* iOS Safari has no Fullscreen API, so the fill comes from CSS. Also keep
   the page from scrolling or rubber-banding under the game. game.js adds
   body.touch on coarse-pointer devices. */
body.touch {
  padding: 0; margin: 0;
  position: fixed; inset: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
/* dvh/dvw track the *visible* viewport as Safari's toolbars slide in and out,
   so bottom-anchored UI never hides behind the address bar (100vh would). */
body.touch #game-wrap {
  width: 100vw; height: 100vh;
  width: 100dvw; height: 100dvh;
  max-width: none;
}
body.touch #canvas-holder {
  width: 100%; height: 100%;
  background: #000;
  display: flex; align-items: center; justify-content: center;
}
body.touch canvas {
  width: 100vw; height: 100vh;
  width: 100dvw; height: 100dvh;
  object-fit: cover; /* game.js flips to contain when the crop is too big */
  background: #000; border: none; border-radius: 0;
}
/* overlays hug the visible game area (--stage-*) and dodge the notch/home bar */
body.touch #panel {
  left: max(var(--stage-x, 0px), env(safe-area-inset-left));
  right: max(var(--stage-x, 0px), env(safe-area-inset-right));
  top: max(var(--stage-y, 0px), env(safe-area-inset-top));
  bottom: max(var(--stage-y, 0px), env(safe-area-inset-bottom));
}
body.touch #hud {
  left: max(var(--stage-x, 0px), env(safe-area-inset-left));
  right: max(var(--stage-x, 0px), env(safe-area-inset-right));
  top: max(var(--stage-y, 0px), env(safe-area-inset-top));
}
body.touch #version {
  right: calc(12px + max(var(--stage-x, 0px), env(safe-area-inset-right)));
  top: calc(62px + max(var(--stage-y, 0px), env(safe-area-inset-top)));
}
body.touch #panel-inner { transform: scale(var(--ui-scale, 1)); transform-origin: right center; }
body.touch #panel.title-menu #panel-inner { transform-origin: right bottom; }
body.touch #hint {
  transform: translateX(-50%) scale(var(--ui-scale, 1));
  transform-origin: center bottom;
  bottom: calc(18px + max(var(--stage-y, 0px), env(safe-area-inset-bottom)));
}
body.touch #log {
  bottom: calc(120px + max(var(--stage-y, 0px), env(safe-area-inset-bottom)));
  transform: translateX(-50%) scale(var(--ui-scale, 1));
  transform-origin: bottom center;
}
/* dialog open: the panel is right/centre-anchored, so tuck toasts into the
   free top-left corner (the joystick is hidden while a menu is up) */
body.touch.panel-open #log {
  left: calc(10px + max(var(--stage-x, 0px), env(safe-area-inset-left)));
  right: auto; bottom: auto;
  top: calc(64px + max(var(--stage-y, 0px), env(safe-area-inset-top)));
  width: 44vw; max-width: 320px;
  align-items: flex-start;
  transform: scale(var(--ui-scale, 1));
  transform-origin: top left;
}
body.touch #btn-fs { display: none; } /* already fullscreen on a phone */
body.touch .hud-right button { font-size: 34px; }
body.touch #btn-stats { font-size: 28px; }

/* on-screen controls: hidden by default, shown only while actually playing */
#touch-controls { display: none; }
body.touch #touch-controls.playing { display: block; }
#touch-stick {
  position: absolute;
  left: calc(22px + env(safe-area-inset-left));
  bottom: calc(26px + env(safe-area-inset-bottom));
  width: 132px; height: 132px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, rgba(255,255,255,.10), rgba(10,14,28,.34));
  border: 2px solid rgba(255,255,255,.28);
  box-shadow: inset 0 2px 10px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.35);
  touch-action: none;
  z-index: 8;
}
#touch-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 62px; height: 62px;
  margin: -31px 0 0 -31px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #eaf1ff, #9fb6e6);
  border: 2px solid rgba(255,255,255,.7);
  box-shadow: 0 3px 8px rgba(0,0,0,.45);
  pointer-events: none;
  will-change: transform;
}
#touch-interact {
  position: absolute;
  right: calc(30px + env(safe-area-inset-right));
  bottom: calc(42px + env(safe-area-inset-bottom));
  width: 88px; height: 88px;
  border-radius: 50%;
  font-size: 40px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  /* frosted glass, cohesive with the thumbstick */
  background: radial-gradient(circle at 50% 36%, rgba(128,158,228,.55), rgba(10,14,28,.5));
  border: 2px solid rgba(255,255,255,.55);
  box-shadow: inset 0 2px 12px rgba(255,255,255,.18), 0 5px 16px rgba(0,0,0,.42);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  touch-action: none;
  transition: opacity .18s ease, transform .09s ease;
  z-index: 8;
}
/* nothing in reach: fade back so it's clearly idle */
#touch-interact.dim { opacity: .34; }
#touch-interact:active { transform: scale(.9); }
/* a soft pulse-ring to draw the eye when something IS interactable */
#touch-interact:not(.dim)::after {
  content: ''; position: absolute; inset: -3px;
  border-radius: 50%; border: 2px solid rgba(255,231,94,.85);
  animation: tappulse 1.4s ease-in-out infinite;
}
@keyframes tappulse { 0%,100% { opacity: .35; transform: scale(1); } 50% { opacity: .9; transform: scale(1.06); } }

/* "please rotate" — phones held in portrait (the game is a wide top-down city) */
#rotate-hint { display: none; }
@media (orientation: portrait) {
  body.touch #rotate-hint {
    display: flex;
    position: fixed; inset: 0; z-index: 20;
    flex-direction: column; align-items: center; justify-content: center;
    gap: 16px; padding: 24px;
    background: #070a18; color: #dbe8ff; text-align: center;
  }
}
#rotate-hint .rot-emoji { font-size: 68px; animation: rotpulse 1.7s ease-in-out infinite; }
#rotate-hint b { font-size: 21px; letter-spacing: .5px; }
#rotate-hint span { font-size: 14px; color: #7f93c8; }
@keyframes rotpulse { 0%, 100% { transform: rotate(-16deg); } 50% { transform: rotate(16deg); } }
