@font-face { font-family: 'Lilita One'; font-style: normal; font-weight: 400; font-display: swap; src: url(../fonts/lilita-one-latin.woff2) format('woff2'); }
@font-face { font-family: 'Figtree'; font-style: normal; font-weight: 300 900; font-display: swap; src: url(../fonts/figtree-latin.woff2) format('woff2'); }

:root {
    --ember: #E8552B;      /* brändiväri: kesäillan nuotio / kisapaita */
    --limsa: #F7C948;      /* palkintolimsa */
    --lake: #2F67B1;       /* Sonkajärvi */
    --ink: #24324A;
    --paper: #FFF8EA;
    --paper2: #FCEFD2;
    --good: #2E9E5B;
    --bad: #D9473B;
    --pad-h: 64px;
    --display: 'Lilita One', 'Arial Rounded MT Bold', sans-serif;
    --body: 'Figtree', 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #7CC6EE; color: var(--ink); font-family: var(--body); -webkit-tap-highlight-color: transparent; }
body { touch-action: manipulation; user-select: none; -webkit-user-select: none; }
canvas#cv { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; }
button { font: inherit; color: inherit; cursor: pointer; }
svg { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

/* ---------- yläpalkki ---------- */
.top { position: fixed; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 10px; padding: max(8px, env(safe-area-inset-top)) 12px 6px; pointer-events: none; z-index: 5; }
.top > * { pointer-events: auto; }
.back { font-weight: 800; color: var(--ink); text-decoration: none; background: var(--paper); border: 2.5px solid var(--ink); border-radius: 999px; padding: 5px 12px; box-shadow: 2px 2px 0 var(--ink); font-size: 14px; white-space: nowrap; }
.back { display: inline-flex; align-items: center; gap: 4px; }
.back svg { width: 16px; height: 16px; stroke-width: 2.8; }
.back:hover { background: var(--limsa); }
.brand { display: flex; align-items: center; gap: 6px; }
.brand img { width: 34px; height: 34px; }
.brand-name { font-family: var(--display); font-size: 22px; color: var(--paper); -webkit-text-stroke: 1px var(--ink); paint-order: stroke fill; text-shadow: 2px 2px 0 var(--ink); letter-spacing: .5px; }
.hud { margin: 0 auto; text-align: center; line-height: 1; }
.timer { font-family: var(--display); font-size: clamp(28px, 6vw, 52px); color: #fff; text-shadow: 3px 3px 0 var(--ink), -1px -1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink); font-variant-numeric: tabular-nums; min-width: 4.5ch; }
.pen { font-family: var(--display); font-size: 16px; color: var(--bad); text-shadow: 1px 1px 0 #fff; min-height: 16px; }
.tools { display: flex; gap: 6px; }
.ico-btn, .lang-btn { width: 40px; height: 40px; border-radius: 12px; border: 2.5px solid var(--ink); background: var(--paper); box-shadow: 2px 2px 0 var(--ink); display: grid; place-items: center; padding: 0; }
.ico-btn svg { width: 20px; height: 20px; }
.lang-btn { font-weight: 800; font-size: 14px; }
.ico-btn:active, .lang-btn:active, .back:active { transform: translate(2px, 2px); box-shadow: none; }
#btnSound .off { display: none; }
#btnSound[aria-pressed="false"] .on { display: none; }
#btnSound[aria-pressed="false"] .off { display: block; }

/* ---------- radan edistyminen ---------- */
.progress { position: fixed; top: calc(max(8px, env(safe-area-inset-top)) + 58px); left: 50%; transform: translateX(-50%); width: min(520px, 80vw); height: 14px; z-index: 4; pointer-events: none; }
.progress-track { position: absolute; inset: 4px 0; background: rgba(255, 248, 234, .85); border: 2px solid var(--ink); border-radius: 99px; }
.progress-track i { position: absolute; top: -5px; width: 12px; height: 12px; margin-left: -6px; border-radius: 50%; border: 2px solid var(--ink); }
.progress-track i.hurdle { background: #9A6A3C; border-radius: 3px; }
.progress-track i.water { background: var(--lake); width: auto; border-radius: 6px; margin-left: 0; }
.progress-track i.sand { background: #EFCF8A; width: auto; border-radius: 6px 6px 2px 2px; margin-left: 0; }
.progress-runner { position: absolute; top: -3px; left: 0; width: 18px; height: 18px; margin-left: -9px; border-radius: 50%; background: var(--ember); border: 2.5px solid var(--ink); transition: none; }

/* ---------- tasapaino- ja rytmimittari ---------- */
.meters { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--pad-h) + 14px + env(safe-area-inset-bottom)); width: min(440px, 88vw); z-index: 4; pointer-events: none; display: grid; gap: 6px; }
.meter { display: flex; align-items: center; gap: 8px; }
.meter-label { font-family: var(--display); font-size: 14px; color: #fff; text-shadow: 1px 1px 0 var(--ink), -1px -1px 0 var(--ink); min-width: 6.5ch; }
.meter-bar { position: relative; flex: 1; height: 20px; border-radius: 99px; border: 2.5px solid var(--ink); background: linear-gradient(90deg, #F6B9A9 0 12.5%, #FFF4D6 12.5% 87.5%, #F6B9A9 87.5%); overflow: hidden; }
.meter-bar::after { content: ''; position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; background: rgba(36, 50, 74, .35); }
.meter-bar .zone { position: absolute; top: 0; bottom: 0; width: 12.5%; background: repeating-linear-gradient(45deg, var(--bad) 0 4px, #E86E61 4px 8px); opacity: .85; }
.meter-bar .zl { left: 0; } .meter-bar .zr { right: 0; }
.needle { position: absolute; top: -2px; bottom: -2px; left: 50%; width: 10px; margin-left: -5px; border-radius: 4px; background: var(--ink); will-change: transform; }
.meters.danger .meter-bar { animation: pulse .35s infinite alternate; }
@keyframes pulse { to { box-shadow: 0 0 0 4px rgba(217, 71, 59, .55); } }
.rhythm { display: flex; align-items: center; gap: 8px; }
.rhythm-bar { position: relative; flex: 1; height: 10px; border-radius: 99px; background: rgba(255, 248, 234, .8); border: 2px solid var(--ink); margin-left: calc(6.5ch + 8px); }
.rhythm-bar .sweet { position: absolute; top: 0; bottom: 0; background: #7FD39A; }
.rhythm-bar .tick { position: absolute; top: -5px; width: 4px; height: 16px; margin-left: -2px; background: var(--ink); border-radius: 2px; left: 50%; }
.rhythm-label { font-weight: 800; font-size: 13px; min-width: 9ch; color: #fff; text-shadow: 1px 1px 0 var(--ink), -1px -1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink); }
.rhythm-label.fast, .rhythm-label.same { color: #FFB4A8; }
.rhythm-label.good { color: #B8F5C8; }
.rhythm-label.slow { color: #FFE38A; }

/* ---------- huudot ---------- */
.callout { position: fixed; left: 50%; top: 26%; transform: translate(-50%, -50%); z-index: 6; pointer-events: none; font-family: var(--display); font-size: clamp(30px, 7vw, 72px); color: #fff; text-align: center; text-shadow: 4px 4px 0 var(--ink), -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink); white-space: nowrap; opacity: 0; }
.callout.show { animation: pop 1.1s ease-out forwards; }
.callout.good { color: #B8F5C8; } .callout.bad { color: #FFB4A8; } .callout.gold { color: var(--limsa); }
@keyframes pop { 0% { opacity: 0; transform: translate(-50%, -30%) scale(.6) rotate(-4deg); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.08) rotate(-2deg); } 25% { transform: translate(-50%, -50%) scale(1) rotate(-2deg); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -64%) scale(1) rotate(-2deg); } }
.announcer { position: fixed; left: 12px; top: calc(max(8px, env(safe-area-inset-top)) + 84px); z-index: 4; max-width: min(460px, calc(100vw - 24px)); display: flex; align-items: center; gap: 8px; background: var(--ink); color: var(--paper); padding: 8px 14px 8px 10px; border-radius: 14px 14px 14px 4px; font-weight: 700; font-size: 15px; box-shadow: 3px 3px 0 rgba(36, 50, 74, .35); animation: slidein .3s ease-out; }
.announcer svg { width: 20px; height: 20px; flex: none; color: var(--limsa); }
@keyframes slidein { from { transform: translateX(-30px); opacity: 0; } }

/* ---------- paneelit ---------- */
.panel { position: fixed; z-index: 8; background: var(--paper); border: 3px solid var(--ink); border-radius: 22px; box-shadow: 6px 6px 0 var(--ink); padding: 18px 20px 16px; overflow: auto; max-height: calc(100dvh - var(--pad-h) - 96px); user-select: none; }
.start-panel { top: 76px; left: max(16px, 4vw); width: min(430px, calc(100vw - 32px)); }
.start-title { font-family: var(--display); font-weight: 400; font-size: clamp(40px, 8vw, 58px); line-height: .95; margin: 0; color: var(--ember); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 3px 3px 0 var(--ink); transform: rotate(-2.5deg); transform-origin: left; }
.tagline { margin: 6px 0 12px; font-weight: 600; }
.challenge-banner { margin: -4px 0 10px; background: var(--limsa); border: 2.5px solid var(--ink); border-radius: 12px; padding: 8px 12px; font-weight: 800; transform: rotate(1deg); }
.modes { display: flex; flex-wrap: wrap; gap: 6px; }
.modes button { border: 2.5px solid var(--ink); background: #fff; border-radius: 999px; padding: 6px 12px; font-weight: 800; font-size: 14px; }
.modes button[aria-selected="true"] { background: var(--ink); color: var(--paper); }
.mode-info { font-size: 14px; margin: 8px 0 4px; min-height: 1.3em; color: #4A5872; }
.sec-title { font-family: var(--display); font-weight: 400; font-size: 20px; margin: 12px 0 6px; letter-spacing: .3px; }
.styles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.style-card { text-align: left; border: 2.5px solid var(--ink); background: #fff; border-radius: 14px; padding: 8px; display: grid; gap: 4px; align-content: start; }
.style-card svg.fig { width: 100%; height: 54px; stroke-width: 2.6; }
.style-card b { font-size: 14px; line-height: 1.1; }
.style-card small { font-size: 11.5px; line-height: 1.2; color: #4A5872; min-height: 2.4em; }
.style-card[aria-pressed="true"] { background: var(--limsa); box-shadow: 3px 3px 0 var(--ink); transform: translate(-1px, -1px); }
.stats { display: grid; gap: 2px; font-size: 10.5px; font-weight: 700; }
.stats span { display: grid; grid-template-columns: 4.6em 1fr; align-items: center; gap: 4px; }
.stats i { height: 6px; border-radius: 3px; background: linear-gradient(90deg, var(--ember) var(--v), #E8DCC2 var(--v)); }
.partners { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.partner { border: 2.5px solid var(--ink); background: #fff; border-radius: 14px; padding: 6px 4px; display: grid; justify-items: center; gap: 1px; font-size: 12px; }
.partner svg { width: 40px; height: 40px; stroke: none; }
.partner b { font-size: 14px; }
.partner small { font-size: 10.5px; color: #4A5872; text-align: center; line-height: 1.15; }
.partner[aria-pressed="true"] { background: var(--limsa); box-shadow: 3px 3px 0 var(--ink); transform: translate(-1px, -1px); }
.go-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 3px solid var(--ink); background: var(--ember); color: #fff; font-family: var(--display); font-size: 22px; padding: 10px 20px; border-radius: 16px; box-shadow: 4px 4px 0 var(--ink); margin-top: 14px; text-shadow: 1px 1px 0 var(--ink); }
.go-btn svg { width: 22px; height: 22px; stroke-width: 3; }
.go-btn:active, .sec-btn:active, .style-card:active, .partner:active { transform: translate(3px, 3px); box-shadow: none; }
.go-btn kbd { font-family: var(--body); font-size: 12px; background: rgba(0, 0, 0, .2); border-radius: 6px; padding: 1px 6px; }
.hint { font-size: 13px; margin: 10px 0 0; color: #4A5872; }
.hint.small { font-size: 12px; margin-top: 4px; }
.account { margin-top: 12px; padding-top: 10px; border-top: 2px dashed #D9C9A6; font-size: 13px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-height: 1em; }
.account:empty { display: none; }
.account a, .link-btn { color: var(--lake); font-weight: 800; background: none; border: 0; padding: 0; text-decoration: underline; text-underline-offset: 3px; }
.account .me { font-weight: 800; }

.result-panel { top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(460px, calc(100vw - 24px)); text-align: center; max-height: calc(100dvh - 24px); }
.res-title { font-family: var(--display); font-weight: 400; font-size: 34px; margin: 0; color: var(--ember); -webkit-text-stroke: 1.5px var(--ink); paint-order: stroke fill; text-shadow: 2px 2px 0 var(--ink); transform: rotate(-2deg); }
.res-time { font-family: var(--display); font-size: clamp(52px, 14vw, 78px); line-height: 1; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.res-stars { display: flex; justify-content: center; gap: 4px; min-height: 34px; }
.res-stars svg { width: 34px; height: 34px; stroke: var(--ink); stroke-width: 1.8; fill: #E8DCC2; }
.res-stars svg.on { fill: var(--limsa); animation: starpop .4s ease-out backwards; }
.res-stars svg:nth-child(2) { animation-delay: .15s; } .res-stars svg:nth-child(3) { animation-delay: .3s; }
@keyframes starpop { from { transform: scale(0) rotate(-40deg); } }
.res-break { display: grid; grid-template-columns: 1fr auto; gap: 2px 16px; margin: 10px auto; max-width: 260px; text-align: left; font-size: 15px; }
.res-break dt { color: #4A5872; } .res-break dd { margin: 0; font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }
.res-break .newbest { color: var(--good); }
.res-emoji { font-size: 24px; letter-spacing: 2px; margin: 4px 0; }
.res-prize { font-weight: 700; margin: 6px 0; background: var(--paper2); border-radius: 12px; padding: 8px 10px; }
.res-prize.win { background: var(--limsa); border: 2.5px solid var(--ink); }
.res-ch { font-weight: 800; margin: 6px 0; }
.res-api { font-size: 13px; color: #4A5872; margin: 4px 0; }
.res-api a { color: var(--lake); font-weight: 800; }
.res-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 4px; }
.res-actions .go-btn { width: 100%; margin-top: 6px; }
.sec-btn { display: inline-flex; align-items: center; gap: 6px; border: 2.5px solid var(--ink); background: #fff; border-radius: 12px; padding: 7px 12px; font-weight: 800; font-size: 14px; box-shadow: 2px 2px 0 var(--ink); }
.sec-btn svg { width: 18px; height: 18px; }
.nick-row { margin-top: 12px; text-align: left; font-size: 13px; font-weight: 700; }
.nick-row div { display: flex; gap: 6px; margin-top: 4px; }
.nick-row input { flex: 1; min-width: 0; font: inherit; font-size: 16px; border: 2.5px solid var(--ink); border-radius: 10px; padding: 6px 10px; background: #fff; user-select: text; }

.top-panel { top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(420px, calc(100vw - 24px)); }
.top-panel h2, .pause-panel h2 { font-family: var(--display); font-weight: 400; font-size: 30px; margin: 0 0 10px; }
.top-list { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 4px; font-size: 15px; min-height: 60px; }
.top-list li { display: grid; grid-template-columns: 2.2em 1fr auto; gap: 8px; padding: 5px 8px; border-radius: 8px; background: #fff; }
.top-list li.me { background: var(--limsa); }
.top-list li b { font-variant-numeric: tabular-nums; }
.top-list li.msg { display: block; background: none; color: #4A5872; }
.pause-panel { top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; min-width: 240px; }

/* ---------- kosketuspadit ---------- */
.pads { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--pad-h) + env(safe-area-inset-bottom)); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: 1fr .8fr 1fr; gap: 8px; z-index: 3; }
.pad { border: 3px solid var(--ink); border-radius: 18px; background: rgba(255, 248, 234, .78); font-family: var(--display); font-size: 18px; letter-spacing: .5px; touch-action: none; box-shadow: 0 4px 0 var(--ink); }
.pad-j { background: rgba(247, 201, 72, .9); }
.pad.down { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); background: #fff; }
@media (pointer: fine) {
    .pads { opacity: .55; width: min(560px, 90vw); left: 50%; transform: translateX(-50%); right: auto; }
    .pads:hover { opacity: .9; }
}
@media (pointer: coarse) {
    :root { --pad-h: clamp(110px, 21vh, 180px); }
    .pads { grid-template-columns: 1fr 1fr; grid-template-rows: .8fr 1fr; }
    .pad-j { grid-column: 1 / 3; grid-row: 1; font-size: 20px; }
    .pad-l { grid-row: 2; grid-column: 1; font-size: 22px; }
    .pad-r { grid-row: 2; grid-column: 2; font-size: 22px; }
}

/* ---------- pienet näytöt ---------- */
@media (max-width: 640px) {
    .brand { display: none; }
    .back { font-size: 13px; padding: 4px 10px; }
    .start-panel { top: auto; bottom: calc(var(--pad-h) + 8px); left: 8px; right: 8px; width: auto; max-height: calc(100dvh - var(--pad-h) - 70px); padding: 14px 14px 12px; border-radius: 18px; }
    .start-title { font-size: 38px; }
    .styles { gap: 5px; } .style-card { padding: 6px; } .style-card small { display: none; } .style-card svg.fig { height: 40px; }
    .partners { gap: 4px; } .partner small { display: none; }
    .go-btn { width: 100%; }
    .announcer { font-size: 13px; top: calc(max(8px, env(safe-area-inset-top)) + 76px); }
    .progress { top: calc(max(8px, env(safe-area-inset-top)) + 50px); }
}
@media (min-width: 1800px) {
    .start-panel { width: 500px; font-size: 17px; }
}

/* ---------- toast, embed ---------- */
.toast { position: fixed; left: 50%; bottom: calc(var(--pad-h) + 90px); transform: translate(-50%, 20px); background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 12px; font-weight: 700; z-index: 20; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.embed-link { display: none; position: fixed; left: 8px; top: max(8px, env(safe-area-inset-top)); z-index: 9; font-family: var(--display); font-size: 14px; color: var(--ink); background: var(--paper); border: 2px solid var(--ink); border-radius: 8px; padding: 2px 8px; text-decoration: none; }
body.embed .embed-link { display: block; }
body.embed .back, body.embed #btnPause, body.embed #btnLang, body.embed .brand, body.embed .start-panel, body.embed #btnShare, body.embed #btnChallenge, body.embed #btnChange, body.embed #btnTop, body.embed .res-api, body.embed .nick-row { display: none !important; }
.credits { display: none; }
body.running .start-panel { display: none; }
