:root {
    --cream: #fffdf7;
    --paper: #ffffff;
    --panel: #cfd5ee;
    --panel-dark: #bfc7e6;
    --ink: #111233;
    --muted: #65708a;
    --blue: #78aef2;
    --red: #fb575f;
    --gold: #ffd867;
    --zoom: 1;
}

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

body {
    min-height: 100vh;
    background:
        radial-gradient(circle at 50% 0%, rgba(120, 174, 242, 0.14), transparent 30rem),
        var(--cream);
    color: var(--ink);
    font-family: Georgia, "Times New Roman", serif;
}

main {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    padding: 24px 16px 48px;
}

.game-header {
    text-align: center;
    max-width: 720px;
}

.game-header h1 {
    color: #1a2448;
    font-size: clamp(2.2rem, 7vw, 4rem);
    line-height: 1;
    letter-spacing: 0;
    margin-bottom: 8px;
}

.game-header p {
    color: #5e6477;
    font-size: clamp(1.04rem, 3vw, 1.25rem);
    line-height: 1.35;
}

.game-card {
    width: min(960px, calc(100vw - 24px));
    min-height: clamp(500px, 64vh, 560px);
    background: var(--paper);
    border: 1px solid #eee9dc;
    border-radius: 28px;
    box-shadow: 0 16px 44px rgba(29, 25, 12, 0.10);
    overflow: hidden;
    display: grid;
    grid-template-rows: 78px 1fr 52px;
}

.game-topbar,
.game-bottombar {
    background: var(--panel);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.game-topbar {
    border-bottom: 3px solid #e8e5dc;
}

.game-bottombar {
    border-top: 1px solid var(--panel-dark);
}

.level-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    font-family: Arial, Helvetica, sans-serif;
    font-weight: 800;
}

#level-stat {
    color: #78aef2;
    font-size: 1rem;
}

#heart-stat {
    color: var(--red);
    font-size: 1.05rem;
    letter-spacing: 1px;
    line-height: 1;
}

.round-control,
.hint-orb,
.text-control {
    font-family: Arial, Helvetica, sans-serif;
    font-weight: 800;
    cursor: pointer;
    border: none;
    -webkit-tap-highlight-color: transparent;
}

.round-control {
    min-width: 42px;
    height: 42px;
    border-radius: 999px;
    color: #fff;
    background: var(--blue);
    border: 3px solid #fff;
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12);
    font-size: 0;
    position: absolute;
    top: 18px;
    text-decoration: none;
}

.home-link {
    left: 22px;
}

#restart-btn {
    left: calc(50% - 118px);
}

#new-btn {
    right: calc(50% - 118px);
}

.home-link::before,
#restart-btn::before,
#new-btn::before {
    font-size: 1.18rem;
    line-height: 1;
}

.home-link::before { content: "\2190"; }
#restart-btn::before { content: "\2699"; }
#new-btn::before { content: "\21bb"; }

.playfield {
    position: relative;
    min-height: 400px;
    background:
        linear-gradient(180deg, rgba(255,255,255,0.96), rgba(252,252,252,0.98)),
        #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.arrow-board {
    width: min(420px, calc(100vw - 68px));
    aspect-ratio: 1 / 1;
    position: relative;
    touch-action: manipulation;
    transform: scale(var(--zoom));
    transform-origin: center;
    transition: transform 0.18s ease;
}

.puzzle-svg {
    width: 100%;
    height: 100%;
    display: block;
    overflow: visible;
}

.arrow-tile {
    cursor: pointer;
    outline: none;
}

.arrow-hit {
    fill: none;
    stroke: transparent;
    stroke-width: 22;
    stroke-linecap: square;
    stroke-linejoin: miter;
}

.arrow-outer {
    fill: none;
    stroke: var(--ink);
    stroke-width: 5.2;
    stroke-linecap: square;
    stroke-linejoin: miter;
    filter: drop-shadow(0 1px 0 rgba(17, 18, 51, 0.10));
}

.arrow-inner {
    fill: none;
    stroke: #fff;
    stroke-width: 2.3;
    stroke-linecap: square;
    stroke-linejoin: miter;
}

.arrow-marker-stem {
    stroke: var(--marker-color, var(--ink));
    stroke-width: 2.4;
    stroke-linecap: square;
    pointer-events: none;
}

.arrow-marker-head {
    fill: var(--marker-color, var(--ink));
    pointer-events: none;
}

.dot-grid {
    fill: url(#dotGrid);
    opacity: 0.75;
    pointer-events: none;
}

.arrow-tile:hover,
.arrow-tile:focus-visible {
    --marker-color: #27337a;
}

.arrow-tile.hint .arrow-outer {
    animation: hintPulse 0.95s ease-in-out 2;
    stroke: #225f99;
}

.arrow-tile.hint .arrow-marker-stem {
    stroke: #225f99;
}

.arrow-tile.hint .arrow-marker-head {
    fill: #225f99;
}

.arrow-tile.ready {
    --marker-color: var(--red);
}

.arrow-tile.blocked {
    animation: gentleWiggle 0.32s ease-in-out;
}

.arrow-tile.exiting-up { animation: exitUp 0.36s ease-in forwards; }
.arrow-tile.exiting-down { animation: exitDown 0.36s ease-in forwards; }
.arrow-tile.exiting-left { animation: exitLeft 0.36s ease-in forwards; }
.arrow-tile.exiting-right { animation: exitRight 0.36s ease-in forwards; }

.tap-prompt {
    position: absolute;
    left: 50%;
    bottom: clamp(16px, 4vh, 34px);
    transform: translateX(-50%);
    min-width: 190px;
    padding: 8px 24px;
    border-radius: 12px;
    color: #34364f;
    background: #fff;
    border: 1px solid #d8d8d8;
    box-shadow:
        0 2px 0 rgba(0, 0, 0, 0.15),
        0 16px 28px rgba(255, 255, 255, 0.88);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 0.92rem;
    font-weight: 800;
    text-align: center;
}

.hint-orb {
    position: absolute;
    left: 50%;
    top: -17px;
    transform: translateX(-50%);
    width: 38px;
    height: 38px;
    border-radius: 999px;
    color: #23324e;
    background: var(--blue);
    border: 3px solid #fff;
    box-shadow: 0 2px 0 rgba(0,0,0,0.16);
    font-size: 0;
}

.hint-orb::before {
    content: "\1f4a1";
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    font-size: 1.12rem;
}

.zoom-control {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 170px;
    height: 100%;
    font-family: Arial, Helvetica, sans-serif;
}

.zoom-step {
    width: 18px;
    height: 18px;
    border: 1px solid #858ca8;
    border-radius: 50%;
    background: #d8ddef;
    color: #66708b;
    font-size: 0.9rem;
    font-weight: 800;
    line-height: 1;
    cursor: pointer;
}

#zoom-slider {
    width: 112px;
    accent-color: #f6f7ff;
    cursor: pointer;
}

.text-control {
    position: absolute;
    right: 18px;
    color: #39415f;
    background: transparent;
    font-size: 0.92rem;
    padding: 10px 12px;
}

#remaining-stat {
    position: absolute;
    left: 18px;
    color: #4e5874;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 0.86rem;
    font-weight: 800;
}

.status-row {
    min-height: 1.6rem;
    text-align: center;
    color: var(--muted);
    font-size: 1rem;
}

.win-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.48);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.win-overlay[hidden] {
    display: none;
}

.win-box {
    width: min(420px, calc(100vw - 32px));
    background: #fff;
    border: 4px solid var(--panel);
    border-radius: 22px;
    padding: 34px 28px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,0.30);
}

.win-box h2 {
    color: #1a2448;
    font-size: 2rem;
    line-height: 1.1;
    margin-bottom: 10px;
}

.win-box p {
    color: var(--muted);
    font-size: 1.1rem;
    margin-bottom: 22px;
}

.win-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

.modal-btn {
    min-height: 46px;
    font-family: Arial, Helvetica, sans-serif;
    font-weight: 800;
    font-size: 1rem;
    padding: 10px 20px;
    border: none;
    border-radius: 12px;
    background: var(--blue);
    color: #fff;
    cursor: pointer;
}

.modal-btn.secondary {
    background: #3e496a;
}

.round-control:focus-visible,
.hint-orb:focus-visible,
.text-control:focus-visible,
.modal-btn:focus-visible,
.arrow-tile:focus-visible {
    outline: 3px solid var(--gold);
    outline-offset: 4px;
}

.round-control:disabled,
.hint-orb:disabled,
.text-control:disabled {
    opacity: 0.55;
    cursor: default;
}

@keyframes gentleWiggle {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-7px); }
    75% { transform: translateX(7px); }
}

@keyframes hintPulse {
    0%, 100% { stroke-width: 5.2; }
    50% { stroke-width: 7.4; }
}

@keyframes exitUp {
    to { transform: translateY(-380px); opacity: 0; }
}

@keyframes exitDown {
    to { transform: translateY(380px); opacity: 0; }
}

@keyframes exitLeft {
    to { transform: translateX(-380px); opacity: 0; }
}

@keyframes exitRight {
    to { transform: translateX(380px); opacity: 0; }
}

@media (max-width: 640px) {
    main {
        padding: 16px 8px 32px;
        gap: 14px;
    }

    .game-card {
        width: calc(100vw - 12px);
        min-height: 560px;
        border-radius: 24px;
        grid-template-rows: 72px 1fr 52px;
    }

    .game-header h1 {
        font-size: 2.15rem;
    }

    .game-header p {
        font-size: 1rem;
    }

    .round-control {
        top: 16px;
        min-width: 38px;
        height: 38px;
    }

    .home-link {
        left: 14px;
    }

    #restart-btn {
        left: calc(50% - 105px);
    }

    #new-btn {
        right: calc(50% - 105px);
    }

    .arrow-board {
        width: min(360px, calc(100vw - 34px));
    }

    .zoom-control {
        min-width: 150px;
    }

    #zoom-slider {
        width: 92px;
    }

    .tap-prompt {
        bottom: 30px;
        min-width: 176px;
        font-size: 0.85rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .arrow-tile.blocked,
    .arrow-tile.hint .arrow-outer,
    .arrow-tile.exiting-up,
    .arrow-tile.exiting-down,
    .arrow-tile.exiting-left,
    .arrow-tile.exiting-right {
        animation-duration: 0.01ms;
        animation-iteration-count: 1;
    }
}
