:root {
  --bg: #070b1f; --panel: #0e1530cc; --line: #ffffff1f; --text: #eef4ff; --muted: #9fb0d6;
  --cyan: #38e1ff; --pink: #ff3b6b; --yellow: #ffd84a;
  --safe-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  --safe-right: var(--safe-area-inset-right, env(safe-area-inset-right, 0px));
  --safe-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  --safe-left: var(--safe-area-inset-left, env(safe-area-inset-left, 0px));
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
#shell { position: fixed; inset: 0; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; }
[hidden] { display: none !important; }

.screen { position: absolute; inset: 0; }
#menu {
  display: flex; flex-direction: column; gap: 14px; padding: max(16px, var(--safe-top)) max(20px, var(--safe-right)) max(14px, var(--safe-bottom)) max(20px, var(--safe-left));
  background: linear-gradient(180deg, #070b1fee 0%, #070b1fb0 40%, #070b1fe6 100%); overflow-y: auto; touch-action: pan-y;
}
header { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.intro { flex: 1 1 340px; }
.play-button { display: inline-flex; align-items: center; gap: 18px; width: min(100%, 280px); min-height: 60px; margin-top: 12px; padding: 10px 22px; border: 2px solid #b4f5ff; border-radius: 14px; background: var(--cyan); color: #04121c; font: inherit; text-align: left; cursor: pointer; }
.play-button > span:first-child { font-size: 26px; }
.play-button b { display: block; font-size: 22px; }
.play-button small { display: block; font-size: 13px; }
.start-hint { margin: 8px 0 0; font-size: 13px; color: var(--text); }
button:focus-visible, summary:focus-visible { outline: 3px solid var(--cyan); outline-offset: 3px; }
.play-button:focus-visible { outline-color: #fff; }
.settings { max-width: 390px; }
.settings summary { cursor: pointer; padding: 12px; min-height: 44px; font-size: 14px; color: var(--text); }
.settings[open] .options { padding: 8px 12px; border-radius: 12px; background: var(--panel); }
.eyebrow { font-size: 11px; letter-spacing: .22em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
h1 { margin: 4px 0 4px; font-size: clamp(34px, 6vw, 64px); font-weight: 900; letter-spacing: .02em; line-height: 1; }
h1 em { font-style: normal; color: var(--cyan); }
.tagline { margin: 0; color: var(--muted); max-width: 560px; font-size: 14px; }
.options { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; font-size: 13px; color: var(--muted); }
.options label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.options input { accent-color: var(--cyan); }
.skins { display: flex; gap: 6px; }
.skin { width: 22px; height: 22px; border-radius: 5px; border: 2px solid #ffffff33; cursor: pointer; padding: 0; }
.skin.on { border-color: #fff; box-shadow: 0 0 10px #fff8; }

.worlds { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.world {
  position: relative; text-align: left; color: var(--text); font: inherit; cursor: pointer;
  background: #1a2148; border: 2.5px solid #0d0b1e; border-radius: 14px; box-shadow: 0 4px 0 #0d0b1e;
  padding: 12px 12px 10px 66px; min-height: 92px; display: flex; flex-direction: column; gap: 2px;
  transition: transform .12s, border-color .12s, box-shadow .12s;
}
.world:focus-visible { background: #232c5c; box-shadow: 0 4px 0 #0d0b1e, inset 0 0 0 2px var(--c); }
@media (hover: hover) and (pointer: fine) { .world:hover { transform: translateY(-3px); background: #232c5c; box-shadow: 0 7px 0 #0d0b1e, inset 0 0 0 2px var(--c); } }
.world .planet { position: absolute; left: 12px; top: 14px; width: 42px; height: 42px; border-radius: 50%; border: 2.5px solid #0d0b1e; }
.world .num { position: absolute; right: 10px; top: 8px; font-size: 11px; color: var(--muted); }
.world b { font-size: 15px; }
.world small { color: var(--muted); font-size: 12px; }
.tier { font-size: 11px; font-weight: 800; letter-spacing: .04em; margin-top: 3px; }
.t1 { color: #86efac; } .t2 { color: #7dd3fc; } .t3 { color: #fde047; } .t4 { color: #fb923c; } .t5 { color: #f472b6; } .t6 { color: #ff3b6b; }
.bar { height: 4px; background: #ffffff14; border-radius: 3px; overflow: hidden; margin-top: 5px; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--c), #fff); }
.meta { font-size: 11px; color: var(--muted); }
footer { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 11px; color: var(--muted); margin-top: auto; }

#hud { position: absolute; top: max(10px, var(--safe-top)); left: max(12px, var(--safe-left)); right: max(12px, var(--safe-right)); display: flex; align-items: center; gap: 12px; pointer-events: none; }
#hud > * { pointer-events: auto; }
#btn-pause { width: 48px; height: 48px; flex-shrink: 0; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font-weight: 900; cursor: pointer; }
.hud-title { display: flex; flex-direction: column; min-width: 120px; }
.hud-title b { font-size: 14px; }
.hud-title span { font-size: 11px; color: var(--muted); }
.progress { position: relative; flex: 1; height: 14px; border-radius: 8px; background: #00000066; border: 1px solid var(--line); overflow: hidden; }
.progress i { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, #a78bfa, #38e1ff); }
.progress span { position: absolute; inset: 0; text-align: center; font-size: 10px; font-weight: 800; line-height: 13px; text-shadow: 0 1px 2px #000; }
.coins { color: var(--yellow); letter-spacing: 2px; font-size: 15px; text-shadow: 1px 1px 0 #0d0b1e; }
.track { font-size: 11px; color: var(--muted); max-width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.dialog-wrap { display: grid; place-items: center; padding: max(10px, var(--safe-top)) max(10px, var(--safe-right)) max(10px, var(--safe-bottom)) max(10px, var(--safe-left)); background: #02040fa0; }
.dialog { background: #1a2148; border: 3px solid #0d0b1e; border-radius: 18px; padding: 22px 26px; min-width: 260px;
  display: flex; flex-direction: column; gap: 10px; text-align: center; box-shadow: 0 6px 0 #0d0b1e; max-height: 100%; overflow-y: auto; touch-action: pan-y; }
.dialog h2 { margin: 2px 0 6px; font-size: 26px; }
.dialog p { margin: 0 0 6px; color: var(--muted); }
.dialog button { font: inherit; font-weight: 800; padding: 11px 16px; border-radius: 11px; border: 2.5px solid #0d0b1e; box-shadow: 0 3px 0 #0d0b1e; background: #ffffff10; color: var(--text); cursor: pointer; }
.dialog button:hover { background: #ffffff1c; }
.dialog button.primary { background: var(--cyan); color: #04121c; }

#toast { position: absolute; left: 50%; top: 70px; transform: translate(-50%, -8px); padding: 8px 16px; border-radius: 999px; background: #0e1530e6; border: 1px solid var(--line);
  font-weight: 800; font-size: 14px; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- economy: wallet, chest, shop, daily reward, results */
.side { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.economy { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; max-width: 390px; }
.wallet { display: inline-flex; align-items: center; gap: 6px; font-weight: 900; font-size: 16px; padding: 6px 12px 6px 8px; border-radius: 999px;
  background: #0e1530e6; border: 2.5px solid #0d0b1e; box-shadow: 0 3px 0 #0d0b1e; color: var(--yellow); min-width: 70px; }
.wallet::before { content: ''; width: 18px; height: 18px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff6b0, #facc15 55%, #b5780a); border: 2px solid #0d0b1e; }
.pill { font: inherit; font-weight: 800; font-size: 13px; min-height: 44px; padding: 7px 14px; border-radius: 999px; border: 2.5px solid #0d0b1e; box-shadow: 0 3px 0 #0d0b1e;
  background: #232c5c; color: var(--text); cursor: pointer; display: inline-flex; gap: 6px; align-items: baseline; }
.pill:hover { background: #2e3870; }
.pill.shop { background: var(--cyan); color: #04121c; }
.pill.chest small { color: var(--muted); font-weight: 700; }
.pill.chest.ready { background: var(--yellow); color: #2a1a00; }
.pill.chest.ready small { color: #2a1a00; }
.pill:disabled { opacity: .55; cursor: default; }
.options select { font: inherit; font-size: 12px; background: #0e1530; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 2px 4px; }
footer a { color: var(--muted); }

.dialog.wide { max-width: min(640px, 94vw); }
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.day { border: 2.5px solid #0d0b1e; border-radius: 10px; padding: 8px 2px; background: #ffffff10; display: flex; flex-direction: column; gap: 2px; }
.day small { font-size: 10px; color: var(--muted); }
.day b { color: var(--yellow); }
.day.done { opacity: .45; }
.day.today { background: #facc1533; box-shadow: inset 0 0 0 2px var(--yellow); }
.day.big b { font-size: 18px; }
.dialog button.video { background: #a78bfa; color: #120726; display: flex; flex-direction: column; align-items: center; gap: 1px; }
.dialog button.video small { font-size: 11px; font-weight: 700; opacity: .8; }
.dialog button:disabled { opacity: .5; cursor: default; }
.reward { list-style: none; margin: 0 0 4px; padding: 0; display: flex; flex-direction: column; gap: 3px; font-size: 14px; }
.reward li { display: flex; justify-content: space-between; gap: 18px; }
.reward b { color: var(--yellow); }
.reward li.bonus b { color: #c4b5fd; }

#shop { display: flex; flex-direction: column; gap: 10px; padding: max(12px, var(--safe-top)) max(16px, var(--safe-right)) max(12px, var(--safe-bottom)) max(16px, var(--safe-left));
  background: #070b1ff2; touch-action: pan-y; }
.shop-head { display: flex; align-items: center; gap: 12px; }
.shop-head h2 { margin: 0; flex: 1; font-size: 24px; }
.shop-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(220px, 34%) 1fr; gap: 14px; }
.shop-preview { display: flex; flex-direction: column; gap: 6px; align-items: stretch; text-align: center; }
.shop-preview canvas { width: 100%; aspect-ratio: 16 / 10; border: 3px solid #0d0b1e; border-radius: 14px; background: #070b1f; display: block; }
.shop-preview b { font-size: 18px; }
.shop-preview small { color: var(--muted); }
.shop-preview button { font: inherit; font-weight: 800; padding: 10px; border-radius: 11px; border: 2.5px solid #0d0b1e; box-shadow: 0 3px 0 #0d0b1e; background: var(--cyan); color: #04121c; cursor: pointer; }
.shop-preview button:disabled { background: #ffffff14; color: var(--muted); cursor: default; }
.shop-colors { display: flex; gap: 8px; align-items: center; justify-content: center; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.shop-list { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs button { font: inherit; font-weight: 800; font-size: 13px; padding: 6px 12px; border-radius: 999px; border: 2px solid #0d0b1e; background: #1a2148; color: var(--muted); cursor: pointer; }
.tabs button.on { background: #fff; color: #0d0b1e; }
.items { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; overflow-y: auto; padding-bottom: 8px; align-content: start; }
.item { font: inherit; text-align: left; color: var(--text); background: #1a2148; border: 2.5px solid #0d0b1e; border-radius: 12px; box-shadow: 0 3px 0 #0d0b1e;
  padding: 9px 10px; display: flex; flex-direction: column; gap: 2px; cursor: pointer; border-left-width: 6px; }
.item b { font-size: 14px; } .item small { font-size: 11px; color: var(--muted); }
.item span { font-size: 12px; font-weight: 800; color: var(--yellow); margin-top: 3px; }
.item.owned span { color: var(--muted); } .item.on span { color: #86efac; }
.item.sel { background: #2e3870; box-shadow: 0 3px 0 #0d0b1e, inset 0 0 0 2px #fff; }
.item.common { border-left-color: #94a3b8; } .item.rare { border-left-color: #38bdf8; } .item.epic { border-left-color: #c084fc; } .item.legend { border-left-color: #fbbf24; }

.fake-ad { position: fixed; inset: 0; z-index: 50; display: grid; place-content: center; gap: 10px; text-align: center; background: #000e; color: #fff; font: 900 22px system-ui; }
.fake-ad span { font-size: 48px; color: var(--yellow); }

@media (max-width: 640px), (max-height: 460px) {
  .shop-body { grid-template-columns: 40% 1fr; gap: 10px; }
  .items { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .side { align-items: flex-start; }
}

@media (max-width: 640px) {
  .track, .hud-title span { display: none; }
  .worlds { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .world { padding-left: 58px; min-height: 84px; }
  .world .planet { width: 36px; height: 36px; }
}
@media (max-height: 460px) and (min-width: 641px) {
  #menu { gap: 12px; padding-top: max(12px, var(--safe-top)); }
  h1 { font-size: 34px; }
  .tagline { font-size: 12px; max-width: 470px; }
  .intro { flex-basis: 300px; }
  .side, .economy { max-width: 320px; }
  .play-button { margin-top: 8px; }
}

/* Telegram fullscreen: keep HUD and menu below the client's own controls */
.tg #hud { top: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px) + 8px); }
.tg #menu { padding-top: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px) + 12px); }

#rotate { position: absolute; inset: 0; display: grid; place-content: center; gap: 12px; text-align: center; padding: 24px;
  background: #070b1fe6; z-index: 5; }
#rotate b { font-size: 56px; color: var(--cyan); }
#rotate p { margin: 0; font-weight: 700; }
#rotate button { font: inherit; font-weight: 800; padding: 10px 16px; border-radius: 11px; border: 2.5px solid #0d0b1e; background: #ffffff14; color: var(--text); box-shadow: 0 3px 0 #0d0b1e; }

.privacy-choice { border: 0; background: transparent; color: inherit; font: inherit; text-decoration: underline; padding: 4px 8px; cursor: pointer; }
