:root {
    --violet: #7b8cff;
    --violet-dark: #5f6fd9;
    --pink: #ff7aab;
    --teal: #4fd4c4;
    --ink: #e8edf5;
    --muted: #9aa8bc;
    --card: rgba(36, 46, 64, 0.92);
    --card-solid: #283348;
    --surface: #334058;
    --bg-deep: #141b28;
    --bg-mid: #1c2638;
    --bg-soft: #243044;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
    font-family: -apple-system, "Helvetica Neue", Arial, sans-serif;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    background:
        radial-gradient(circle at 18% 12%, rgba(90, 120, 180, 0.22), transparent 42%),
        radial-gradient(circle at 88% 22%, rgba(70, 100, 150, 0.16), transparent 45%),
        radial-gradient(circle at 50% 92%, rgba(50, 90, 120, 0.2), transparent 50%),
        linear-gradient(165deg, var(--bg-deep) 0%, var(--bg-mid) 48%, var(--bg-soft) 100%);
    color: var(--ink);
}

#app {
    position: relative;
    width: 100%;
    height: 100%;
}

.screen {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: env(safe-area-inset-top) 18px env(safe-area-inset-bottom);
}
.screen.active { display: flex; }

.screen.overlay {
    background: rgba(8, 12, 20, 0.62);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 20;
}

.menu-card, .dialog, .panel {
    width: 100%;
    max-width: 420px;
    background: var(--card);
    border: 1px solid rgba(150, 175, 210, 0.14);
    border-radius: 26px;
    padding: 28px 24px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.4);
    text-align: center;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: var(--ink);
}
.panel {
    max-height: 88%;
    overflow-y: auto;
    text-align: left;
}

.title {
    font-size: 34px;
    font-weight: 800;
    background: linear-gradient(90deg, var(--violet), var(--teal));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 0.5px;
}
.subtitle {
    margin: 6px 0 24px;
    color: var(--muted);
    font-size: 15px;
}
h2 { font-size: 24px; margin-bottom: 18px; text-align: center; color: var(--ink); }
h3 { font-size: 16px; margin: 16px 0 4px; color: var(--violet); }
p  { font-size: 14px; line-height: 1.5; color: var(--muted); }

.menu-buttons { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }

.btn {
    border: none;
    border-radius: 16px;
    padding: 14px 18px;
    font-size: 16px;
    font-weight: 600;
    color: var(--ink);
    background: var(--surface);
    cursor: pointer;
    transition: transform 0.08s ease, box-shadow 0.15s ease, filter 0.15s ease;
}
.btn:active { transform: scale(0.96); filter: brightness(1.08); }
.btn-primary {
    color: #fff;
    background: linear-gradient(90deg, var(--violet), var(--violet-dark));
    box-shadow: 0 8px 20px rgba(90, 110, 220, 0.4);
}
.btn-danger { color: #fff; background: linear-gradient(90deg, #e86b8c, #d44a5e); }
.btn-small { padding: 10px 16px; font-size: 14px; }

.logo-blob {
    position: relative;
    width: 96px;
    height: 96px;
    margin: 0 auto 6px;
}
.blob {
    position: absolute;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    filter: blur(0.5px);
    animation: bob 2.6s ease-in-out infinite;
}
.blob.b1 { background: var(--violet); left: 4px;  top: 22px; animation-delay: 0s; }
.blob.b2 { background: var(--pink);   left: 26px; top: 2px;  animation-delay: 0.3s; }
.blob.b3 { background: var(--teal);   left: 46px; top: 30px; animation-delay: 0.6s; }
@keyframes bob {
    0%, 100% { transform: translateY(0) scale(1); }
    50%      { transform: translateY(-8px) scale(1.08); }
}

.hud-top {
    position: absolute;
    top: calc(env(safe-area-inset-top) + 8px);
    left: 12px;
    right: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 5;
}
.icon-btn {
    width: 42px; height: 42px;
    border-radius: 12px;
    background: var(--card);
    border: 1px solid rgba(150, 175, 210, 0.16);
    color: var(--ink);
    font-weight: 800; font-size: 15px;
    letter-spacing: 1px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.28);
}
.progress-wrap { flex: 1; }
.progress-label { font-size: 12px; font-weight: 700; margin-bottom: 3px; color: var(--ink); text-shadow: 0 1px 3px rgba(0,0,0,0.45); }
.progress-bar {
    height: 10px; border-radius: 6px;
    background: rgba(20, 28, 42, 0.75);
    overflow: hidden;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.35);
    border: 1px solid rgba(150, 175, 210, 0.12);
}
.progress-fill {
    height: 100%; width: 0%;
    background: linear-gradient(90deg, var(--teal), var(--violet));
    border-radius: 6px;
    transition: width 0.25s ease;
}
.secrets-count {
    background: var(--card);
    border: 1px solid rgba(150, 175, 210, 0.16);
    padding: 8px 12px;
    border-radius: 12px;
    font-weight: 800;
    font-size: 14px;
    color: #ffd76a;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.28);
}

#game-screen { padding: 0; justify-content: flex-start; }
.canvas-holder {
    position: relative;
    width: 100%;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding-top: calc(env(safe-area-inset-top) + 56px);
    background: #1a2333;
    overflow: hidden;
}
#game-canvas {
    background: #1a2333;
    touch-action: none;
}
.hint-toast {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%) translateY(-10px);
    background: rgba(20, 28, 42, 0.94);
    color: #f0f4fa;
    border: 1px solid rgba(150, 175, 210, 0.2);
    padding: 10px 16px;
    border-radius: 14px;
    font-size: 13px;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    text-align: center;
    max-width: 80%;
}
.hint-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.touch-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 12px 20px calc(env(safe-area-inset-bottom) + 14px);
    gap: 12px;
    background: rgba(16, 22, 34, 0.55);
}
.dpad {
    position: relative;
    width: 150px;
    height: 110px;
}
.dbtn {
    position: absolute;
    width: 48px; height: 48px;
    border: 1px solid rgba(150, 175, 210, 0.18);
    border-radius: 14px;
    background: var(--card-solid);
    color: var(--ink);
    font-size: 18px; font-weight: 700;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    cursor: pointer;
}
.dbtn:active { transform: scale(0.92); }
.dbtn.up    { left: 51px; top: 0; }
.dbtn.left  { left: 0;    top: 56px; }
.dbtn.right { left: 102px;top: 56px; }
.dbtn.down  { left: 51px; top: 56px; }

.levels-list { display: flex; flex-direction: column; gap: 12px; margin: 6px 0 18px; }
.level-item {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--surface);
    border: 1px solid rgba(150, 175, 210, 0.12);
    border-radius: 16px;
    padding: 14px 16px;
    cursor: pointer;
    transition: transform 0.08s ease;
}
.level-item:active { transform: scale(0.98); }
.level-item.locked { opacity: 0.5; cursor: not-allowed; }
.level-badge {
    width: 42px; height: 42px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; color: #fff;
    background: linear-gradient(135deg, var(--violet), var(--teal));
    flex-shrink: 0;
}
.level-info { flex: 1; }
.level-name { font-weight: 700; font-size: 15px; color: var(--ink); }
.level-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.level-status { font-size: 12px; font-weight: 700; }
.level-status.done { color: var(--teal); }
.level-status.progress { color: var(--violet); }
.level-status.locked { color: #6d7a90; }

.results-grid { margin: 8px 0 20px; }
.res-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 4px;
    border-bottom: 1px solid rgba(150, 175, 210, 0.12);
    font-size: 15px;
    color: var(--muted);
}
.res-row b { font-size: 17px; color: var(--ink); }

.rules-body { margin-bottom: 18px; }
.rules-body p { margin-bottom: 6px; }

.settings-body { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.switch-row {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--surface);
    border: 1px solid rgba(150, 175, 210, 0.12);
    border-radius: 16px; padding: 14px 16px;
    font-size: 16px; font-weight: 600; cursor: pointer;
    color: var(--ink);
}
.switch-row input { display: none; }
.switch {
    position: relative;
    width: 50px; height: 28px;
    background: #4a5568; border-radius: 20px;
    transition: background 0.2s ease;
    flex-shrink: 0;
}
.switch::after {
    content: "";
    position: absolute; top: 3px; left: 3px;
    width: 22px; height: 22px;
    background: #f0f4fa; border-radius: 50%;
    transition: transform 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.35);
}
.switch-row input:checked + .switch { background: var(--violet); }
.switch-row input:checked + .switch::after { transform: translateX(22px); }
