:root {
    --bg: #0c0912;
    --panel: #171226;
    --line: rgba(255, 255, 255, 0.10);
    --text: #eef0f6;
    --muted: #9a94ad;
    --pink: #ff0048;
    --purple: #8b00ff;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background:
        radial-gradient(900px 500px at 50% -10%, rgba(139, 0, 255, 0.22), transparent 70%),
        var(--bg);
}

.topbar {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 14px 20px;
}

.brand {
    color: var(--muted);
    text-decoration: none;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.08em;
    white-space: nowrap;
}

.brand:hover { color: var(--text); }

.title {
    margin: 0;
    flex: 1;
    font-size: clamp(16px, 3vw, 26px);
    font-weight: 900;
    letter-spacing: 0.01em;
    background: linear-gradient(90deg, #ff0048, #ff6aa2 45%, #8b00ff);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.controls { display: flex; gap: 8px; }

.btn {
    font: inherit;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.06em;
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 10px 18px;
    cursor: pointer;
    transition: transform 0.12s ease, background 0.12s ease, opacity 0.12s ease;
}

.btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.12); transform: translateY(-1px); }
.btn:disabled { opacity: 0.35; cursor: default; }

.btn.primary {
    border: 0;
    background: linear-gradient(90deg, var(--pink), var(--purple));
    color: #fff;
    box-shadow: 0 10px 26px rgba(255, 0, 72, 0.28);
}

.btn.primary:hover:not(:disabled) { box-shadow: 0 12px 30px rgba(255, 0, 72, 0.42); }

.tagline {
    margin: 10px 20px 8px;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
}

.stage-wrap {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0 12px;
}

#stage {
    /* Portrait 9:16. Sized by max constraints so the page (header, board, tray)
       always fits one screen; a short viewport narrows the board, not clips it. */
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 9 / 16;
    display: block;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: #14101f;
    box-shadow: 0 30px 70px rgba(0, 0, 0, 0.55);
    touch-action: none;
    cursor: grab;
}

#stage:active { cursor: grabbing; }

.tray {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    padding: 14px 16px 20px;
}

.part {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px 6px 6px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--text);
    font: inherit;
    cursor: grab;
    user-select: none;
    transition: transform 0.12s ease, border-color 0.12s ease;
}

.part:hover { transform: translateY(-2px); border-color: rgba(255, 0, 72, 0.55); }

.part-icon { width: 42px; height: 42px; display: block; }
.part-name { font-size: 13px; font-weight: 700; }

.score {
    display: flex;
    align-items: center;
    padding: 0 12px;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.04em;
    color: #ffd7e3;
    white-space: nowrap;
}

.ghost {
    position: fixed;
    left: 0;
    top: 0;
    width: 60px;
    height: 60px;
    margin: -30px 0 0 -30px;
    pointer-events: none;
    z-index: 50;
    opacity: 0.85;
    filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.6));
}

.ghost canvas { width: 60px; height: 60px; }

@media (max-width: 640px) {
    .topbar { flex-wrap: wrap; padding: 10px 12px; gap: 8px; }
    .title { flex-basis: 100%; order: 0; white-space: normal; font-size: 18px; }
    .controls {
        width: 100%;
        order: 1;
        flex-wrap: wrap;
        gap: 6px;
    }
    .controls .btn {
        flex: 1 1 auto;
        padding: 8px 10px;
        font-size: 12px;
    }
    .score { font-size: 12px; }
    .stage-wrap { padding: 0 8px; }
    #stage { max-width: calc(100vw - 16px); border-radius: 12px; }
    .part-name { display: none; }
    .part { padding: 4px 8px 4px 4px; }
}


@media (max-width: 640px) {
    body {
        height: 100dvh;
        min-height: 0;
        overflow: hidden;
    }
    .brand { display: none; }
    .tagline { display: none; }
    .stage-wrap { min-height: 0; padding: 4px 8px 6px; }
    .tray {
        flex: 0 0 auto;
        justify-content: flex-start;
        position: static;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 20;
        padding: 5px 6px;
        border-radius: 14px 14px 0 0;
        background: #14101f;
        overflow-x: auto;
        flex-wrap: nowrap;
    }
}
