*{box-sizing:border-box}
html,body{margin:0;min-height:100%;font-family:Arial,Helvetica,sans-serif;background:#e0f2fe;color:#0f172a;overflow-x:hidden}
#splash{
    position:fixed;
    inset:0;
    z-index:999999;
    background:rgba(0,0,0,.72);
    cursor:pointer;
    display:flex;
    align-items:center;
    justify-content:center;
}
#splash::before{
    content:"";
    width:min(760px,86vw);
    height:min(520px,70vh);
    background:#000 url("splash.jpg") center center/contain no-repeat;
    border-radius:24px;
    box-shadow:0 18px 55px rgba(0,0,0,.65);
    border:4px solid white;
}
header{text-align:center;padding:10px;background:linear-gradient(180deg,#2563eb,#38bdf8);color:white;box-shadow:0 4px 12px rgba(0,0,0,.2)}
h1{margin:0;font-size:clamp(26px,5vw,54px);text-shadow:0 2px 4px rgba(0,0,0,.35)}
#status{margin-top:5px;font-size:clamp(16px,3vw,24px);font-weight:900}
#letterPanel{padding:8px;background:#fefce8;border-bottom:3px solid #facc15}
#letters{display:flex;flex-wrap:wrap;justify-content:center;gap:6px;max-height:170px;overflow-y:auto}
.letterBtn{min-width:48px;min-height:48px;border:3px solid #2563eb;border-radius:14px;background:white;color:#1d4ed8;font-size:25px;font-weight:900;cursor:pointer;box-shadow:0 4px 0 #1d4ed8}
.letterBtn.mastered{background:#22c55e;color:white;border-color:#15803d;box-shadow:0 4px 0 #166534}
.letterBtn.active{background:#f97316;color:white;border-color:#c2410c;box-shadow:0 4px 0 #9a3412}
#stageWrap{position:relative;width:min(50vw,450px);height:min(62vh,580px);min-height:360px;margin:12px auto;background:white;border:6px solid #2563eb;border-radius:24px;overflow:hidden;box-shadow:0 10px 25px rgba(0,0,0,.18);touch-action:none}
#traceCanvas{width:100%;height:100%;display:block;touch-action:none}
#warning{position:absolute;left:50%;top:18px;transform:translateX(-50%);background:#dc2626;color:white;font-size:clamp(22px,5vw,46px);font-weight:900;padding:12px 22px;border-radius:18px;display:none;animation:flash .25s alternate infinite;pointer-events:none;box-shadow:0 8px 18px rgba(0,0,0,.25)}
@keyframes flash{from{opacity:.35;transform:translateX(-50%) scale(.95)}to{opacity:1;transform:translateX(-50%) scale(1.05)}}
#controls{display:flex;justify-content:center;gap:10px;flex-wrap:wrap;padding:8px 8px 18px}
button{border:0;border-radius:16px;padding:14px 20px;background:#facc15;color:#111827;font-size:18px;font-weight:900;cursor:pointer;box-shadow:0 5px 0 #ca8a04}
button:active{transform:translateY(4px);box-shadow:0 1px 0 #ca8a04}
@media(max-width:650px){#letters{max-height:128px}.letterBtn{min-width:40px;min-height:40px;font-size:21px;border-radius:11px}#stageWrap{height:56vh;min-height:320px}}


.hidden {
    display: none !important;
}

#messagePopup {
    position: fixed;
    inset: 0;
    z-index: 999998;
    background: rgba(0,0,0,.55);
    display: flex;
    align-items: center;
    justify-content: center;
}

#messageBox {
    width: min(420px, 90vw);
    background: white;
    color: #111827;
    border: 5px solid #2563eb;
    border-radius: 24px;
    padding: 24px;
    text-align: center;
    box-shadow: 0 18px 55px rgba(0,0,0,.45);
}

#messageText {
    font-size: clamp(22px, 5vw, 34px);
    font-weight: 900;
    margin-bottom: 18px;
}


@media(max-width:800px){
    #stageWrap{
        width:min(92vw,450px);
    }
}
