:root {
    --ap-cream: #fff8e9;
    --ap-paper: #fffdf8;
    --ap-ink: #4c382d;
    --ap-muted: #826f62;
    --ap-rust: #bd633e;
    --ap-gold: #daa345;
    --ap-forest: #62745a;
    --ap-line: rgba(114, 79, 55, .12);
}

.ap-overlay {
    position: fixed;
    inset: 0;
    z-index: 12000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: max(18px, env(safe-area-inset-top)) 12px max(16px, env(safe-area-inset-bottom));
    background:
        radial-gradient(circle at 18% 8%, rgba(255, 211, 126, .42), transparent 32%),
        linear-gradient(180deg, rgba(74, 52, 39, .28), rgba(46, 34, 27, .58));
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    animation: apFadeIn .28s ease both;
}

.ap-overlay.ap-closing { animation: apFadeOut .24s ease both; }
.ap-scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }
body.ap-modal-open { overflow: hidden; }

.ap-sheet {
    position: relative;
    width: min(100%, 440px);
    max-height: calc(100vh - 34px);
    overflow: auto;
    border: 1px solid rgba(255,255,255,.65);
    border-radius: 30px;
    background: var(--ap-paper);
    color: var(--ap-ink);
    box-shadow: 0 28px 70px rgba(54, 35, 23, .28);
    animation: apSheetUp .5s cubic-bezier(.2,.8,.2,1) both;
}

.ap-sheet::before {
    content: '';
    position: absolute;
    inset: 0 0 auto;
    height: 180px;
    border-radius: 30px 30px 50% 50%;
    background: linear-gradient(145deg, #ffe5a9, #f5b986 54%, #d89572);
    opacity: .78;
    pointer-events: none;
}

/* Держим весь вводный абзац итогов на одном фоне: изгиб больше не режет строки. */
.ap-finale-sheet::before { height: 220px; }
.ap-finale-sheet .ap-subtitle { color: #6f5141; font-weight: 600; }

.ap-sheet-inner { position: relative; padding: 20px 20px 24px; }
.ap-kicker {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(255,255,255,.72);
    color: #875438;
    font-size: 11px;
    font-weight: 900;
    letter-spacing: .07em;
    text-transform: uppercase;
}

.ap-title {
    margin: 12px 0 5px;
    font-size: clamp(27px, 7.4vw, 36px);
    line-height: 1.04;
    letter-spacing: -.04em;
    font-weight: 900;
}

.ap-subtitle { margin: 0; color: var(--ap-muted); font-size: 14px; line-height: 1.45; }

.ap-hero-wrap {
    display: grid;
    grid-template-columns: 146px 1fr;
    gap: 14px;
    align-items: end;
    margin: 18px 0 14px;
}

.ap-polaroid {
    padding: 7px 7px 22px;
    border-radius: 15px;
    background: white;
    box-shadow: 0 13px 28px rgba(81, 48, 30, .18);
    transform: rotate(-2.5deg);
}

.ap-polaroid img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; }
.ap-level-big { font-size: 42px; line-height: .95; font-weight: 1000; letter-spacing: -.06em; color: var(--ap-rust); }
.ap-level-big span { display: block; margin-top: 7px; font-size: 12px; line-height: 1.25; letter-spacing: 0; color: var(--ap-muted); font-weight: 800; }
.ap-level-big .ap-level-end { display:block; margin-top:9px; font-size:9px; line-height:1.25; letter-spacing:0; color:#9b887a; font-weight:750; }

.ap-stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 18px; }
.ap-stat {
    min-width: 0;
    padding: 11px 8px;
    border: 1px solid var(--ap-line);
    border-radius: 16px;
    background: rgba(255,248,233,.74);
    text-align: center;
}
.ap-stat strong { display: block; font-size: 21px; line-height: 1; color: var(--ap-ink); }
.ap-stat span { display: block; margin-top: 6px; color: var(--ap-muted); font-size: 10px; line-height: 1.15; font-weight: 800; }

.ap-section {
    margin-top: 12px;
    padding: 15px;
    border: 1px solid var(--ap-line);
    border-radius: 20px;
    background: #fff;
}
.ap-section-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; font-weight: 900; font-size: 15px; }
.ap-section-note { color: var(--ap-muted); font-weight: 700; font-size: 11px; }

.ap-winner-title { font-size: 22px; line-height: 1.08; font-weight: 1000; letter-spacing: -.035em; color: var(--ap-ink); }
.ap-winner-note { margin: 7px 0 0; color: var(--ap-muted); font-size: 11px; line-height: 1.4; }
.ap-winner-cloud {
    display: grid;
    grid-template-columns: repeat(8, 32px);
    grid-auto-rows: 32px;
    justify-content: center;
    margin: 15px auto 18px;
    padding: 7px 0 9px;
}
.ap-winner-avatar {
    position: relative;
    z-index: 1;
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    overflow: hidden;
    border: 2px solid #f2c567;
    border-radius: 50%;
    background: #f8dfaf;
    box-shadow: 0 4px 10px rgba(105,65,37,.12);
    color: #8a562f;
    font-size: 13px;
    font-weight: 1000;
}
.ap-winner-avatar:nth-child(3n) { top: 3px; z-index: 2; }
.ap-winner-avatar:nth-child(4n) { top: -2px; z-index: 3; }
.ap-winner-avatar:nth-child(n+9):nth-child(-n+16) { left: 12px; }
.ap-winner-avatar:nth-child(n+25) { left: 48px; }
.ap-winner-avatar img { width:100%; height:100%; object-fit:cover; }
.ap-winner-avatar.is-self { box-shadow:0 0 0 3px rgba(98,116,90,.28), 0 4px 10px rgba(105,65,37,.12); border-color:var(--ap-forest); }

.ap-personal-result { display:flex; align-items:center; gap:11px; padding:13px; border-radius:17px; background:linear-gradient(135deg,#fff3c8,#fde0bb); }
.ap-personal-icon { width:42px; height:42px; flex:0 0 auto; display:grid; place-items:center; border-radius:50%; background:#fff; font-size:22px; box-shadow:0 6px 14px rgba(139,84,38,.13); }
.ap-personal-copy { min-width:0; }
.ap-personal-copy small { display:block; margin-bottom:3px; color:#9b6c45; font-size:9px; font-weight:1000; letter-spacing:.07em; text-transform:uppercase; }
.ap-personal-copy strong { display:block; font-size:13px; }
.ap-personal-copy span { display:block; margin-top:3px; color:var(--ap-muted); font-size:11px; line-height:1.3; }

.ap-podium { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; align-items: end; }
.ap-podium-person { min-width: 0; text-align: center; }
.ap-podium-person.is-first { order: 2; }
.ap-podium-person.is-second { order: 1; }
.ap-podium-person.is-third { order: 3; }
.ap-podium-avatar {
    width: 43px;
    height: 43px;
    margin: 0 auto 7px;
    display: grid;
    place-items: center;
    overflow: hidden;
    border: 3px solid #f2c567;
    border-radius: 50%;
    background: #f8dfaf;
    color: #8a562f;
    font-size: 17px;
    font-weight: 1000;
}
.ap-podium-person.is-first .ap-podium-avatar { width: 55px; height: 55px; box-shadow: 0 0 0 5px rgba(242,197,103,.18); }
.ap-podium-avatar img { width: 100%; height: 100%; object-fit: cover; }
.ap-podium-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; font-weight: 900; }
.ap-podium-place { margin-top: 6px; padding: 7px 4px; border-radius: 11px 11px 5px 5px; background: #f5dfb4; font-size: 12px; font-weight: 1000; }
.ap-podium-person.is-first .ap-podium-place { padding-top: 15px; background: linear-gradient(180deg,#f7cf70,#e9aa42); color:#6a421e; }
.ap-podium-person.is-second .ap-podium-place { padding-top: 10px; background:#e9e4df; }
.ap-podium-person.is-third .ap-podium-place { background:#e8c1a1; }

.ap-badge-card { display:flex; align-items:center; gap:11px; margin-top:12px; padding:12px 13px; border-radius:17px; background:linear-gradient(135deg,#fff3c8,#fde0bb); }
.ap-badge-medal { width:42px; height:42px; flex:0 0 auto; display:grid; place-items:center; border-radius:50%; background:#fff; font-size:23px; box-shadow:0 6px 14px rgba(139,84,38,.13); }
.ap-badge-copy strong { display:block; font-size:13px; }
.ap-badge-copy span { display:block; margin-top:2px; color:var(--ap-muted); font-size:11px; line-height:1.3; }

.ap-primary, .ap-secondary {
    width: 100%;
    min-height: 48px;
    border: 0;
    border-radius: 16px;
    font: inherit;
    font-size: 14px;
    font-weight: 900;
    cursor: pointer;
}
.ap-primary { margin-top: 16px; color: #fff; background: linear-gradient(135deg,#c46b43,#a95136); box-shadow: 0 10px 23px rgba(169,81,54,.25); }
.ap-secondary { margin-top: 8px; color: var(--ap-ink); background: #f5ecdf; }

.ap-preview-tools {
    position: fixed;
    z-index: 13000;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    display: flex;
    max-width: calc(100vw - 20px);
    gap: 5px;
    padding: 6px;
    border: 1px solid rgba(255,255,255,.45);
    border-radius: 17px;
    background: rgba(58,43,34,.88);
    box-shadow: 0 12px 28px rgba(34,23,17,.26);
    backdrop-filter: blur(12px);
}
.ap-preview-tools button { border:0; border-radius:11px; padding:8px 9px; color:#fff; background:rgba(255,255,255,.1); font:inherit; font-size:10px; font-weight:850; white-space:nowrap; }
.ap-preview-tools button:first-child { background:#bd633e; }

.ap-preview-label {
    position: fixed;
    z-index: 11000;
    top: calc(8px + env(safe-area-inset-top));
    right: 8px;
    padding: 5px 9px;
    border-radius: 999px;
    color:#fff;
    background:rgba(71,52,42,.78);
    font-size:9px;
    font-weight:900;
    letter-spacing:.07em;
    pointer-events:none;
}

.ap-transition { align-items:center; overflow:hidden; background:linear-gradient(155deg,#fff1c2,#d99b62 53%,#6f7657); }
.ap-transition-stage { position:relative; width:min(88vw,400px); height:min(76vh,650px); display:grid; place-items:center; }
.ap-transition-copy { position:absolute; z-index:8; top:0; left:0; right:0; text-align:center; color:#fff; text-shadow:0 2px 14px rgba(54,33,20,.35); }
.ap-transition-copy strong { display:block; font-size:26px; line-height:1.05; }
.ap-transition-copy span { display:block; margin-top:7px; font-size:13px; font-weight:750; }
.ap-season-card { position:absolute; width:min(76vw,310px); padding:10px 10px 36px; border-radius:19px; background:white; box-shadow:0 24px 55px rgba(57,35,23,.32); }
.ap-season-card img { display:block; width:100%; aspect-ratio:1; object-fit:cover; border-radius:13px; }
.ap-summer-card { animation:apCloseAlbum 3.4s .35s cubic-bezier(.3,.7,.2,1) both; }
.ap-autumn-card { opacity:0; transform:translateY(35px) scale(.92) rotate(2deg); animation:apOpenAutumn 1.1s 3.15s cubic-bezier(.2,.8,.2,1) forwards; }
.ap-card-caption { position:absolute; left:12px; right:12px; bottom:9px; text-align:center; color:#75513b; font-size:12px; font-weight:900; }
.ap-transition .ap-primary { position:absolute; z-index:10; left:18px; right:18px; bottom:0; width:auto; opacity:0; animation:apButtonIn .6s 4.05s ease forwards; }
.ap-flying-leaf { position:absolute; z-index:6; top:-15%; font-size:32px; filter:drop-shadow(0 7px 9px rgba(78,42,20,.18)); animation:apLeafFall 2.7s ease-in-out both; }
.ap-flying-leaf.l1 { left:4%; animation-delay:1.45s; }
.ap-flying-leaf.l2 { left:27%; animation-delay:1.7s; font-size:44px; }
.ap-flying-leaf.l3 { right:22%; animation-delay:1.55s; font-size:38px; }
.ap-flying-leaf.l4 { right:0; animation-delay:1.85s; }

.ap-welcome-hero { position:relative; height:190px; margin:-20px -20px 14px; overflow:hidden; border-radius:30px 30px 50% 50%; background:#e5b374; }
.ap-welcome-hero img { width:100%; height:100%; object-fit:cover; }
.ap-welcome-hero::after { content:'🍂'; position:absolute; right:22px; top:20px; font-size:44px; filter:drop-shadow(0 6px 10px rgba(82,48,23,.18)); animation:apFloat 2.7s ease-in-out infinite; }
.ap-welcome-sheet .ap-subtitle { font-size:15px; line-height:1.45; }
.ap-game-card { position:relative; overflow:hidden; margin-top:18px; padding:18px; border:1px solid rgba(135,84,56,.12); border-radius:22px; background:linear-gradient(145deg,#fff1c8,#f4c993 58%,#e7ad73); box-shadow:0 13px 28px rgba(117,73,42,.12); }
.ap-game-card::after { content:'🌰'; position:absolute; right:-14px; top:-18px; font-size:92px; opacity:.13; transform:rotate(18deg); pointer-events:none; }
.ap-game-kicker { position:relative; z-index:1; color:#8a5738; font-size:10px; line-height:1.2; font-weight:1000; letter-spacing:.075em; text-transform:uppercase; }
.ap-game-heading { position:relative; z-index:1; display:flex; align-items:center; gap:12px; margin-top:10px; }
.ap-game-icon { width:52px; height:52px; flex:0 0 auto; display:grid; place-items:center; border-radius:17px; background:rgba(255,255,255,.78); box-shadow:0 7px 16px rgba(117,73,42,.1); font-size:27px; }
.ap-game-heading h2 { margin:0; font-size:25px; line-height:.96; letter-spacing:-.035em; }
.ap-game-card > p { position:relative; z-index:1; margin:14px 0 0; color:#6f5141; font-size:14px; line-height:1.42; font-weight:700; }
.ap-game-together { position:relative; z-index:1; display:grid; grid-template-columns:35px 1fr; gap:10px; align-items:start; margin-top:15px; padding:12px; border-radius:16px; background:rgba(255,255,255,.67); }
.ap-game-together > span { width:35px; height:35px; display:grid; place-items:center; border-radius:12px; background:#fff; font-size:19px; }
.ap-game-together strong { display:block; font-size:13px; line-height:1.2; }
.ap-game-together small { display:block; margin-top:4px; color:var(--ap-muted); font-size:11px; line-height:1.35; }

.ap-challenge { padding:3px 0 80px; color:var(--ap-ink); }
.ap-challenge-hero { position:relative; overflow:hidden; padding:21px 18px 18px; border-radius:24px; background:linear-gradient(145deg,#f7dca2,#e7ad73 55%,#bd7350); box-shadow:0 15px 35px rgba(139,83,48,.15); }
.ap-challenge-hero::after { content:'🌰'; position:absolute; right:-5px; top:-8px; font-size:92px; opacity:.26; transform:rotate(17deg); }
.ap-challenge-kicker { font-size:10px; font-weight:1000; letter-spacing:.08em; text-transform:uppercase; color:#805136; }
.ap-challenge-title { margin-top:6px; max-width:75%; font-size:28px; line-height:1; font-weight:1000; letter-spacing:-.045em; }
.ap-challenge-copy { position:relative; z-index:1; max-width:83%; margin-top:9px; font-size:12px; line-height:1.4; color:#76523d; font-weight:700; }
.ap-community-count { display:flex; justify-content:space-between; align-items:flex-end; margin:17px 0 7px; }
.ap-community-count strong { font-size:27px; line-height:1; }
.ap-community-count span { color:var(--ap-muted); font-size:11px; font-weight:800; }
.ap-progress { position:relative; height:16px; overflow:hidden; border-radius:999px; background:#eadfce; box-shadow:inset 0 1px 3px rgba(80,49,31,.09); }
.ap-progress > i { display:block; height:100%; border-radius:inherit; background:linear-gradient(90deg,#dca244,#bd633e); box-shadow:0 0 16px rgba(218,163,69,.45); }
.ap-milestones { position:relative; display:grid; grid-template-columns:repeat(4,1fr); gap:7px; margin-top:14px; }
.ap-milestone { position:relative; overflow:hidden; min-height:104px; padding:8px; border:1px solid var(--ap-line); border-radius:15px; background:#fff; }
.ap-milestone img { width:100%; aspect-ratio:1; border-radius:10px; object-fit:cover; filter:saturate(.85); }
.ap-milestone.locked img { filter:grayscale(.8) blur(1px); opacity:.38; }
.ap-milestone em { position:absolute; inset:8px 8px auto auto; width:23px; height:23px; display:grid; place-items:center; border-radius:50%; background:rgba(255,255,255,.9); font-style:normal; font-size:12px; }
.ap-milestone span { display:block; margin-top:5px; text-align:center; color:var(--ap-muted); font-size:9px; font-weight:900; }
.ap-contribution { display:grid; grid-template-columns:auto 1fr auto; gap:10px; align-items:center; margin-top:15px; padding:14px; border-radius:17px; background:#fff8e9; }
.ap-contribution-icon { width:38px; height:38px; display:grid; place-items:center; border-radius:13px; background:#f2d19b; font-size:20px; }
.ap-contribution strong { display:block; font-size:12px; }
.ap-contribution small { color:var(--ap-muted); font-size:10px; }
.ap-contribution-value { color:var(--ap-rust); font-size:20px; font-weight:1000; }
.ap-demo-note { margin-top:10px; color:#9b887a; font-size:10px; line-height:1.4; text-align:center; }

.ap-album-card { position:relative; overflow:hidden; display:grid; grid-template-columns:96px 1fr; gap:14px; align-items:center; margin-bottom:16px; padding:13px; border:1px solid var(--ap-line); border-radius:22px; background:linear-gradient(145deg,#fff3d2,#f4d1ad); box-shadow:0 12px 28px rgba(117,73,42,.1); cursor:pointer; }
.ap-album-card img { width:96px; height:96px; border:6px solid #fff; border-radius:14px; object-fit:cover; transform:rotate(-2deg); box-shadow:0 8px 18px rgba(78,44,25,.14); }
.ap-album-copy small { color:#9b6c45; font-weight:900; text-transform:uppercase; letter-spacing:.06em; }
.ap-album-copy strong { display:block; margin-top:5px; font-size:18px; line-height:1.05; }
.ap-album-copy span { display:block; margin-top:7px; color:var(--ap-muted); font-size:11px; line-height:1.35; }

@keyframes apFadeIn { from { opacity:0 } to { opacity:1 } }
@keyframes apFadeOut { to { opacity:0 } }
@keyframes apSheetUp { from { opacity:0; transform:translateY(35px) scale(.97) } to { opacity:1; transform:none } }
@keyframes apCloseAlbum { 0% { transform:rotate(-2deg) scale(1); opacity:1 } 55% { transform:translateY(40px) rotate(4deg) scale(.84); opacity:1 } 100% { transform:translate(-36px,125px) rotate(-15deg) scale(.45); opacity:0 } }
@keyframes apOpenAutumn { to { opacity:1; transform:translateY(12px) scale(1) rotate(-1deg) } }
@keyframes apButtonIn { to { opacity:1; transform:translateY(0) } from { opacity:0; transform:translateY(10px) } }
@keyframes apLeafFall { 0% { transform:translateY(-10vh) rotate(0); opacity:0 } 15% { opacity:1 } 100% { transform:translate(45px,90vh) rotate(560deg); opacity:0 } }
@keyframes apFloat { 50% { transform:translateY(7px) rotate(8deg) } }

@media (min-width: 700px) {
    .ap-overlay { align-items:center; }
}

@media (max-width: 699px) {
    /* На телефоне итог и приветствие становятся полноценными страницами.
       Скролл принадлежит оверлею, поэтому вложенного «окна в окне» больше нет. */
    .ap-overlay.ap-scroll {
        display: block;
        padding: 0;
        overflow-y: auto;
        overscroll-behavior-y: contain;
        background: var(--ap-paper);
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }

    .ap-scroll .ap-sheet {
        width: 100%;
        min-height: 100vh;
        min-height: 100dvh;
        max-height: none;
        overflow: visible;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        animation: apFadeIn .28s ease both;
    }

    .ap-scroll .ap-sheet::before {
        border-radius: 0 0 50% 50%;
    }

    .ap-scroll .ap-sheet-inner {
        box-sizing: border-box;
        min-height: 100vh;
        min-height: 100dvh;
        padding: max(20px, env(safe-area-inset-top)) 20px calc(92px + env(safe-area-inset-bottom));
    }

    .ap-scroll .ap-welcome-hero {
        margin-top: calc(0px - max(20px, env(safe-area-inset-top)));
        border-radius: 0 0 50% 50%;
    }

    /* Панель остаётся доступной владельцу, но контент резервирует под неё место. */
    .ap-preview-tools {
        left: 10px;
        right: 10px;
        justify-content: stretch;
    }

    .ap-preview-tools button {
        min-width: 0;
        flex: 1;
    }
}

@media (max-width: 365px) {
    .ap-preview-tools button { padding:7px 6px; font-size:9px; }
    .ap-hero-wrap { grid-template-columns:125px 1fr; }
    .ap-stat strong { font-size:18px; }
}

@media (prefers-reduced-motion: reduce) {
    .ap-overlay, .ap-sheet, .ap-summer-card, .ap-autumn-card, .ap-transition .ap-primary, .ap-flying-leaf { animation-duration:.01ms !important; animation-delay:0ms !important; }
}
