@font-face {
  font-family: 'Press Start 2P';
  src: url('../assets/fonts/PressStart2P.ttf') format('truetype');
  font-display: swap;
}

:root {
  --bg: #10142a;
  --panel: rgba(18, 22, 46, 0.78);
  --panel-edge: rgba(255, 255, 255, 0.14);
  --ink: #f4f1ff;
  --muted: #a9a6c9;
  --red: #ff4436;
  --red-d: #b8180e;
  --gold: #ffd23f;
  --teal: #5ce1e6;
  --green: #3fd16a;
  --safe-t: max(env(safe-area-inset-top, 0px), var(--tg-safe-top, 0px));
  --safe-b: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-bottom, 0px));
  --safe-l: max(env(safe-area-inset-left, 0px), var(--tg-safe-left, 0px));
  --safe-r: max(env(safe-area-inset-right, 0px), var(--tg-safe-right, 0px));
  --btn: clamp(64px, 15vmin, 112px);
  --font: 'Press Start 2P', ui-monospace, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; width: 100%; overflow: hidden; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 12px;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: none; overscroll-behavior: none;
}
body { position: fixed; inset: 0; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- HUD */
#hud {
  position: fixed; left: 0; right: 0; top: 0; z-index: 20; pointer-events: none;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: calc(var(--safe-t) + 8px) calc(var(--safe-r) + 10px) 0 calc(var(--safe-l) + 10px);
}
.hud-left { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  background: rgba(10, 12, 30, 0.55); border: 1px solid var(--panel-edge); border-radius: 999px;
  padding: 8px 12px; font-size: 11px; display: flex; align-items: center; gap: 8px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.egg-ico { width: 11px; height: 14px; border-radius: 50% 50% 50% 50% / 58% 58% 42% 42%; background: radial-gradient(circle at 35% 30%, #fff, #fff1c9 55%, #e0b25f); box-shadow: 0 0 0 1px #b8873a; }
.icon-btn {
  pointer-events: auto; width: 46px; height: 46px; border-radius: 14px; border: 1px solid var(--panel-edge);
  background: rgba(10, 12, 30, 0.55); display: flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer;
}
.icon-btn span { width: 6px; height: 18px; background: var(--ink); border-radius: 2px; }
.icon-btn:active { transform: scale(0.94); }

/* ---------------------------------------------------------------- touch controls */
#controls { position: fixed; inset: 0; z-index: 10; touch-action: none; }
.pad { position: absolute; bottom: calc(var(--safe-b) + 18px); display: flex; gap: 14px; pointer-events: none; }
.pad-left { left: calc(var(--safe-l) + 18px); }
.pad-right { right: calc(var(--safe-r) + 22px); }
.tbtn {
  width: var(--btn); height: var(--btn); border-radius: 50%;
  background: rgba(255, 255, 255, 0.12); border: 2px solid rgba(255, 255, 255, 0.35);
  display: flex; align-items: center; justify-content: center; transition: transform 60ms, background 60ms;
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
}
.tbtn svg { width: 46%; height: 46%; fill: rgba(255, 255, 255, 0.85); }
.tbtn.on { background: rgba(255, 255, 255, 0.32); transform: scale(0.92); }
.tbtn-jump { width: calc(var(--btn) * 1.15); height: calc(var(--btn) * 1.15); background: rgba(255, 68, 54, 0.28); border-color: rgba(255, 140, 120, 0.6); }
.tbtn-jump.on { background: rgba(255, 68, 54, 0.55); }

/* ---------------------------------------------------------------- screens */
#screens { position: fixed; inset: 0; z-index: 30; pointer-events: none; }
.screen {
  position: fixed; inset: 0; display: none; align-items: center; justify-content: center; flex-direction: column;
  padding: calc(var(--safe-t) + 14px) calc(var(--safe-r) + 14px) calc(var(--safe-b) + 14px) calc(var(--safe-l) + 14px);
  pointer-events: auto; touch-action: pan-y; overflow-y: auto;
}
.screen.show { display: flex; animation: fade 160ms ease-out; }
.screen.dim { background: rgba(6, 8, 20, 0.55); }
@keyframes fade { from { opacity: 0; transform: scale(0.98); } to { opacity: 1; transform: none; } }

#boot { background: radial-gradient(ellipse at 50% 40%, #233066, var(--bg)); z-index: 50; }
#boot .bar { width: min(260px, 60vw); height: 10px; border-radius: 6px; background: rgba(255, 255, 255, 0.1); overflow: hidden; margin: 22px 0 14px; }
#boot-bar { height: 100%; width: 10%; background: linear-gradient(90deg, var(--red), var(--gold)); transition: width 200ms; }
#boot p { color: var(--muted); font-size: 10px; text-align: center; max-width: 80vw; line-height: 1.8; }

.logo {
  font-size: clamp(34px, 9vmin, 70px); letter-spacing: 4px; color: var(--red);
  text-shadow: 0 4px 0 var(--red-d), 0 8px 0 rgba(0, 0, 0, 0.35), 0 0 30px rgba(255, 68, 54, 0.35);
  position: relative;
}
.logo-sub { font-size: clamp(8px, 1.9vmin, 12px); color: var(--gold); margin-top: 10px; letter-spacing: 2px; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5); }

.panel {
  background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 22px;
  padding: 20px; width: min(440px, 92vw); max-height: 100%; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.panel h2 { margin: 2px 0 16px; font-size: 15px; text-align: center; color: var(--gold); letter-spacing: 1px; line-height: 1.5; }
.menu-col { display: flex; flex-direction: column; gap: 10px; width: min(300px, 80vw); margin-top: 26px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.btn {
  font-family: var(--font); font-size: 12px; color: var(--ink); cursor: pointer;
  border: none; border-radius: 14px; padding: 15px 14px; letter-spacing: 1px;
  background: linear-gradient(#3a3f6e, #2a2e55); box-shadow: 0 4px 0 #171a36, inset 0 1px 0 rgba(255, 255, 255, 0.15);
  transition: transform 60ms, box-shadow 60ms;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #171a36; }
.btn.primary { background: linear-gradient(#ff5a4c, #e02a1d); box-shadow: 0 4px 0 #8f130a, inset 0 1px 0 rgba(255, 255, 255, 0.25); }
.btn.primary:active { box-shadow: 0 1px 0 #8f130a; }
.btn.gold { background: linear-gradient(#ffdf6b, #f2b51c); color: #3a2600; box-shadow: 0 4px 0 #9a6f06; }
.btn.danger { background: linear-gradient(#7a2633, #561a24); box-shadow: 0 4px 0 #2e0d13; }
.btn.small { padding: 10px 10px; font-size: 10px; }
.btn:disabled { opacity: 0.4; }

/* level grid */
.grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.tile {
  aspect-ratio: 1; border-radius: 14px; border: none; font-family: var(--font); color: var(--ink);
  background: linear-gradient(#3a3f6e, #2a2e55); box-shadow: 0 3px 0 #171a36; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; font-size: 14px; padding: 4px;
}
.tile .stars { font-size: 8px; color: var(--gold); letter-spacing: 1px; }
.tile.locked { opacity: 0.45; cursor: default; }
.tile.soon { opacity: 0.25; cursor: default; font-size: 8px; }
.tile.done { background: linear-gradient(#2f6d4a, #22503a); box-shadow: 0 3px 0 #133022; }
.level-name { text-align: center; color: var(--muted); font-size: 10px; margin-top: 12px; min-height: 14px; line-height: 1.5; }

/* settings */
.set { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 10px 0; font-size: 10px; }
.set label { color: var(--muted); }
.set input[type=range] { width: 52%; accent-color: var(--red); }
.seg { display: flex; border-radius: 10px; overflow: hidden; border: 1px solid var(--panel-edge); }
.seg button { font-family: var(--font); font-size: 9px; border: none; padding: 9px 10px; background: transparent; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--red); color: #fff; }

/* results */
.big-stars { text-align: center; font-size: 34px; letter-spacing: 8px; margin: 4px 0 14px; color: rgba(255, 255, 255, 0.15); }
.big-stars .on { color: var(--gold); text-shadow: 0 0 16px rgba(255, 210, 63, 0.6); }
.stats { display: grid; grid-template-columns: 1fr auto; gap: 10px 14px; font-size: 10px; margin-bottom: 18px; }
.stats span:nth-child(odd) { color: var(--muted); }
.stats .new { color: var(--green); }
.credits { font-size: 9px; line-height: 2; color: var(--muted); }
.credits b { color: var(--ink); font-weight: normal; }
.credits a { color: var(--teal); }

#rotate .ico { width: 70px; height: 44px; border: 4px solid var(--ink); border-radius: 10px; margin-bottom: 22px; animation: rot 1.6s ease-in-out infinite; }
@keyframes rot { 0%, 30% { transform: rotate(-90deg); } 60%, 100% { transform: rotate(0); } }
#rotate p { font-size: 10px; line-height: 2; text-align: center; color: var(--muted); max-width: 80vw; }

#toast {
  position: fixed; left: 50%; top: calc(var(--safe-t) + 64px); transform: translateX(-50%); z-index: 60;
  background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 12px; padding: 10px 14px; font-size: 10px; pointer-events: none;
}

@media (max-height: 420px) {
  .panel { padding: 14px; }
  .panel h2 { margin-bottom: 10px; font-size: 13px; }
  .menu-col { margin-top: 14px; gap: 8px; }
  .btn { padding: 11px 12px; font-size: 11px; }
  .grid { grid-template-columns: repeat(8, 1fr); }
  .big-stars { font-size: 26px; margin-bottom: 8px; }
}

/* ---------------------------------------------------------------- v2: online / leaderboard */
.sub { font-size: 8px; color: var(--muted); opacity: 0.9; }
.btn .sub { color: inherit; opacity: 0.8; }
.status { align-self: center; font-size: 8px; color: var(--green); margin-top: 2px; line-height: 1.6; padding: 6px 12px; border-radius: 999px; background: rgba(10, 12, 30, 0.6); border: 1px solid var(--panel-edge); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note { text-align: center; font-size: 9px; color: var(--muted); line-height: 1.8; min-height: 4px; margin: 4px 0 12px; }
.tabs { margin: 0 auto 12px; width: max-content; }
.board { list-style: none; margin: 0; padding: 0; max-height: 46vh; overflow-y: auto; }
.board li { display: grid; grid-template-columns: 34px 1fr auto; gap: 8px; align-items: center; padding: 9px 8px; border-radius: 10px; font-size: 10px; }
.board li:nth-child(odd) { background: rgba(255, 255, 255, 0.04); }
.board li.me { background: rgba(255, 68, 54, 0.22); }
.board .rk { text-align: center; }
.board .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .sc { color: var(--gold); }
.board-me { display: flex; justify-content: space-between; font-size: 10px; padding: 10px 8px 0; border-top: 1px solid var(--panel-edge); margin-top: 8px; color: var(--gold); }
.lock { width: 12px; height: 10px; border-radius: 2px; background: var(--muted); position: relative; display: inline-block; margin-top: 6px; }
.lock::before { content: ''; position: absolute; left: 2px; top: -7px; width: 8px; height: 8px; border: 2px solid var(--muted); border-bottom: none; border-radius: 6px 6px 0 0; box-sizing: border-box; }
