* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #14213d; font-family: system-ui, -apple-system, 'Segoe UI', sans-serif; color: #2b2118; overscroll-behavior: none; }
[hidden] { display: none !important; }

/* Портретная сцена: на телефоне — весь экран, на десктопе — колонка 9:16 */
#app { position: relative; height: 100dvh; width: min(100vw, calc(100dvh * 0.62)); margin: 0 auto; overflow: hidden; background: #4cc9f0; user-select: none; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }

.btn { font-family: inherit; font-weight: 900; font-size: 18px; line-height: 1; color: #2b2118; background: #fff; border: 3px solid #2b2118; border-radius: 16px; padding: 14px 18px; box-shadow: 0 5px 0 #2b2118; cursor: pointer; transition: transform .06s, box-shadow .06s; }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #2b2118; }
.btn.primary { background: #ffd60a; }
.btn.small { font-size: 14px; padding: 8px 12px; border-radius: 12px; box-shadow: 0 3px 0 #2b2118; }
.btn.icon { width: 46px; height: 46px; padding: 0; font-size: 20px; }
.btn small { font-weight: 700; opacity: .6; }
.btn:disabled { opacity: .55; cursor: default; }
.pulse { animation: pulse 1s infinite alternate; }
@keyframes pulse { to { filter: hue-rotate(-20deg) saturate(3) brightness(1.05); transform: scale(1.04); } }

/* ---------- экраны меню ---------- */
.screen { position: absolute; inset: 0; overflow-y: auto; padding: max(16px, env(safe-area-inset-top)) 16px 24px; background: linear-gradient(#4cc9f0, #caf0f8 60%, #fefae0); }
.screen header { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 10px; margin-bottom: 14px; }
.screen header h2 { margin: 0; font-size: 24px; font-weight: 900; text-align: right; }
.screen header .wallet { grid-column: 1 / -1; }
.wallet { display: flex; justify-content: center; gap: 8px; font-weight: 900; }
.wallet span { background: rgba(255,255,255,.8); border: 2px solid #2b2118; border-radius: 999px; padding: 4px 12px; font-size: 14px; }

.menu { display: flex; flex-direction: column; align-items: center; }
.logo { text-align: center; margin-top: 2vh; }
.logo h1 { margin: -6px 0 12px; font-size: 46px; line-height: .9; font-weight: 900; color: #e63946; -webkit-text-stroke: 2px #2b2118; text-shadow: 0 5px 0 #2b2118; transform: rotate(-3deg); }
.logo h1 span { color: #ffd60a; }
#logoBird canvas { animation: bob 1.6s ease-in-out infinite alternate; }
@keyframes bob { to { transform: translateY(-8px) rotate(4deg); } }
.menu nav { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; max-width: 340px; margin-top: 16px; }
.menu nav .primary { grid-column: 1 / -1; font-size: 26px; padding: 18px; }
.menu nav .btn:last-child { grid-column: 1 / -1; }
.fine { font-size: 11px; opacity: .6; text-align: center; margin-top: 18px; }

.grid { display: grid; gap: 10px; }
.grid.levels { grid-template-columns: repeat(3, 1fr); }
.level { background: #fff; border: 3px solid #2b2118; border-radius: 16px; box-shadow: 0 4px 0 #2b2118; padding: 10px 4px; cursor: pointer; font: inherit; color: inherit; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.level b { font-size: 28px; font-weight: 900; }
.level small { font-size: 10px; opacity: .7; }
.level.locked { background: #dee2e6; opacity: .7; box-shadow: none; }
.stars .star { color: #ced4da; font-size: 16px; -webkit-text-stroke: 1px #6c584c; }
.stars .star.on { color: #ffb703; }
.stars.big .star { font-size: 52px; -webkit-text-stroke: 2px #6c584c; }
.stars.big .star.on { animation: pop .4s backwards; }
.stars.big .star:nth-child(2) { animation-delay: .25s; font-size: 64px; }
.stars.big .star:nth-child(3) { animation-delay: .5s; }
@keyframes pop { from { transform: scale(0) rotate(-90deg); } 70% { transform: scale(1.3); } }

.list { display: flex; flex-direction: column; gap: 10px; }
.card { display: flex; align-items: center; gap: 12px; text-align: left; width: 100%; background: #fff; border: 3px solid #2b2118; border-radius: 16px; box-shadow: 0 4px 0 #2b2118; padding: 10px 12px; font: inherit; color: inherit; cursor: pointer; }
.card > div { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.card b { font-weight: 900; }
.card small { opacity: .7; }
.card .emoji { font-size: 34px; }
.card.locked, .card:disabled { background: #e9ecef; opacity: .75; box-shadow: none; cursor: default; }
.card.active { background: #d8f3dc; }
.card.danger { background: #ffe5e5; }
.bar { height: 10px; border: 2px solid #2b2118; border-radius: 999px; overflow: hidden; background: #e9ecef; }
.bar i { display: block; height: 100%; background: #06d6a0; }

.grid.memes { grid-template-columns: 1fr 1fr; }
.meme-card { background: #fff; border: 4px solid var(--rarity); outline: 3px solid #2b2118; border-radius: 14px; padding: 8px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 3px; min-height: 210px; }
.meme-card canvas { border-radius: 10px; border: 2px solid #2b2118; }
.meme-card b { font-weight: 900; font-size: 14px; }
.meme-card i { font-size: 11px; }
.meme-card small { font-size: 10px; font-weight: 800; color: var(--rarity); }
.meme-card.unknown { background: #e9ecef; justify-content: center; }
.meme-card .q { font-size: 64px; font-weight: 900; color: var(--rarity); }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; }
#hud .btn, #overlay { pointer-events: auto; }
.hud-top { display: flex; justify-content: space-between; align-items: flex-start; padding: max(10px, env(safe-area-inset-top)) 10px 0; }
.hud-mid { text-align: center; font-weight: 900; color: #fff; text-shadow: 0 2px 0 #2b2118, 0 0 4px #2b2118; }
#hudLevel { font-size: 12px; opacity: .9; }
#hudScore { font-size: 30px; line-height: 1; }
.hud-bottom { position: absolute; left: 0; right: 0; bottom: max(10px, env(safe-area-inset-bottom)); display: flex; justify-content: space-between; align-items: center; padding: 0 12px; font-size: 22px; }
#hint { font-size: 14px; font-weight: 900; color: #fff; text-shadow: 0 2px 0 #2b2118, 0 0 4px #2b2118; text-align: center; flex: 1; }

#overlay { position: absolute; inset: 0; background: rgba(20,33,61,.6); display: flex; align-items: center; justify-content: center; padding: 16px; overflow-y: auto; }
.panel { background: #fffdf5; border: 4px solid #2b2118; border-radius: 22px; box-shadow: 0 8px 0 #2b2118; padding: 16px; width: 100%; max-width: 360px; text-align: center; max-height: 100%; overflow-y: auto; animation: pop .3s; }
.panel h2 { margin: 0 0 6px; font-size: 26px; font-weight: 900; }
.panel h2.win { color: #e63946; } .panel h2.lose { color: #6c757d; }
.panel h3 { margin: 10px 0 6px; }
.panel table { width: 100%; font-size: 13px; margin: 8px 0; border-collapse: collapse; }
.panel td { padding: 3px 4px; text-align: left; border-bottom: 1px dashed #ccc; } .panel td:last-child { text-align: right; font-weight: 800; }
.scoreline { font-size: 18px; } .scoreline b { font-size: 26px; } .scoreline small { display: block; font-size: 12px; opacity: .6; }
.row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.row .btn { font-size: 15px; padding: 12px 14px; }
#newMemes .meme-card { max-width: 190px; margin: 0 auto 8px; min-height: 0; }

.ad-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center; z-index: 99; color: #fff; text-align: center; }
.ad-box { border: 2px dashed #fff; border-radius: 16px; padding: 30px; font-size: 18px; }

/* ---------- визуальная полировка v0.2 ---------- */
.screen { background: linear-gradient(#1e96e0, #6fcbf5 45%, #c9ecfb 80%, #ffe9c4); }
@property --ray { syntax: "<angle>"; inherits: false; initial-value: 0deg; }
.screen.menu::before { content: ""; position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background: repeating-conic-gradient(from var(--ray) at 50% 150px, rgba(255,255,255,.2) 0 10deg, rgba(255,255,255,0) 10deg 20deg); animation: spin 40s linear infinite;
  -webkit-mask-image: radial-gradient(circle at 50% 150px, #000 0, transparent 420px); mask-image: radial-gradient(circle at 50% 150px, #000 0, transparent 420px); }
.screen.menu::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 90px; z-index: 0; pointer-events: none;
  background: radial-gradient(ellipse 70% 100% at 25% 100%, #5fc26a 99%, transparent 100%), radial-gradient(ellipse 70% 80% at 85% 100%, #8ddc8a 99%, transparent 100%); }
.screen.menu > * { position: relative; z-index: 1; }
@keyframes spin { to { --ray: 360deg; } }

.logo h1 { font-size: 52px; letter-spacing: 1px; text-shadow: 0 3px 0 #2b2118, 0 7px 0 rgba(43,33,24,.35); animation: logoIn .7s cubic-bezier(.2,1.6,.4,1) backwards; }
@keyframes logoIn { from { transform: scale(0) rotate(-20deg); } }
#logoBird canvas { filter: drop-shadow(0 8px 0 rgba(0,0,0,.18)); }

.btn { background: linear-gradient(#fff, #e9edf2); text-shadow: 0 1px 0 #fff; }
.btn.primary { background: linear-gradient(#ffe45c, #ffb703); }
.btn:hover:not(:disabled) { filter: brightness(1.05); }
.menu nav .btn { animation: btnIn .45s cubic-bezier(.2,1.4,.4,1) backwards; }
.menu nav .btn:nth-child(2) { animation-delay: .05s; } .menu nav .btn:nth-child(3) { animation-delay: .1s; }
.menu nav .btn:nth-child(4) { animation-delay: .15s; } .menu nav .btn:nth-child(5) { animation-delay: .2s; }
.menu nav .btn:nth-child(6) { animation-delay: .25s; } .menu nav .btn:nth-child(7) { animation-delay: .3s; }
@keyframes btnIn { from { transform: translateY(30px) scale(.8); opacity: 0; } }

.level { background: linear-gradient(#fff, #ffe9a8); transition: transform .08s; }
.level:not(.locked):active { transform: translateY(3px); box-shadow: 0 1px 0 #2b2118; }
.level b { color: #e63946; -webkit-text-stroke: 1px #2b2118; }
.level.locked { background: #dee2e6; }
.card { background: linear-gradient(#fff, #f1f4f8); }
.card.active { background: linear-gradient(#e6fbe9, #bfeccb); }
.wallet span { background: linear-gradient(#fff, #fff3c4); box-shadow: 0 2px 0 #2b2118; }
.meme-card { box-shadow: 0 5px 0 #2b2118; background: linear-gradient(#fff, #f6f1e6); }
.meme-card:not(.unknown) { animation: pop .35s backwards; }
.panel { background: linear-gradient(#fffdf5, #ffeec2); }
.panel h2.win { -webkit-text-stroke: 1px #2b2118; text-shadow: 0 3px 0 #2b2118; color: #ffd60a; font-size: 28px; }
#hudScore { font-size: 34px; -webkit-text-stroke: 1.5px #2b2118; text-shadow: 0 3px 0 #2b2118; }
.hud-bottom > div:not(#hint):not(:empty) { background: rgba(255,255,255,.85); border: 2px solid #2b2118; border-radius: 999px; padding: 2px 10px; box-shadow: 0 3px 0 #2b2118; font-size: 18px; }

/* ---------- рекорды ---------- */
#hudBest { font-size: 12px; min-height: 14px; }
#hudBest.beaten { color: #ffd60a; font-size: 14px; animation: pulseTxt .5s infinite alternate; }
@keyframes pulseTxt { to { transform: scale(1.12); } }
.level small.best { font-weight: 800; opacity: 1; color: #b26a00; min-height: 12px; }
.record-banner { margin: 8px 0; padding: 8px 10px; border: 3px solid #2b2118; border-radius: 14px; box-shadow: 0 4px 0 #2b2118; font-weight: 900; font-size: 18px; color: #2b2118;
  background: linear-gradient(100deg, #ffe45c, #ffb703 40%, #fff3b0 50%, #ffb703 60%, #ffe45c); background-size: 250% 100%; animation: pop .4s, shine 2.2s linear infinite; }
.record-banner.trophy { background-image: linear-gradient(100deg, #cdb4ff, #9d4edd 40%, #f1e3ff 50%, #9d4edd 60%, #cdb4ff); color: #fff; text-shadow: 0 2px 0 #2b2118; }
.record-banner small { display: block; font-size: 12px; font-weight: 800; }
@keyframes shine { to { background-position: -250% 0; } }
.record-hero { text-align: center; background: linear-gradient(#fffdf5, #ffe9a8); border: 3px solid #2b2118; border-radius: 18px; box-shadow: 0 5px 0 #2b2118; padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.record-hero b { font-size: 40px; font-weight: 900; color: #e63946; -webkit-text-stroke: 1.5px #2b2118; line-height: 1; }
.record-hero span { font-weight: 900; }
.screen h3 { margin: 16px 0 8px; font-weight: 900; }
table.records { width: 100%; border-collapse: collapse; background: rgba(255,255,255,.85); border: 3px solid #2b2118; border-radius: 12px; overflow: hidden; font-size: 13px; }
table.records td { padding: 6px 8px; border-bottom: 1px dashed #bbb; } table.records td:last-child { text-align: right; font-weight: 900; }
table.records i { opacity: .5; font-weight: 400; }

/* ---------- Record Run ---------- */
.menu nav .wide { grid-column: 1 / -1; }
.btn.run { background: linear-gradient(#ff8a5c, #e63946); color: #fff; text-shadow: 0 2px 0 #2b2118; font-size: 20px; }
.btn.run small { color: #fff; opacity: .9; }
#hudStars { min-height: 18px; font-size: 16px; }

/* ---------- World ranking ---------- */
.btn.world-btn { background: linear-gradient(#7ad7ff, #1e96e0); color: #fff; text-shadow: 0 2px 0 #2b2118; }
.tabs { display: flex; gap: 8px; margin: 12px 0; } .tabs .btn { flex: 1; }
.profile-row .emoji { font-size: 30px; }
.lb-list { background: rgba(255,255,255,.9); border: 3px solid #2b2118; border-radius: 16px; box-shadow: 0 4px 0 #2b2118; overflow: hidden; }
.lb-row { display: grid; grid-template-columns: 46px 30px 1fr auto; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px dashed #c9c9c9; font-size: 14px; }
.lb-row:last-child { border-bottom: 0; }
.lb-row .rank { text-align: center; font-weight: 900; color: #6c757d; }
.lb-row .name { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-row .pts { font-weight: 900; color: #e63946; }
.lb-row.top1 { background: linear-gradient(90deg, #fff3b0, transparent); } .lb-row.top2 { background: linear-gradient(90deg, #e9ecef, transparent); } .lb-row.top3 { background: linear-gradient(90deg, #f3d5b5, transparent); }
.lb-row.top1 .rank, .lb-row.top2 .rank, .lb-row.top3 .rank { font-size: 20px; }
.lb-row.me { background: #d8f3dc; outline: 2px solid #2b9348; outline-offset: -2px; }
.lb-gap { text-align: center; font-weight: 900; color: #6c757d; line-height: 1; padding: 2px; }
.lb-offline { padding: 18px; text-align: center; font-weight: 700; }
.field { cursor: default; } .field input { font: inherit; font-weight: 900; font-size: 20px; padding: 8px 10px; border: 3px solid #2b2118; border-radius: 12px; width: 100%; background: #fff; }
.flags { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 6px; }
.flag-btn { font: inherit; font-size: 20px; padding: 6px 0; border: 2px solid #ced4da; border-radius: 10px; background: #fff; cursor: pointer; }
.flag-btn.on { border-color: #2b2118; background: #ffd60a; box-shadow: 0 2px 0 #2b2118; }
.world-rank { min-height: 20px; margin: 6px 0; font-weight: 800; font-size: 15px; } .world-rank b { color: #1e6fd9; font-size: 18px; }

/* ---------- задание уровня и условия звёзд ---------- */
#hudGoal { font-size: 13px; margin-top: 2px; background: rgba(20,33,61,.55); border-radius: 999px; padding: 2px 10px; display: inline-block; text-shadow: none; }
#hudGoal:empty { display: none; }
#hudGoal.done { background: rgba(6,160,110,.85); } #hudGoal.failed { background: rgba(200,40,40,.8); text-decoration: line-through; }
.star-list { text-align: left; margin: 8px 0; border: 2px solid #2b2118; border-radius: 12px; overflow: hidden; background: #fff; }
.star-row { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 6px; padding: 5px 10px; font-size: 13px; font-weight: 700; border-bottom: 1px dashed #ccc; color: #6c757d; }
.star-row:last-child { border-bottom: 0; }
.star-row .star { font-size: 20px; color: #ced4da; -webkit-text-stroke: 1px #6c584c; } .star-row .star.on { color: #ffb703; }
.star-row.ok { color: #2b2118; background: #f0fff4; } .star-row.ok b { color: #2b9348; }

textarea.code { width: 100%; font: 12px ui-monospace, monospace; padding: 8px; border: 2px solid #2b2118; border-radius: 10px; resize: none; word-break: break-all; background: #fff; }
.modal h3 { margin: 12px 0 4px; font-size: 15px; } .modal .fine { margin: 4px 0 8px; opacity: .8; }

a.card { text-decoration: none; }
.btn.danger-btn { background: linear-gradient(#ffe5e5, #ffb3b3); }
/* в приложении: никаких выделений, долгих нажатий и «резинового» скролла страницы */
html.native, html.native body { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; overscroll-behavior: none; }
html.native #app { width: 100vw; }
html.native textarea, html.native input { -webkit-user-select: text; user-select: text; }

/* ---------- модальное окно и «поделиться» ---------- */
.modal { position: absolute; inset: 0; z-index: 20; background: rgba(20,33,61,.7); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal .meme-card { max-width: 240px; margin: 0 auto; min-height: 0; }
.meme-card.tappable { cursor: pointer; transition: transform .1s; } .meme-card.tappable:active { transform: scale(.96); }

/* ---------- Record Run hub ---------- */
.hub { display: grid; gap: 12px; }
.hub-btn { font-size: 24px; padding: 16px; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.hub-btn small { font-size: 13px; opacity: .95; color: inherit; }
.upg .pips { display: flex; gap: 3px; margin-top: 2px; }
.upg .pips i { width: 14px; height: 7px; border-radius: 3px; border: 1.5px solid #2b2118; background: #e9ecef; }
.upg .pips i.on { background: #06d6a0; }
.tabs { flex-wrap: wrap; } .tabs .btn { min-width: 30%; padding: 8px 6px; font-size: 12px; }
