* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
    --frame-bottom: 0px;
    --frame-left: 0px;
    --frame-right: 0px;
    --accent: #c2304a;
    --accent-dark: #8a1d33;
    --gold: #f59e0b;
    --ink: #3b2416;
    --ladder-h: 46px;
}
html, body { height: 100%; }
/* Inside the site iframe a fixed footer bar (~40px) covers the bottom; the site hides it when height <= 400px. */
html.in-frame { --frame-bottom: 44px; }
@media (max-height: 400px) { html.in-frame { --frame-bottom: 0px; } }
@media (max-height: 560px) { :root { --ladder-h: 34px; } }

body { font-family: Arial, Helvetica, sans-serif; background: #9fd3ef; color: #fff; overflow: hidden; user-select: none; -webkit-user-select: none; }
#bg { position: fixed; inset: 0; z-index: 0; }
#bg svg { width: 100%; height: 100%; display: block; }
/* wooden table under the jar, full width (game screen only) */
#table {
    position: fixed; left: 0; right: 0; bottom: var(--frame-bottom); height: calc(var(--ladder-h) + 28px); z-index: 0; display: none;
    border-top: 3px solid #e2ab7a;
    background: repeating-linear-gradient(180deg, transparent 0 23px, rgba(70, 35, 15, .3) 23px 25px), linear-gradient(#c4834f, #8a5332);
}
body.ingame #table { display: block; }
#app {
    position: relative; z-index: 1;
    height: calc(100vh - var(--frame-bottom));
    height: calc(100dvh - var(--frame-bottom));
    padding: 0 var(--frame-right) 0 var(--frame-left);
    display: flex; justify-content: center;
}
#stage { position: relative; width: 100%; max-width: 480px; height: 100%; overflow: hidden; }
.screen { display: none; position: absolute; inset: 0; flex-direction: column; }
.screen.active { display: flex; }

/* ---------- buttons ---------- */
.btn {
    display: block; width: 280px; max-width: 100%; border: none; padding: 12px 20px; margin: 6px auto; min-height: 50px;
    font-size: 19px; font-weight: bold; border-radius: 50px; cursor: pointer; font-family: inherit;
    box-shadow: 0 4px 0 rgba(0, 0, 0, .2), 0 8px 16px rgba(0, 0, 0, .2); transition: transform .12s ease;
}
.btn:active { transform: translateY(2px); }
.btn small { display: block; font-size: 12px; font-weight: normal; opacity: .9; margin-top: 2px; }
.btn .row { display: flex; align-items: center; justify-content: center; gap: 8px; }
.btn-primary { background: linear-gradient(#d8435d, #b0263f); color: #fff; box-shadow: 0 4px 0 #6e1426, 0 8px 16px rgba(0, 0, 0, .25); }
.btn-secondary { background: #fff; color: var(--accent-dark); }
.btn-secondary.done { opacity: .75; }
.btn-ghost { background: transparent; color: var(--ink); box-shadow: none; text-decoration: underline; font-size: 15px; padding: 6px; min-height: 40px; }
.btn-ghost.dark { color: #6b7280; }
.tag { font-size: 12px; background: var(--gold); color: #fff; border-radius: 10px; padding: 2px 7px; }
.tag:empty { display: none; }
.icon-btn {
    width: 44px; height: 44px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .9); background: rgba(70, 30, 20, .45);
    color: #fff; font-size: 18px; font-weight: bold; display: flex; align-items: center; justify-content: center; flex-shrink: 0; cursor: pointer; font-family: inherit;
}
.icon-btn.off { opacity: .6; }
#btn-pause { gap: 5px; }
#btn-pause i { display: block; width: 5px; height: 16px; background: #fff; border-radius: 2px; }

/* ---------- start ---------- */
#start-screen { align-items: center; justify-content: center; text-align: center; padding: 64px 16px 16px; overflow-y: auto; }
#start-screen .corner { position: absolute; top: 15px; left: 15px; display: flex; gap: 8px; z-index: 2; }
.start-inner { display: flex; flex-direction: column; align-items: center; width: 100%; margin: auto 0; }
.logo { display: block; filter: drop-shadow(0 8px 14px rgba(0, 0, 0, .3)); }
#start-screen h1 {
    font-size: 40px; letter-spacing: 1px; margin: 2px 0 8px; color: #fff; -webkit-text-stroke: 2px #5a1e14; paint-order: stroke fill;
    text-shadow: 0 4px 0 #5a1e14, 0 6px 12px rgba(0, 0, 0, .35);
}
.desc {
    font-size: 15px; line-height: 1.4; max-width: 320px; margin-bottom: 12px; color: var(--ink); font-weight: bold;
    background: rgba(255, 255, 255, .82); border-radius: 14px; padding: 8px 14px; box-shadow: 0 3px 10px rgba(0, 0, 0, .15);
}
.skins { display: flex; gap: 8px; justify-content: center; margin-top: 8px; }
.skin { width: 52px; height: 52px; border-radius: 12px; background: rgba(255, 255, 255, .85); border: 3px solid transparent; box-shadow: 0 2px 6px rgba(0, 0, 0, .2); cursor: pointer; padding: 0; position: relative; }
.skin canvas { width: 100%; height: 100%; display: block; }
.skin.sel { border-color: var(--accent); }
.skin.locked canvas { filter: grayscale(1); opacity: .45; }
.skin.locked::after { content: '🔒'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 20px; }
.start-stats { font-size: 13px; margin-top: 4px; color: var(--ink); font-weight: bold; background: rgba(255, 255, 255, .72); border-radius: 12px; padding: 6px 12px; }
.start-stats:empty { display: none; }
@media (max-height: 640px) {
    #start-screen h1 { font-size: 32px; margin-bottom: 6px; }
    .desc { font-size: 14px; padding: 6px 12px; margin-bottom: 8px; }
    .btn { min-height: 46px; padding: 9px 18px; margin: 5px auto; }
}

/* ---------- game ---------- */
.hud { flex-shrink: 0; display: flex; align-items: center; gap: 8px; padding: 10px 12px 6px; position: relative; z-index: 2; }
html.in-frame .hud { padding-right: 12px; }
.scorebox { background: rgba(255, 255, 255, .93); color: var(--ink); border-radius: 16px; padding: 4px 14px 5px; box-shadow: 0 3px 10px rgba(0, 0, 0, .2); min-width: 104px; }
.scorebox b { display: block; font-size: 26px; line-height: 1.05; color: var(--accent-dark); }
.scorebox span { font-size: 12px; font-weight: bold; color: #7b5a45; }
.scorebox.pop b { animation: pop .25s ease; }
@keyframes pop { 50% { transform: scale(1.15); } }
.hud .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.best, .daily-badge { font-size: 13px; font-weight: bold; color: var(--ink); background: rgba(255, 255, 255, .72); border-radius: 12px; padding: 4px 10px; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.daily-badge { background: rgba(245, 158, 11, .92); color: #fff; font-size: 12px; }
.daily-badge:empty { display: none; }
.nextbox { width: 56px; height: 56px; border-radius: 50%; background: rgba(255, 255, 255, .93); box-shadow: 0 3px 10px rgba(0, 0, 0, .2); display: flex; align-items: center; justify-content: center; position: relative; flex-shrink: 0; }
.nextbox span { position: absolute; top: -9px; font-size: 10px; font-weight: bold; background: var(--accent); border-radius: 8px; padding: 1px 6px; white-space: nowrap; }
.nextbox canvas { width: 40px; height: 40px; }
.play { flex: 1; min-height: 0; position: relative; touch-action: none; cursor: pointer; }
.play canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.ladder { flex-shrink: 0; height: var(--ladder-h); position: relative; }
.ladder canvas { width: 100%; height: 100%; display: block; }
.hint {
    position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%); width: 260px; max-width: 86%; pointer-events: none;
    background: rgba(40, 20, 10, .78); border-radius: 16px; padding: 12px 14px; text-align: center; font-size: 16px; line-height: 1.35;
    opacity: 0; transition: opacity .3s;
}
.hint.show { opacity: 1; }
.hint small { display: block; font-size: 12px; opacity: .85; margin-top: 4px; }
.toast {
    position: absolute; left: 50%; top: 84px; transform: translate(-50%, -10px); background: rgba(40, 20, 10, .85); padding: 8px 14px; border-radius: 14px;
    font-weight: bold; font-size: 15px; opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none; z-index: 4; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- modals ---------- */
.modal-overlay { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); display: none; align-items: center; justify-content: center; padding: 14px; z-index: 10; }
.modal-overlay.show { display: flex; }
.modal {
    background: #fff; color: #374151; border-radius: 18px; padding: 20px 18px 0; width: 100%; max-width: 360px; text-align: center;
    box-shadow: 0 15px 35px rgba(0, 0, 0, .4); max-height: 100%; overflow-y: auto; overscroll-behavior: contain;
}
.modal h2 { font-size: 25px; color: var(--accent-dark); margin: 2px 0 4px; }
.modal .sub { font-size: 14px; color: #6b7280; margin-bottom: 6px; }
.modal p { font-size: 14px; line-height: 1.45; text-align: left; margin: 8px 0; }
.modal.help p { font-size: 15px; }
.bigscore { font-size: 46px; font-weight: 900; color: var(--accent); line-height: 1.1; }
.newbest { display: inline-block; background: var(--gold); color: #fff; font-weight: bold; font-size: 13px; border-radius: 10px; padding: 3px 10px; margin: 4px 0 2px; }
.stats { display: flex; justify-content: center; gap: 8px; margin: 10px 0 8px; }
.stat { background: #fdf0ec; border-radius: 12px; padding: 8px 8px; flex: 1; max-width: 120px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; }
.stat canvas { width: 44px; height: 44px; }
.stat b { display: block; font-size: 17px; color: var(--accent-dark); }
.stat b.n { font-size: 26px; margin: 6px 0 4px; }
.stat span { font-size: 12px; color: #6b7280; }
.daily-info { text-align: center !important; color: #6b4a10; }
.ach-new { display: flex; align-items: center; gap: 10px; background: #fff7e0; border: 2px solid #f6d27a; border-radius: 12px; padding: 7px 12px; text-align: left; font-size: 13px; color: #6b4a10; margin: 6px 0; }
.ach-new .ico, .ach .ico { font-size: 26px; flex-shrink: 0; }
.ach-new b { display: block; color: #8a5a00; font-size: 14px; }
.modal-buttons { position: sticky; bottom: 0; background: #fff; padding: 10px 0 16px; margin-top: 6px; }
.modal .btn { width: 100%; max-width: 260px; }
.modal .btn-secondary { border: 2px solid var(--accent); box-shadow: none; }
.help-ladder { width: 100%; height: auto; display: block; margin: 4px 0; }
.ach { display: flex; align-items: center; gap: 10px; text-align: left; padding: 7px 4px; border-bottom: 1px solid #f1e6e0; opacity: .45; filter: grayscale(1); }
.ach.on { opacity: 1; filter: none; }
.ach b { display: block; font-size: 15px; color: var(--accent-dark); }
.ach small { font-size: 13px; color: #6b7280; }

.ach-toast {
    position: absolute; left: 50%; top: 78px; transform: translate(-50%, -20px); display: flex; align-items: center; gap: 10px;
    background: #fff7e0; color: #6b4a10; border: 2px solid #f6d27a; border-radius: 14px; padding: 8px 14px; box-shadow: 0 6px 18px rgba(0, 0, 0, .3);
    opacity: 0; transition: opacity .3s, transform .3s; pointer-events: none; z-index: 20; white-space: nowrap;
}
.ach-toast.show { opacity: 1; transform: translate(-50%, 0); }
.ach-toast .ico { font-size: 26px; }
.ach-toast small { display: block; font-size: 11px; }
.ach-toast b { font-size: 15px; color: #8a5a00; }
