/* Shared menu components (screens, title, buttons, panels, tables) and the stage select, intro, results and continue screens. */

/* ---------- menus ---------- */
.screen {
    position: fixed; inset: 0; z-index: 20;
    display: none; flex-direction: column; align-items: center; justify-content: flex-start; text-align: center;
    padding: max(20px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
    background: radial-gradient(ellipse at center, rgba(10,2,6,.35) 0%, rgba(4,0,3,.85) 80%);
    overflow-y: auto; -webkit-overflow-scrolling: touch;
}
/* Centre with auto margins, not justify-content: when a screen is taller than the viewport
   (phones, landscape) the auto margins collapse to 0, so the top stays reachable by scrolling. */
.screen > :first-child { margin-top: auto; }
.screen > :last-child { margin-bottom: auto; }
.screen.show { display: flex; animation: fadeIn .35s ease-out; }
.screen.clear-bg { background: radial-gradient(ellipse at center, transparent 30%, rgba(4,0,3,.6) 100%); }
.title {
    font-family: 'Creepster', cursive; font-weight: 400; margin: 0; line-height: .9;
    font-size: min(clamp(48px, calc(var(--u) * 15), 200px), 13vw); letter-spacing: .04em; max-width: 100%;
    color: var(--blood);
    filter: drop-shadow(0 0 18px rgba(255,30,30,.55)) drop-shadow(5px 5px 0 #000);
    animation: titleBob 3s ease-in-out infinite;
    user-select: none; -webkit-user-select: none; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
    white-space: nowrap;           /* the letters are separate spans: never let the word wrap */
}
.coin-star { width: 1.7em; height: 1.7em; vertical-align: -.5em; margin-right: .45em; fill: var(--gold, #ffd54a); filter: drop-shadow(0 0 3px rgba(255,200,60,.8)); }
/* Each letter is its own span (see secret.js), each painted with the same blood gradient. */
.title .tl {
    display: inline-block;
    background: linear-gradient(180deg, #ffb3a0 0%, #ff2a2a 35%, #6d0000 100%);
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
    transition: filter .5s ease-out, transform .5s ease-out;
}
.title .tl.hit { filter: brightness(2.1) drop-shadow(0 0 10px rgba(255,220,170,.95)); transform: translateY(-3px) scale(1.07); transition: none; }
.secret-pip {
    position: fixed; z-index: 60; pointer-events: none; font-size: 13px; line-height: 1;
    transform: translate(-50%, -50%); opacity: 0; animation: secretPip .55s ease-out forwards;
    filter: drop-shadow(0 0 6px rgba(255,200,150,.9));
}
@keyframes secretPip { 20% { opacity: .9; } 100% { opacity: 0; transform: translate(-50%, -190%) scale(.8); } }
.secret-shake > * { animation: secretShake .55s linear !important; }   /* the children, so the screen's own fade-in isn't replayed */
@keyframes secretShake {
    10%, 50%, 90% { transform: translate(-9px, 4px) rotate(-.6deg); }
    30%, 70% { transform: translate(9px, -4px) rotate(.6deg); }
}
#secret-reveal {
    position: fixed; inset: 0; z-index: 80; pointer-events: none;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
    background: radial-gradient(circle at 50% 50%, rgba(20,0,0,.88) 0%, rgba(8,0,0,.72) 45%, rgba(0,0,0,.35) 100%);
    transition: opacity .6s;
}
#secret-reveal.out { opacity: 0; }
#secret-reveal .sk {
    font-size: min(38vw, 220px); line-height: 1;
    filter: drop-shadow(0 0 30px rgba(255,60,30,.9)) drop-shadow(0 0 80px rgba(255,180,60,.5));
    animation: secretSkull 1.1s cubic-bezier(.2, 1.6, .4, 1) both, secretFloat 2.4s 1.1s ease-in-out infinite;
}
#secret-reveal .l1, #secret-reveal .l2 { font-family: 'Creepster', cursive; letter-spacing: .08em; text-align: center; opacity: 0; animation: secretLine .5s ease-out forwards; }
#secret-reveal .l1 { color: #ffd8c8; font-size: min(6vw, 30px); animation-delay: .7s; text-shadow: 0 0 12px rgba(255,80,40,.8), 3px 3px 0 #000; }
#secret-reveal .l2 { color: var(--gold, #ffd54a); font-size: min(8vw, 44px); animation-delay: 1.2s; text-shadow: 0 0 18px rgba(255,200,60,.9), 3px 3px 0 #000; }
@keyframes secretSkull { from { transform: translateY(40%) scale(.1) rotate(-25deg); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes secretFloat { 50% { transform: translateY(-8px) rotate(2deg); } }
@keyframes secretLine { from { opacity: 0; transform: translateY(12px) scale(.9); } to { opacity: 1; transform: none; } }
.subtitle { margin: 14px 0 34px; font-size: clamp(8px, calc(var(--u) * 1.3), 14px); color: #d9b; letter-spacing: 4px; }
.h2 { font-family: 'Creepster', cursive; font-size: min(clamp(40px, calc(var(--u) * 9), 110px), 13vw); color: var(--blood); margin: 0 0 18px; text-shadow: 0 0 20px rgba(255,0,0,.6), 4px 4px 0 #000; font-weight: 400; }
.menu { display: flex; flex-direction: column; gap: 12px; align-items: stretch; min-width: min(320px, 80vw); }
.btn {
    font: inherit; font-size: clamp(12px, calc(var(--u) * 1.8), 18px); letter-spacing: 2px;
    padding: 16px 24px; cursor: pointer; color: var(--bone);
    background: linear-gradient(180deg, #3a0c12, #1a0508); border: 3px solid #6a1822; border-radius: 4px;
    box-shadow: 0 4px 0 #000, inset 0 0 0 2px rgba(255,255,255,.04);
    transition: transform .08s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:hover, .btn:focus-visible, .btn.sel { outline: none; border-color: var(--blood); color: #fff; box-shadow: 0 4px 0 #000, 0 0 18px rgba(255,40,40,.55); transform: translateY(-2px); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #000; }
.btn.primary { background: linear-gradient(180deg, #b01818, #5a0808); border-color: #ff4a3a; color: #fff; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.btn-row .btn { flex: 1 1 180px; }
.blink { animation: blink 1.1s steps(2) infinite; }
.foot { margin-top: 30px; font-size: clamp(7px, calc(var(--u) * 1), 11px); color: #866; letter-spacing: 2px; line-height: 2; }
.copyright { margin-top: 14px; font-size: clamp(6px, calc(var(--u) * .8), 9px); color: #5e4448; letter-spacing: 1px; line-height: 1.6; pointer-events: none; }
/* Short screens (a 960×600 itch.io embed, landscape phones): a tighter title so the whole menu fits. */
@media (max-height: 760px) {
    #scr-title .title { font-size: min(clamp(40px, calc(var(--u) * 11), 130px), 13vw); }
    #scr-title .subtitle { margin: 6px 0 12px; }
    #scr-title .menu { gap: 6px; }
    #scr-title .btn { padding: 9px 20px; }
    #scr-title .name-chip { margin-top: 10px; }
    #scr-title .foot { margin-top: 8px; line-height: 1.7; }
    #scr-title .copyright { margin-top: 6px; }
}

.panel { max-width: 680px; width: 100%; background: rgba(12,3,6,.8); border: 3px solid #4a121a; padding: clamp(16px, 3vw, 30px); border-radius: 6px; }

#scores-table { width: 100%; border-collapse: collapse; font-size: clamp(10px, calc(var(--u) * 1.5), 16px); margin-bottom: 22px; }
#scores-table td { padding: 8px 6px; border-bottom: 1px dashed #3a1016; }
#scores-table td:first-child { color: #a55; width: 3em; text-align: left; }
#scores-table td:nth-child(2) { text-align: left; }
#scores-table td:last-child { text-align: right; color: var(--gold); }
#scores-table tr.me td { color: #fff; text-shadow: 0 0 8px var(--blood); }
.table-note { font-size: 9px; color: #866; margin: -10px 0 18px; }

.stat-grid { display: grid; grid-template-columns: 1fr auto; gap: 10px 20px; font-size: clamp(9px, calc(var(--u) * 1.4), 15px); margin: 0 auto 22px; text-align: left; max-width: 440px; }
.stat-grid span:nth-child(even) { text-align: right; color: var(--gold); }
#final-score { font-size: clamp(26px, calc(var(--u) * 6), 64px); color: #fff; text-shadow: 0 0 20px var(--blood), 4px 4px 0 #000; margin: 4px 0 18px; }
#newbest { color: var(--gold); font-size: clamp(10px, calc(var(--u) * 1.6), 16px); margin-bottom: 16px; }
#rank { font-family: 'Creepster', cursive; font-size: clamp(60px, calc(var(--u) * 12), 130px); line-height: 1; margin-bottom: 4px; }
.rank-S { color: var(--gold); text-shadow: 0 0 30px var(--ember), 4px 4px 0 #000; animation: pulse .6s infinite alternate; }
.rank-A { color: #ff6a3a; text-shadow: 0 0 20px var(--blood), 4px 4px 0 #000; }
.rank-B, .rank-C, .rank-D { color: #b99; text-shadow: 4px 4px 0 #000; }

/* ---------- stage select ---------- */
#stage-cards { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; width: min(760px, 100%); margin-bottom: 14px; }
.act-label { grid-column: 1 / -1; font-size: 9px; letter-spacing: 4px; color: #e9b; text-shadow: 1px 1px 0 #000; text-align: left; margin: 4px 0 -2px; }
@media (max-width: 760px) { #stage-cards { grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); } }
.card {
    font: inherit; cursor: pointer; color: var(--bone); position: relative; overflow: hidden;
    aspect-ratio: 1 / 1; border-radius: 8px; border: 3px solid #3a1016; padding: 10px 6px;
    background: linear-gradient(180deg, var(--c1), var(--c2)); box-shadow: 0 5px 0 #000;
    display: flex; flex-direction: column; justify-content: space-between; align-items: center;
    transition: transform .12s, border-color .15s, box-shadow .15s;
}
.card::after { content: ''; position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 120%, rgba(0,0,0,0) 30%, rgba(0,0,0,.55)); pointer-events: none; }
.card > * { position: relative; z-index: 1; }
.card:hover, .card.sel { transform: translateY(-4px); border-color: #fff; box-shadow: 0 9px 0 #000, 0 0 24px var(--c1); }
.card.locked { filter: grayscale(1) brightness(.45); cursor: not-allowed; }
.card.shake { animation: shake .3s; }
.card-num { font-family: 'Creepster', cursive; font-size: clamp(28px, calc(var(--u) * 5), 54px); text-shadow: 3px 3px 0 #000; }
.card-name { font-size: clamp(7px, calc(var(--u) * 1), 11px); line-height: 1.6; text-shadow: 2px 2px 0 #000; }
.stars { color: #5a4a3a; letter-spacing: 2px; font-size: clamp(10px, calc(var(--u) * 1.6), 16px); }
.stars .on { color: var(--gold); text-shadow: 0 0 8px var(--ember); }
#stage-detail { width: min(640px, 100%); min-height: 120px; }
#sd-name { font-family: 'Creepster', cursive; font-size: clamp(28px, calc(var(--u) * 5), 54px); color: var(--blood); text-shadow: 3px 3px 0 #000; }
#sd-desc { font-size: clamp(8px, calc(var(--u) * 1.15), 12px); color: #cab; line-height: 1.9; margin: 8px 0 12px; }
#sd-meta { font-size: clamp(8px, calc(var(--u) * 1.1), 11px); color: var(--gold); margin-bottom: 16px; line-height: 1.9; }

/* ---------- stage intro ---------- */
#scr-intro { background: linear-gradient(180deg, rgba(0,0,0,.2), rgba(0,0,0,.75) 45%, rgba(0,0,0,.75) 55%, rgba(0,0,0,.2)); cursor: pointer; }
#in-num { font-size: clamp(10px, calc(var(--u) * 1.6), 16px); letter-spacing: 8px; color: #d9a; animation: slideIn .5s ease-out; }
#in-name { font-family: 'Creepster', cursive; font-size: min(clamp(52px, calc(var(--u) * 12), 150px), 14vw); color: var(--blood); line-height: 1; margin: 10px 0; text-shadow: 0 0 30px rgba(255,0,0,.6), 5px 5px 0 #000; animation: slamIn .5s cubic-bezier(.2,1.6,.4,1); }
#in-sub { font-size: clamp(8px, calc(var(--u) * 1.3), 13px); color: #cab; letter-spacing: 3px; animation: slideIn .6s ease-out; }
#in-goal { margin-top: 26px; font-size: clamp(9px, calc(var(--u) * 1.4), 14px); color: var(--gold); line-height: 2; animation: fadeIn 1s ease-out; }

/* ---------- results ---------- */
#res-title { margin-bottom: 8px; }
#res-sub { font-size: clamp(8px, calc(var(--u) * 1.2), 12px); color: #cab; margin-bottom: 18px; letter-spacing: 2px; }
#tally { display: grid; grid-template-columns: 1fr auto; gap: 12px 20px; font-size: clamp(9px, calc(var(--u) * 1.4), 15px); text-align: left; margin: 0 auto 18px; max-width: 460px; }
#tally .row { display: contents; }
#tally .row > span { opacity: 0; transform: translateX(-10px); transition: opacity .2s, transform .2s; }
#tally .row.in > span { opacity: 1; transform: none; }
#tally .row > span:last-child { text-align: right; color: var(--gold); }
#tally .row.total > span { font-size: 1.35em; color: #fff; padding-top: 10px; border-top: 2px dashed #4a1a22; }
#res-stars { font-size: clamp(36px, calc(var(--u) * 7), 70px); letter-spacing: 12px; min-height: 1.3em; margin-bottom: 16px; }
#res-stars span { display: inline-block; color: #3a2a2a; }
#res-stars span.on { color: var(--gold); text-shadow: 0 0 20px var(--ember), 3px 3px 0 #000; animation: starPop .45s cubic-bezier(.2,1.8,.4,1); }
#res-buttons { opacity: 0; transition: opacity .3s; }
#res-buttons.show { opacity: 1; }

/* ---------- continue ---------- */
#cont-num { font-family: 'Creepster', cursive; font-size: clamp(90px, calc(var(--u) * 22), 260px); color: #fff; line-height: 1; text-shadow: 0 0 40px var(--blood), 6px 6px 0 #000; }
#cont-num.tick { animation: contTick .9s ease-out; }
#cont-note { font-size: clamp(8px, calc(var(--u) * 1.1), 11px); color: #b99; margin: 10px 0 22px; line-height: 2; }

#loading { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: var(--ink); font-size: 12px; letter-spacing: 3px; color: #a55; }
#loading.hide { opacity: 0; pointer-events: none; transition: opacity .6s; }
