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

:root {
    --frame-bottom: 0px;
    --frame-left: 0px;
    --frame-right: 0px;
    --ball: 44px;
    --accent: #6d28d9;
}

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(135deg, #3b2a8f 0%, #7b2ff7 55%, #c471ed 100%);
    background-attachment: fixed;
    color: #fff;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
}

#app {
    position: relative;
    width: 100%;
    max-width: 560px;
    height: calc(100vh - var(--frame-bottom));
    height: calc(100dvh - var(--frame-bottom));
    margin: 0 auto;
}

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

.screen.active {
    display: flex;
}

/* ---------- Balls (shared) ---------- */
.ball {
    position: relative;
    display: block;
    width: var(--ball);
    height: var(--ball);
    border-radius: 50%;
    box-shadow: inset -4px -6px 10px rgba(0, 0, 0, 0.35), inset 3px 4px 8px rgba(255, 255, 255, 0.45), 0 2px 4px rgba(0, 0, 0, 0.3);
}

.ball.c0 { background: radial-gradient(circle at 35% 30%, #ff8a80, #e53935 60%, #b71c1c); }
.ball.c1 { background: radial-gradient(circle at 35% 30%, #82b1ff, #1e88e5 60%, #0d47a1); }
.ball.c2 { background: radial-gradient(circle at 35% 30%, #b9f6ca, #43a047 60%, #1b5e20); }
.ball.c3 { background: radial-gradient(circle at 35% 30%, #fff59d, #fdd835 60%, #f9a825); }
.ball.c4 { background: radial-gradient(circle at 35% 30%, #ea80fc, #8e24aa 60%, #4a148c); }
.ball.c5 { background: radial-gradient(circle at 35% 30%, #ffd180, #fb8c00 60%, #e65100); }
.ball.c6 { background: radial-gradient(circle at 35% 30%, #84ffff, #00acc1 60%, #006064); }
.ball.c7 { background: radial-gradient(circle at 35% 30%, #ff80ab, #ec407a 60%, #ad1457); }
.ball.c8 { background: radial-gradient(circle at 35% 30%, #f4ff81, #aeea00 60%, #64a300); }
.ball.c9 { background: radial-gradient(circle at 35% 30%, #d7a98c, #8d5b45 60%, #4e342e); }
.ball.c10 { background: radial-gradient(circle at 35% 30%, #ffffff, #e0e0e0 60%, #9e9e9e); }
.ball.c11 { background: radial-gradient(circle at 35% 30%, #90a4ae, #37474f 60%, #15191c); }

/* Colour-blind helper symbols */
.symbols .ball::after {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(var(--ball) * 0.42);
    font-weight: bold;
    color: rgba(255, 255, 255, 0.92);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
    line-height: 1;
}
.symbols .ball.c0::after { content: '●'; }
.symbols .ball.c1::after { content: '■'; }
.symbols .ball.c2::after { content: '▲'; }
.symbols .ball.c3::after { content: '★'; color: rgba(0, 0, 0, 0.6); text-shadow: none; }
.symbols .ball.c4::after { content: '◆'; }
.symbols .ball.c5::after { content: '✚'; }
.symbols .ball.c6::after { content: '♥'; }
.symbols .ball.c7::after { content: '♠'; }
.symbols .ball.c8::after { content: '♣'; color: rgba(0, 0, 0, 0.6); text-shadow: none; }
.symbols .ball.c9::after { content: '✖'; }
.symbols .ball.c10::after { content: '◯'; color: rgba(0, 0, 0, 0.55); text-shadow: none; }
.symbols .ball.c11::after { content: '▼'; }

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

.logo {
    display: flex;
    gap: 10px;
    margin-bottom: 18px;
    --ball: 30px;
}

.logo-tube {
    display: flex;
    flex-direction: column-reverse;
    gap: 3px;
    padding: 4px 4px 5px;
    min-height: 116px;
    background: rgba(255, 255, 255, 0.18);
    border: 2px solid rgba(255, 255, 255, 0.55);
    border-top: none;
    border-radius: 0 0 22px 22px;
}

#start-screen h1 {
    font-size: 40px;
    letter-spacing: 2px;
    margin-bottom: 12px;
    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: 24px;
}

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

/* ---------- Buttons ---------- */
.btn {
    display: block;
    width: 250px;
    max-width: 100%;
    border: none;
    padding: 14px 20px;
    margin: 7px auto;
    font-size: 19px;
    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); }

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

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

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 4px 6px 6px;
}

.level-label {
    font-size: 22px;
    font-weight: bold;
    letter-spacing: 1px;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.3);
}

#board-wrap {
    flex: 1;
    min-height: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#board {
    display: flex;
    flex-direction: column;
    gap: var(--row-gap, 20px);
}

.tube-row {
    display: flex;
    justify-content: center;
    gap: var(--tube-gap, 12px);
}

.tube-slot {
    padding-top: calc(var(--ball) + 10px); /* room for the lifted ball */
    cursor: pointer;
}

.tube {
    position: relative;
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    gap: var(--ball-gap, 3px);
    width: calc(var(--ball) + 10px);
    height: calc(var(--ball) * 4 + var(--ball-gap, 3px) * 3 + 14px);
    padding: 4px 0 6px;
    background: rgba(255, 255, 255, 0.16);
    border: 2px solid rgba(255, 255, 255, 0.6);
    border-top: none;
    border-radius: 0 0 calc(var(--ball) * 0.6) calc(var(--ball) * 0.6);
    box-shadow: inset 0 0 12px rgba(255, 255, 255, 0.15);
    transition: box-shadow 0.2s, border-color 0.2s, transform 0.15s;
}

.tube::before {
    /* glass rim */
    content: '';
    position: absolute;
    top: -2px;
    left: -6px;
    right: -6px;
    height: 6px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.7);
}

.tube-slot.selected .tube { border-color: #fff; box-shadow: inset 0 0 14px rgba(255, 255, 255, 0.35), 0 0 14px rgba(255, 255, 255, 0.5); }
.tube-slot.hint-from .tube, .tube-slot.hint-to .tube { border-color: #fde047; box-shadow: 0 0 18px 4px rgba(253, 224, 71, 0.8); }
.tube-slot.done-static .tube { border-color: #a7f3d0; box-shadow: 0 0 16px 3px rgba(167, 243, 208, 0.7); }
.tube-slot.done .tube { animation: tubeDone 0.5s ease; }
.tube-slot.shake .tube { animation: shake 0.4s; }
.tube-slot.extra .tube { border-style: dashed; }

.tube .ball {
    transition: transform 0.15s ease;
}

.tube .ball.lifted {
    transform: translateY(var(--lift, -60px));
}

.tube .ball.flying {
    z-index: 5;
    transition: transform 0.28s cubic-bezier(0.3, 0.7, 0.4, 1);
}

/* ---------- Toolbar ---------- */
.toolbar {
    display: flex;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding-top: 8px;
}

.tool-btn {
    flex: 1;
    max-width: 110px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 4px;
    border: 2px solid rgba(255, 255, 255, 0.6);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    font-family: inherit;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
}

.tool-btn .ico { font-size: 20px; line-height: 1.1; }
.tool-btn:active { background: rgba(255, 255, 255, 0.3); }
.tool-btn:disabled { opacity: 0.4; cursor: default; }

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    top: 64px;
    left: 50%;
    transform: translateX(-50%);
    max-width: calc(100% - 32px);
    background: #111827;
    color: #fff;
    padding: 10px 16px;
    border-radius: 8px;
    font-weight: bold;
    font-size: 14px;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 500;
}

.toast.show { opacity: 1; }

/* ---------- 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: 26px;
    margin-bottom: 10px;
    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: 4px 0 8px;
}

.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; }

.check {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin-top: 12px;
    font-size: 14px;
    line-height: 1.4;
    cursor: pointer;
}

.check input { width: 20px; height: 20px; margin-top: 1px; flex-shrink: 0; accent-color: var(--accent); }

/* ---------- Animations ---------- */
@keyframes shake {
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

@keyframes tubeDone {
    50% { transform: scale(1.06); }
}

@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: 32px; }
    .tool-btn { font-size: 12px; }
}

@media (max-height: 600px) {
    #start-screen h1 { font-size: 30px; margin-bottom: 6px; }
    .logo { display: none; }
    #start-screen .desc { margin-bottom: 12px; font-size: 15px; }
    .btn { padding: 10px 18px; font-size: 17px; margin: 5px auto; }
    .tool-btn { padding: 5px 4px; }
    .tool-btn .ico { font-size: 17px; }
}
