* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
    background: linear-gradient(180deg, #1e1b4b 0%, #312e81 50%, #0f172a 100%);
    min-height: 100vh;
    min-height: 100dvh;
    color: #e0e7ff;
    padding: 12px;
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}
.wrap { max-width: 520px; margin: 0 auto; }
.head { text-align: center; margin-bottom: 12px; }
.head h1 { font-size: 1.6rem; margin-bottom: 10px; text-shadow: 0 2px 4px rgba(0,0,0,0.4); }
.stats {
    display: flex;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
}
.stat {
    background: rgba(0,0,0,0.3);
    padding: 8px 14px;
    border-radius: 8px;
    min-width: 5.5rem;
}
.stat .lbl { opacity: 0.88; margin-right: 8px; font-size: 0.9rem; }
.stat span:last-child {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
}
.canvas-wrap {
    display: flex;
    justify-content: center;
    margin: 12px 0;
}
#game {
    display: block;
    max-width: 100%;
    height: auto;
    background: #0f172a;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.45);
    border: 3px solid rgba(255,255,255,0.15);
    touch-action: none;
    cursor: crosshair;
    outline: none;
}
#game:focus-visible {
    box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.65), 0 8px 32px rgba(0,0,0,0.45);
}
.toolbar {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 8px;
}
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    background: rgba(255,255,255,0.16);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
}
.btn:hover:not(:disabled) { background: rgba(255,255,255,0.26); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
.btn:focus-visible {
    outline: 2px solid #a5b4fc;
    outline-offset: 2px;
}
.hint {
    text-align: center;
    font-size: 0.84rem;
    opacity: 0.9;
    margin-top: 12px;
    line-height: 1.55;
}
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.58);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.overlay.hidden { display: none; }
.overlay-inner {
    background: #1e1b4b;
    padding: 24px 28px;
    border-radius: 16px;
    text-align: center;
    max-width: 90%;
    border: 2px solid rgba(255,255,255,0.18);
    box-shadow: 0 16px 48px rgba(0,0,0,0.45);
}
.overlay-inner p { margin-bottom: 16px; font-size: 1.1rem; }
.overlay .btn.primary {
    background: #a5b4fc;
    color: #1e1b4b;
}
