* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-a: #fff7cf;
    --bg-b: #d9f8ff;
    --ink: #0f2940;
    --ink-soft: #2c5b7f;
    --line: rgba(49, 122, 164, 0.24);
    --panel: rgba(255, 255, 255, 0.62);
    --panel-strong: rgba(255, 255, 255, 0.76);
    --accent-a: #ff8f3f;
    --accent-b: #11bfff;
    --accent-c: #2de4c6;
    --warn: #f39c5a;
    --modal-overlay: rgba(240, 251, 255, 0.84);
    --board-bg: rgba(255, 255, 255, 0.92);
    --board-inset-top: rgba(255, 255, 255, 0.95);
    --board-inset-bottom: rgba(70, 145, 182, 0.2);
    --cell-bg: rgba(255, 255, 255, 0.96);
    --cell-hover-bg: #f2fbff;
    --cell-selected-bg: rgba(139, 229, 255, 0.34);
    --cell-border: rgba(118, 173, 205, 0.42);
    --wall-color: #2f97cb;
    --number-circle-bg: rgba(16, 74, 106, 0.95);
    --number-circle-stroke: rgba(255, 255, 255, 0.95);
    --number-circle-selected-bg: #13afe8;
    --number-circle-selected-stroke: #e9fbff;
    --number-text-color: #f7feff;
}

body.theme-dark {
    --bg-a: #05142a;
    --bg-b: #0d1d3d;
    --ink: #e8f4ff;
    --ink-soft: #9ec5ea;
    --line: rgba(137, 187, 236, 0.26);
    --panel: rgba(9, 23, 47, 0.62);
    --panel-strong: rgba(12, 30, 58, 0.82);
    --accent-a: #ffb35f;
    --accent-b: #4ad6ff;
    --accent-c: #5ef5d4;
    --warn: #ffbf85;
    --modal-overlay: rgba(2, 10, 24, 0.74);
    --board-bg: rgba(6, 22, 44, 0.88);
    --board-inset-top: rgba(74, 130, 193, 0.18);
    --board-inset-bottom: rgba(7, 13, 25, 0.55);
    --cell-bg: rgba(7, 26, 52, 0.92);
    --cell-hover-bg: rgba(18, 53, 94, 0.92);
    --cell-selected-bg: rgba(57, 173, 236, 0.32);
    --cell-border: rgba(86, 145, 206, 0.36);
    --wall-color: rgba(121, 190, 245, 0.9);
    --number-circle-bg: rgba(10, 41, 78, 0.96);
    --number-circle-stroke: rgba(171, 219, 255, 0.85);
    --number-circle-selected-bg: rgba(52, 188, 255, 0.92);
    --number-circle-selected-stroke: rgba(232, 249, 255, 0.98);
    --number-text-color: #eef9ff;
}

body {
    font-family: "Sora", sans-serif;
    color: var(--ink);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 22px 10px;
    overflow-x: hidden;
    background: linear-gradient(135deg, var(--bg-a), var(--bg-b));
}

.ambient {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.ambient-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(30px);
    opacity: 0.72;
    mix-blend-mode: screen;
    animation: orbFloat 14s ease-in-out infinite;
}

.orb-a {
    width: 36vmax;
    height: 36vmax;
    background: radial-gradient(circle at 30% 30%, rgba(255, 146, 61, 0.65), rgba(255, 146, 61, 0));
    top: -12vmax;
    left: -8vmax;
}

.orb-b {
    width: 32vmax;
    height: 32vmax;
    background: radial-gradient(circle at 35% 35%, rgba(33, 188, 255, 0.7), rgba(33, 188, 255, 0));
    right: -10vmax;
    top: 12vmax;
    animation-delay: -4.5s;
}

.orb-c {
    width: 30vmax;
    height: 30vmax;
    background: radial-gradient(circle at 40% 30%, rgba(32, 229, 190, 0.62), rgba(32, 229, 190, 0));
    bottom: -12vmax;
    left: 40%;
    animation-delay: -8s;
}

.ambient-grid {
    position: absolute;
    inset: -40%;
    background-image: linear-gradient(var(--line) 1px, transparent 1px),
        linear-gradient(90deg, var(--line) 1px, transparent 1px);
    background-size: 36px 36px;
    transform: rotate(-12deg);
    opacity: 0.35;
    animation: gridDrift 18s linear infinite;
}

.particle-field {
    position: absolute;
    inset: 0;
}

.particle-field span {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.7);
    box-shadow: 0 0 12px rgba(29, 175, 255, 0.56);
    animation: particlePulse 5.4s ease-in-out infinite;
}

.particle-field span:nth-child(1) { top: 14%; left: 12%; animation-delay: -1.2s; }
.particle-field span:nth-child(2) { top: 28%; left: 84%; animation-delay: -2.3s; }
.particle-field span:nth-child(3) { top: 42%; left: 24%; animation-delay: -0.8s; }
.particle-field span:nth-child(4) { top: 62%; left: 76%; animation-delay: -4.4s; }
.particle-field span:nth-child(5) { top: 72%; left: 18%; animation-delay: -2.9s; }
.particle-field span:nth-child(6) { top: 82%; left: 57%; animation-delay: -3.8s; }
.particle-field span:nth-child(7) { top: 18%; left: 63%; animation-delay: -0.6s; }
.particle-field span:nth-child(8) { top: 34%; left: 47%; animation-delay: -3.1s; }
.particle-field span:nth-child(9) { top: 54%; left: 9%; animation-delay: -1.7s; }
.particle-field span:nth-child(10) { top: 64%; left: 38%; animation-delay: -2.1s; }
.particle-field span:nth-child(11) { top: 76%; left: 89%; animation-delay: -0.3s; }
.particle-field span:nth-child(12) { top: 9%; left: 39%; animation-delay: -4.9s; }

.game-container {
    position: relative;
    width: fit-content;
    display: grid;
    place-items: center;
    z-index: 1;
}

.panel {
    background: var(--panel);
    backdrop-filter: blur(14px) saturate(125%);
    border: 1px solid rgba(255, 255, 255, 0.65);
    box-shadow: 0 16px 35px rgba(11, 70, 114, 0.12);
    border-radius: 16px;
}

.brand {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 12px);
    display: grid;
    justify-items: center;
    gap: 4px;
    width: max-content;
    transform: translateX(-50%) translateY(0);
    transition: opacity 200ms ease, transform 220ms ease, max-height 220ms ease, margin 220ms ease;
    max-height: 180px;
    opacity: 1;
}

.brand img {
    width: 40px;
    height: 40px;
    filter: drop-shadow(0 5px 10px rgba(17, 92, 147, 0.25));
}

h1 {
    font-family: "Syne", sans-serif;
    font-size: clamp(1.6rem, 4vw, 2.3rem);
    letter-spacing: 0.08em;
    color: var(--ink);
}

.subtitle {
    font-size: 0.76rem;
    letter-spacing: 0.24em;
    text-transform: uppercase;
    color: var(--ink-soft);
}

.game-info {
    position: absolute;
    left: 50%;
    top: calc(100% + 12px);
    width: max-content;
    display: grid;
    gap: 6px;
    padding: 8px 10px;
    transform: translateX(-50%) translateY(0);
    transition: opacity 200ms ease, transform 220ms ease, max-height 220ms ease, margin 220ms ease, padding 220ms ease;
    max-height: 120px;
    opacity: 1;
}

.game-info .text {
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--panel-strong);
    min-height: 34px;
    min-width: 170px;
    padding: 0 12px;
    display: grid;
    place-items: center;
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

.hud-line {
    letter-spacing: 0.02em;
}

.hint-button {
    min-height: 34px;
    min-width: 170px;
    border-radius: 10px;
    border: 1px solid rgba(122, 190, 223, 0.55);
    background: rgba(255, 255, 255, 0.9);
    color: var(--ink);
    font-weight: 700;
    font-size: 0.84rem;
    display: grid;
    place-items: center;
}

.hint-button:hover:not(:disabled) {
    background: linear-gradient(135deg, rgba(255, 171, 111, 0.93), rgba(67, 204, 255, 0.92));
    color: #fff;
}

.hud-top-left {
    position: absolute;
    right: calc(100% + 12px);
    top: 10px;
    display: grid;
    gap: 3px;
    align-items: start;
    justify-items: end;
    color: var(--ink);
    transition: opacity 200ms ease, transform 220ms ease;
}

.hud-title {
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.1;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}

.hud-subtitle {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--ink-soft);
}

#timer {
    font-weight: 600;
}

.puzzle-area {
    position: relative;
    width: min-content;
    height: min-content;
    padding: 10px;
    border-radius: 20px;
    overflow: hidden;
}

.puzzle-grid {
    display: grid;
    gap: 0;
    position: relative;
    min-height: 280px;
    min-width: 280px;
    width: min-content;
    height: min-content;
    border-radius: 12px;
    overflow: hidden;
    background: var(--board-bg);
    box-shadow: inset 0 1px 0 var(--board-inset-top), inset 0 -1px 0 var(--board-inset-bottom);
    transition: filter 0.26s ease;
}

.puzzle-grid.board-reveal .cell {
    animation: cellIn 240ms ease both;
    animation-delay: calc(var(--i, 0) * 9ms);
}

.puzzle-grid.paused,
.path-svg.paused,
.numbers-svg.paused {
    filter: blur(8px) saturate(0.8);
}

.cell {
    border: 1px solid var(--cell-border);
    border-right: none;
    border-bottom: none;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    cursor: pointer;
    user-select: none;
    z-index: 2;
    background: var(--cell-bg);
    transition: background-color 90ms ease, transform 90ms ease;
}

.cell:hover {
    background: var(--cell-hover-bg);
}

.cell.selected {
    background: var(--cell-selected-bg);
    animation: cellPulse 180ms ease-out;
}

.cell.wall-below {
    border-bottom: 3px solid var(--wall-color) !important;
}

.cell.wall-right {
    border-right: 3px solid var(--wall-color) !important;
}

.cell.diagonal .diagonal-marker {
    width: 9px;
    height: 9px;
    background: transparent;
    border-right: 2px solid rgba(34, 170, 225, 0.9);
    border-top: 2px solid rgba(34, 170, 225, 0.9);
    transform: rotate(45deg);
    position: absolute;
    opacity: 0.8;
    pointer-events: none;
    z-index: 5;
    box-shadow: 0 0 10px rgba(34, 170, 225, 0.45);
}

.cell.diagonal.selected .diagonal-marker {
    border-color: #0d95d4;
    opacity: 1;
}

.path-svg,
.numbers-svg {
    position: absolute;
    top: 10px;
    left: 10px;
    width: calc(100% - 20px);
    height: calc(100% - 20px);
    pointer-events: none;
    overflow: visible;
    transition: filter 0.3s ease;
}

.path-svg {
    z-index: 3;
}

.numbers-svg {
    z-index: 4;
}

#gamePath {
    fill: none;
    stroke: url(#pathGradient);
    stroke-width: 35;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0 0 12px rgba(30, 178, 255, 0.32));
    animation: pathGlow 2.6s ease-in-out infinite;
}

#tempPathSegment {
    fill: none;
    stroke-linecap: round;
    visibility: hidden;
}

.click-animation-segment {
    fill: none;
    stroke-linecap: round;
    transition: stroke-dashoffset 100ms ease-out;
}

.numbers-svg .number-circle-bg {
    fill: var(--number-circle-bg);
    stroke: var(--number-circle-stroke);
    stroke-width: 1.4px;
}

.numbers-svg .number-circle-bg.selected {
    fill: var(--number-circle-selected-bg);
    stroke: var(--number-circle-selected-stroke);
}

.numbers-svg .number-text {
    fill: var(--number-text-color);
    font-family: "Sora", sans-serif;
    font-weight: 600;
    text-anchor: middle;
    dominant-baseline: middle;
    user-select: none;
}

body.board-focus-mode .brand,
body.board-focus-mode .game-info {
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
    max-height: 0;
    margin: 0;
    padding-top: 0;
    padding-bottom: 0;
    overflow: hidden;
    pointer-events: none;
}

body.board-focus-mode .hud-top-left,
body.board-focus-mode .settings-fab {
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
}

button {
    min-height: 42px;
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.82);
    color: var(--ink);
    font-family: "Sora", sans-serif;
    font-weight: 500;
    font-size: 0.84rem;
    cursor: pointer;
    transition: transform 120ms ease, background-color 140ms ease, color 140ms ease, border-color 140ms ease;
}

button:hover:not(:disabled) {
    background: linear-gradient(135deg, rgba(255, 160, 95, 0.9), rgba(48, 196, 255, 0.9));
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.7);
}

button:active:not(:disabled) {
    transform: scale(0.965);
}

button:disabled {
    cursor: not-allowed;
    background: rgba(230, 240, 246, 0.8);
    color: rgba(60, 103, 131, 0.55);
    border-color: rgba(154, 188, 206, 0.5);
}

button:focus {
    outline: 2px solid rgba(31, 174, 241, 0.46);
    outline-offset: 2px;
}

.settings-fab {
    position: absolute;
    left: calc(100% + 12px);
    top: 10px;
    width: 36px;
    height: 36px;
    min-height: 36px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid rgba(171, 223, 246, 0.8);
    background: rgba(23, 103, 146, 0.74);
    color: #ecfbff;
    font-weight: 700;
    font-size: 0.7rem;
    z-index: 6;
    backdrop-filter: blur(6px);
    box-shadow: 0 8px 14px rgba(14, 72, 106, 0.28);
    display: grid;
    place-items: center;
    line-height: 0;
    transition: opacity 200ms ease, transform 220ms ease, background-color 140ms ease, border-color 140ms ease;
}

.settings-fab:hover:not(:disabled) {
    background: rgba(30, 129, 180, 0.85);
}

.settings-fab svg {
    width: 18px;
    height: 18px;
    position: absolute;
    inset: 0;
    margin: auto;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    pointer-events: none;
}

body.theme-dark .settings-fab {
    background: rgba(13, 45, 79, 0.86);
    border-color: rgba(118, 172, 229, 0.7);
    color: #e9f5ff;
}

.next-level-button {
    display: none;
}

.generating-text {
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    font-size: 1rem;
    color: #2d78a0;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    background: rgba(255, 255, 255, 0.88);
}

.pause-overlay {
    display: flex;
    position: absolute;
    inset: 10px;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    text-align: center;
    z-index: 15;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.pause-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.pause-overlay-button {
    width: 68px;
    height: 68px;
    min-height: 68px;
    border-radius: 999px;
    border: 1px solid rgba(190, 234, 252, 0.85);
    background: rgba(24, 96, 135, 0.78);
    color: #f2fbff;
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    display: grid;
    place-items: center;
    box-shadow: 0 10px 22px rgba(14, 72, 106, 0.34), 0 0 0 6px rgba(255, 255, 255, 0.14);
}

.pause-overlay-button:hover:not(:disabled) {
    background: rgba(30, 119, 167, 0.88);
    border-color: rgba(223, 246, 255, 0.95);
    color: #ffffff;
    transform: scale(1.03);
}

.pause-overlay-button:active:not(:disabled) {
    transform: scale(0.96);
}

.message-box {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.92);
    color: #1a5478;
    font-size: 0.82rem;
    border: 1px solid rgba(125, 181, 211, 0.68);
    border-left: 4px solid #1cb6f1;
    border-radius: 8px;
    padding: 8px 10px;
    box-shadow: 0 12px 26px rgba(20, 101, 146, 0.14);
    opacity: 0;
    transform: translateX(10px);
    transition: opacity 0.32s ease, transform 0.32s ease, margin-bottom 0.3s ease;
    position: relative;
    z-index: 1000;
    margin-bottom: 8px;
    max-width: 300px;
}

.message-box.show {
    opacity: 1;
    transform: translateX(0);
}

.message-box.hide {
    opacity: 0;
    transform: translateX(10px);
    margin-bottom: -40px;
    pointer-events: none;
}

.message-box span {
    flex-grow: 1;
    margin-right: 8px;
}

.message-box .close-button {
    background: none;
    border: none;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    color: rgba(32, 112, 156, 0.5);
    padding: 0 3px;
    line-height: 1;
    min-height: 0;
}

.message-box .close-button:hover {
    color: rgba(15, 77, 112, 0.95);
}

#messageContainer {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    max-width: 320px;
}

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--modal-overlay);
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
    padding: 10px;
}

.modal-overlay.show {
    display: flex;
    opacity: 1;
}

.modal {
    background: var(--panel-strong);
    border: 1px solid var(--line);
    padding: 22px 24px;
    border-radius: 12px;
    box-shadow: 0 16px 32px rgba(20, 86, 127, 0.16);
    text-align: center;
    max-width: 400px;
    width: 95%;
    transform: scale(0.92);
    transition: transform 0.24s ease;
}

.modal-overlay.show .modal {
    transform: scale(1);
}

.modal h2 {
    margin-bottom: 12px;
    font-size: 1.25rem;
    font-family: "Syne", sans-serif;
}

.modal-message {
    margin-bottom: 18px;
    font-size: 0.94rem;
    line-height: 1.5;
    color: var(--ink-soft);
}

.modal-buttons {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.modal-button {
    min-width: 86px;
}

.modal-button-confirm {
    border-color: rgba(29, 176, 241, 0.55);
    color: #1a9fd7;
}

.modal-button-confirm:hover:not(:disabled) {
    color: #ffffff;
}

.settings-modal {
    text-align: left;
}

.settings-modal h2 {
    margin-bottom: 16px;
}

.settings-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: center;
    margin-bottom: 12px;
}

.settings-row label {
    color: var(--ink);
    font-size: 0.9rem;
    font-weight: 600;
}

.settings-inline {
    display: flex;
    align-items: center;
    gap: 10px;
}

#settingsVolume {
    width: 170px;
    accent-color: #1bb6ef;
}

#settingsVolumeValue {
    min-width: 46px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: var(--ink-soft);
}

#settingsDifficultySelect {
    min-width: 170px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--panel-strong);
    color: var(--ink);
    padding: 6px 8px;
    font-family: "Sora", sans-serif;
}

.settings-row input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: #1bb6ef;
}

@keyframes orbFloat {
    0% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(2.4vmax, -1.6vmax) scale(1.06); }
    100% { transform: translate(0, 0) scale(1); }
}

@keyframes particlePulse {
    0%, 100% { transform: scale(0.7); opacity: 0.32; }
    50% { transform: scale(1.3); opacity: 0.9; }
}

@keyframes gridDrift {
    from { transform: rotate(-12deg) translateX(0); }
    to { transform: rotate(-12deg) translateX(36px); }
}

@keyframes cellIn {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes cellPulse {
    0% { transform: scale(0.94); }
    100% { transform: scale(1); }
}

@keyframes pathGlow {
    0%, 100% { filter: drop-shadow(0 0 8px rgba(30, 178, 255, 0.2)); }
    50% { filter: drop-shadow(0 0 14px rgba(255, 145, 69, 0.32)); }
}

@media (max-width: 860px) {
    .game-info {
        width: max-content;
    }

    .hud-top-left {
        right: calc(100% + 10px);
    }

    .settings-fab {
        left: calc(100% + 10px);
    }
}

@media (max-width: 540px) {
    body {
        padding: 8px;
    }

    .game-info {
        width: calc(100vw - 22px);
        max-width: 330px;
    }

    .game-info .text,
    button {
        min-height: 38px;
        font-size: 0.78rem;
    }

    .hud-top-left {
        right: auto;
        left: 0;
        top: -52px;
        justify-items: start;
    }

    .puzzle-area {
        padding: 8px;
    }

    .settings-fab {
        left: auto;
        right: 0;
        top: -52px;
    }

    .path-svg,
    .numbers-svg,
    .pause-overlay {
        inset: 8px;
        width: calc(100% - 16px);
        height: calc(100% - 16px);
    }

    #messageContainer {
        top: 8px;
        right: 8px;
        max-width: 240px;
    }
}
