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

:root {
    --frame-bottom: 0px;
    --frame-left: 0px;
    --frame-right: 0px;
    --accent: #0f766e;
    --accent-dark: #115e59;
}

html, body {
    height: 100%;
}

/* Inside the site iframe a fixed footer bar (~40px, "Etusivu / Tietoa pelistä") covers the bottom.
   The site hides that bar when height <= 400px. */
html.in-frame { --frame-bottom: 44px; }
@media (max-height: 400px) {
    html.in-frame { --frame-bottom: 0px; }
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(160deg, #0f766e 0%, #155e75 55%, #1e3a8a 100%);
    background-attachment: fixed;
    color: #fff;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
}

#app {
    position: relative;
    width: 100%;
    height: calc(100vh - var(--frame-bottom));
    height: calc(100dvh - var(--frame-bottom));
}

.screen {
    display: none;
    position: absolute;
    inset: 0 var(--frame-right) 0 var(--frame-left);
    flex-direction: column;
    align-items: center;
}

.screen.active {
    display: flex;
}

/* ---------- Start screen ---------- */
#start-screen {
    justify-content: center;
    padding: 20px;
    text-align: center;
}

.logo .lens {
    display: inline-block;
    font-size: 70px;
    filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.35));
    margin-bottom: 4px;
}

#start-screen h1 {
    font-size: 44px;
    letter-spacing: 3px;
    margin-bottom: 10px;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.3);
}

#start-screen .desc {
    font-size: 17px;
    line-height: 1.5;
    max-width: 340px;
    margin-bottom: 22px;
}

.start-info {
    margin-top: 12px;
    font-size: 15px;
    opacity: 0.95;
    min-height: 1.2em;
}

/* ---------- Buttons ---------- */
.btn {
    display: block;
    width: 270px;
    max-width: 100%;
    border: none;
    padding: 14px 20px;
    margin: 6px auto;
    font-size: 18px;
    font-weight: bold;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    font-family: inherit;
}

.btn:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); }
.btn:active { transform: translateY(0); }

.btn-primary { background: #fff; color: var(--accent); }
.btn-secondary { background: rgba(255, 255, 255, 0.18); color: #fff; border: 2px solid rgba(255, 255, 255, 0.7); }
.btn-ghost { background: transparent; color: #fff; box-shadow: none; text-decoration: underline; font-size: 16px; padding: 8px; }
.btn.done { background: #d1fae5; color: #166534; border-color: #d1fae5; }

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.7);
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    flex-shrink: 0;
}

.icon-spacer { width: 40px; flex-shrink: 0; }

/* ---------- Bars ---------- */
.bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    max-width: 1200px;
    padding: 8px 10px;
}

.bar-title { font-size: 19px; font-weight: bold; text-align: center; text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.3); }
.bar-center { flex: 1; text-align: center; min-width: 0; }

.status {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-top: 3px;
    font-size: 15px;
    font-weight: bold;
}

.lives { letter-spacing: 1px; font-size: 15px; }
.lives .lost { opacity: 0.25; }
.found { background: rgba(0, 0, 0, 0.22); border-radius: 10px; padding: 2px 10px; }
.timer { font-variant-numeric: tabular-nums; opacity: 0.9; min-width: 40px; }

.hint-btn {
    display: flex;
    align-items: center;
    gap: 3px;
    height: 40px;
    padding: 0 10px;
    border-radius: 20px;
    border: 2px solid rgba(255, 255, 255, 0.7);
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-family: inherit;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    flex-shrink: 0;
}
.hint-btn .ico { font-size: 18px; }
.hint-btn:disabled { opacity: 0.4; cursor: default; }

/* ---------- Chapter / level select ---------- */
#select-screen { overflow-y: auto; padding-bottom: 20px; }

.chapters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 14px;
    width: 100%;
    max-width: 760px;
    padding: 6px 14px;
}

.chapter-card {
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.12);
    border: 2px solid rgba(255, 255, 255, 0.4);
    cursor: pointer;
    text-align: left;
    color: #fff;
    font-family: inherit;
    padding: 0;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}
.chapter-card svg { display: block; width: 100%; height: auto; aspect-ratio: 600 / 420; }
.chapter-card .info { padding: 10px 12px; }
.chapter-card .name { font-size: 19px; font-weight: bold; }
.chapter-card .sub { font-size: 14px; opacity: 0.9; margin-top: 2px; }
.chapter-card.locked { opacity: 0.55; cursor: default; }
.chapter-card.endless .thumb { height: 90px; display: flex; align-items: center; justify-content: center; font-size: 44px; background: rgba(0, 0, 0, 0.2); }

.level-grid {
    display: none;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    width: 100%;
    max-width: 520px;
    padding: 6px 16px;
}
.level-grid.show { display: grid; }

.level-btn {
    aspect-ratio: 1;
    border-radius: 14px;
    border: 2px solid rgba(255, 255, 255, 0.55);
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    font-family: inherit;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
}
.level-btn .st { font-size: 11px; letter-spacing: 1px; color: #fde047; min-height: 13px; }
.level-btn.next { background: #fff; color: var(--accent); border-color: #fff; }
.level-btn.locked { opacity: 0.35; cursor: default; }

/* ---------- Game ---------- */
#game-screen { padding-bottom: calc(6px + env(safe-area-inset-bottom)); }

.panels {
    flex: 1;
    min-height: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 6px;
}
.panels.side { flex-direction: row; }

.panel {
    position: relative;
    overflow: hidden;
    border-radius: 10px;
    background: #0b1220;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
    touch-action: none;
    cursor: crosshair;
    flex-shrink: 0;
}
.panel.shake { animation: shake 0.35s; }

.layer {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    transform-origin: 0 0;
}
.layer.animate { transition: transform 0.25s ease; }

.scene { display: block; width: 100%; height: 100%; }

.mark-found { fill: none; stroke: #ef4444; stroke-width: 3.5; animation: markIn 0.3s ease; }
.mark-found-halo { fill: none; stroke: #fff; stroke-width: 6.5; opacity: 0.85; animation: markIn 0.3s ease; }
.mark-wrong { stroke: #ef4444; stroke-width: 4; stroke-linecap: round; animation: wrongFade 0.9s ease forwards; }
.mark-hint { fill: rgba(253, 224, 71, 0.18); stroke: #fde047; stroke-width: 3.5; stroke-dasharray: 7 5; animation: hintPulse 0.7s ease-in-out infinite alternate; }

.zoom-hint {
    font-size: 12px;
    opacity: 0.75;
    padding: 4px 0 0;
    text-align: center;
}

/* ---------- Modals ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 400;
    padding: 16px calc(16px + var(--frame-right)) calc(16px + var(--frame-bottom)) calc(16px + var(--frame-left));
}

.modal-overlay.show { display: flex; }

.modal {
    background: #fff;
    color: #374151;
    border-radius: 16px;
    padding: 24px 20px;
    width: 100%;
    max-width: 380px;
    max-height: 100%;
    overflow-y: auto;
    text-align: center;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.4);
    animation: modalIn 0.25s ease;
}

.modal h2 { font-size: 24px; margin-bottom: 8px; color: var(--accent); }
.modal .btn-primary { background: var(--accent); color: #fff; }
.modal .btn-secondary { background: #fff; color: var(--accent); border-color: var(--accent); }

.stars { font-size: 46px; letter-spacing: 6px; margin: 2px 0 6px; }
.stars:empty { display: none; }
.stars .on { color: #f59e0b; text-shadow: 0 2px 6px rgba(245, 158, 11, 0.5); display: inline-block; animation: starPop 0.4s ease backwards; }
.stars .off { color: #d1d5db; }
.stars .on:nth-child(2) { animation-delay: 0.15s; }
.stars .on:nth-child(3) { animation-delay: 0.3s; }

.result-text { font-size: 15px; line-height: 1.45; }
.modal-buttons { margin-top: 14px; }
.modal-buttons .btn { width: 100%; max-width: 260px; }

.modal.help { text-align: left; }
.modal.help h2 { text-align: center; }
.modal.help p { font-size: 15px; line-height: 1.45; margin: 8px 0; }

/* ---------- Animations ---------- */
@keyframes shake {
    20%, 60% { transform: translateX(-5px); }
    40%, 80% { transform: translateX(5px); }
}
@keyframes markIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes wrongFade { 0% { opacity: 1; } 70% { opacity: 1; } 100% { opacity: 0; } }
@keyframes hintPulse { from { opacity: 0.55; } to { opacity: 1; } }
@keyframes starPop { from { transform: scale(0); } 70% { transform: scale(1.3); } to { transform: scale(1); } }
@keyframes modalIn { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- Small / short screens ---------- */
@media (max-width: 360px) {
    #start-screen h1 { font-size: 36px; }
    .status { gap: 8px; font-size: 14px; }
    .level-grid { gap: 7px; }
}

@media (max-height: 600px) {
    #start-screen h1 { font-size: 32px; margin-bottom: 6px; }
    .logo { display: none; }
    #start-screen .desc { margin-bottom: 12px; font-size: 15px; }
    .btn { padding: 10px 18px; font-size: 16px; margin: 4px auto; }
    .zoom-hint { display: none; }
}
