:root {
    --bg-gradient: linear-gradient(135deg, #8fd3f4 0%, #84fab0 100%);
    --primary: #ff7aa8;
    --primary-dark: #d95c8c;
    --accent: #ffb347;
    --text: #2f2a3a;
    --card: rgba(255, 255, 255, 0.9);
    --shadow: 0 20px 45px rgba(47, 42, 58, 0.18);
    --font: "Baloo 2", "Segoe UI", sans-serif;
}

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

.word {
    --letters-count: 8;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: clamp(6px, calc(24px - var(--letters-count, 8) * 0.6px), 18px);
    font-size: clamp(1.2rem, calc(3rem - var(--letters-count, 8) * 0.1rem), 2.6rem);
    letter-spacing: clamp(1px, calc(6px - var(--letters-count, 8) * 0.2px), 4px);
    transition: font-size 0.2s ease;
}

.word span {
    border-bottom: 4px solid rgba(255, 122, 168, 0.5);
    min-width: clamp(20px, calc(48px - var(--letters-count, 8) * 1.5px), 44px);
    text-align: center;
    padding-bottom: 6px;
    font-weight: 600;
}

body {
    font-family: var(--font);
    min-height: 100vh;
    background: var(--bg-gradient);
    color: var(--text);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 40px 24px 60px;
    gap: 24px;
}

.impiccato-main {
    width: min(1040px, 100%);
    display: flex;
    flex-direction: column;
    gap: 18px;
    align-items: stretch;
}

.impiccato-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.75);
    color: rgba(47, 42, 58, 0.85);
    text-decoration: none;
    font-weight: 700;
    border: 1px solid rgba(47, 42, 58, 0.15);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.back-link:hover,
.back-link:focus-visible {
    transform: translateY(-2px);
    box-shadow: 0 12px 25px rgba(47, 42, 58, 0.15);
    border-color: rgba(47, 42, 58, 0.3);
}

.brand-tag {
    padding: 8px 16px;
    border-radius: 999px;
    background: rgba(47, 42, 58, 0.12);
    color: rgba(47, 42, 58, 0.8);
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.page {
    width: min(960px, 100%);
    background: var(--card);
    border-radius: 32px;
    box-shadow: var(--shadow);
    padding: 40px;
    display: flex;
    flex-direction: column;
    gap: 32px;
    position: relative;
    overflow: hidden;
}

.page::before {
    content: "";
    position: absolute;
    width: 320px;
    height: 320px;
    background: radial-gradient(circle at 30% 30%, rgba(255, 122, 168, 0.18), transparent 70%);
    top: -120px;
    right: -80px;
    z-index: 0;
}

.page > * {
    position: relative;
    z-index: 1;
}

.game-header {
    text-align: center;
}

.game-header h1 {
    font-size: clamp(2.2rem, 4vw, 3rem);
    color: var(--primary);
    text-shadow: 0 6px 14px rgba(255, 122, 168, 0.3);
}

.game-header .tagline {
    margin-top: 8px;
    font-size: 1.05rem;
    color: rgba(47, 42, 58, 0.75);
}

.game {
    display: grid;
    grid-template-columns: minmax(240px, 320px) 1fr;
    gap: 40px;
    align-items: center;
}

.gallows {
    position: relative;
    width: 100%;
    height: 300px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.pole {
    background: #6b5b95;
    border-radius: 999px;
}

.pole.base {
    width: 180px;
    height: 14px;
}

.pole.vertical {
    position: absolute;
    height: 260px;
    width: 12px;
    left: calc(50% - 90px);
    bottom: 14px;
}

.pole.horizontal {
    position: absolute;
    height: 12px;
    width: 200px;
    left: calc(50% - 90px);
    bottom: 260px;
}

.rope {
    position: absolute;
    width: 6px;
    height: 45px;
    background: #f7d6a8;
    left: calc(50% + 100px);
    bottom: 260px;
}

.figure {
    position: absolute;
    bottom: 90px;
    left: calc(50% + 90px);
    transform: translateX(-50%);
    display: grid;
    place-items: center;
    width: 100px;
}

.figure > div {
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity 0.35s ease, transform 0.5s cubic-bezier(.34,1.56,.64,1);
}

.figure .head {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ffffff, #fef5fb);
    background: #fff;
}

.figure .body {
    width: 6px;
    height: 70px;
    background: var(--primary);
    margin-top: 2px;
}

.figure .arm {
    width: 60px;
    height: 6px;
    background: var(--primary);
    transform-origin: center left;
}

.figure .arm.right {
    transform-origin: center right;
}

.figure .leg {
    width: 6px;
    height: 60px;
    background: var(--primary);
    margin-top: 4px;
}

.figure .leg.left {
    transform: rotate(18deg);
}

.figure .leg.right {
    transform: rotate(-18deg);
}

.figure .show {
    opacity: 1;
    transform: translateY(0);
}

.status {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.word {
    display: flex;
    gap: 18px;
    justify-content: center;
    font-size: clamp(1.8rem, 4vw, 2.4rem);
    letter-spacing: 4px;
}

.word span {
    border-bottom: 4px solid rgba(255, 122, 168, 0.5);
    min-width: 32px;
    text-align: center;
    padding-bottom: 6px;
    font-weight: 600;
}

.attempts {
    font-size: 1.1rem;
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: center;
}

.attempts span:last-child {
    font-weight: 700;
    color: var(--primary);
    font-size: 1.4rem;
}

.wrong-letters {
    text-align: center;
    font-size: 1rem;
}

.wrong-letters #wrongLetters {
    margin-top: 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    color: var(--primary-dark);
    font-weight: 600;
}

.word-source {
    margin-top: 12px;
    text-align: center;
    font-size: 0.95rem;
    font-weight: 600;
    padding: 10px 14px;
    border-radius: 18px;
    background: rgba(47, 42, 58, 0.08);
    color: rgba(47, 42, 58, 0.85);
    display: inline-flex;
    align-self: center;
    align-items: center;
    gap: 8px;
    transition: background 0.3s ease, color 0.3s ease, transform 0.3s ease;
}

.word-source::before {
    content: "";
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 0 4px rgba(47, 42, 58, 0.12);
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

.word-source[data-source="loading"] {
    background: rgba(47, 42, 58, 0.16);
    color: rgba(47, 42, 58, 0.75);
}

.word-source[data-source="loading"]::before {
    background: rgba(47, 42, 58, 0.5);
    box-shadow: 0 0 0 4px rgba(47, 42, 58, 0.2);
}

.word-source[data-source="remote"] {
    background: rgba(73, 212, 141, 0.15);
    color: #218c5c;
}

.word-source[data-source="remote"]::before {
    background: #33c17a;
    box-shadow: 0 0 0 4px rgba(51, 193, 122, 0.25);
}

.word-source[data-source="fallback"] {
    background: rgba(255, 163, 102, 0.18);
    color: #b0521f;
}

.word-source[data-source="fallback"]::before {
    background: #ff8a3d;
    box-shadow: 0 0 0 4px rgba(255, 138, 61, 0.25);
}

.controls {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.keyboard {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
    gap: 10px;
}

.keyboard button {
    padding: 12px;
    border-radius: 14px;
    border: none;
    font-size: 1.1rem;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.8);
    color: var(--text);
    background: linear-gradient(145deg, #fff5fc, #ffe3f2);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.25s ease;
}

.keyboard button:hover:not(:disabled),
.keyboard button:focus-visible {
    transform: translateY(-2px);
    box-shadow: 0 14px 24px rgba(47, 42, 58, 0.16);
}

.keyboard button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

button.primary {
    align-self: center;
    padding: 14px 32px;
    border-radius: 20px;
    border: none;
    background: var(--primary);
    color: white;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 12px 24px rgba(255, 122, 168, 0.3);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

button.primary:hover,
button.primary:focus-visible {
    transform: translateY(-3px);
    box-shadow: 0 16px 28px rgba(255, 122, 168, 0.38);
}

.footer {
    text-align: center;
    font-size: 0.95rem;
    color: rgba(47, 42, 58, 0.65);
}

.modal {
    position: fixed;
    inset: 0;
    background: #120c1e;
    display: grid;
    place-items: center;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    overflow: hidden;
    z-index: 9999;
}

.modal::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 15% 20%, #ffe396 0%, #ffcf7f 55%, #f9b561 100%),
        radial-gradient(circle at 80% 15%, #ff7aa8 0%, #f95695 52%, #e23274 100%),
        radial-gradient(circle at 70% 70%, #84fab0 0%, #4dd8a0 48%, #33b985 100%),
        linear-gradient(135deg, #322d42, #241f33);
    filter: blur(10px);
    opacity: 0.55;
    z-index: 0;
    pointer-events: none;
}

.modal::after {
    content: "";
    position: absolute;
    width: clamp(180px, 28vw, 340px);
    height: clamp(180px, 28vw, 340px);
    background: linear-gradient(135deg, #ff7aa8, #ff4f91);
    border-radius: 24px;
    box-shadow: 0 28px 55px rgba(255, 79, 145, 0.35);
    z-index: 1;
    pointer-events: none;
    top: 12%;
    right: 14%;
    transform: rotate(-8deg);
}

.modal[data-state="lose"]::after {
    background: linear-gradient(135deg, #ff8a64, #ff4f4f);
    box-shadow: 0 28px 55px rgba(255, 79, 79, 0.38);
}
.modal[data-state="win"]::after {
    background: linear-gradient(135deg, #7ce8b5, #49d48d);
    box-shadow: 0 28px 55px rgba(73, 212, 141, 0.32);
}

.modal.hidden {
    opacity: 0;
    visibility: hidden;
}

.modal .modal-content {
    background: #ffffff;
    border-radius: 24px;
    padding: 36px 42px;
    text-align: center;
    box-shadow: 0 24px 50px rgba(47, 42, 58, 0.25);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 22px;
    width: min(480px, 90vw);
    position: relative;
    z-index: 3;
}

.modal-content h2 {
    color: var(--primary);
    font-size: 2.2rem;
    position: relative;
    z-index: 4;
}

.modal-content p {
    font-size: 1.15rem;
    line-height: 1.6;
}

.modal-summary {
    background: linear-gradient(145deg, rgba(255, 250, 253, 0.9), rgba(255, 244, 248, 0.9));
    border-radius: 20px;
    padding: 18px 22px;
    display: grid;
    gap: 16px;
    text-align: left;
    box-shadow: inset 0 0 0 1px rgba(255, 122, 168, 0.15);
}

.modal-summary .summary-block {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.summary-label {
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 1.8px;
    color: rgba(47, 42, 58, 0.65);
    font-weight: 700;
}

.summary-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary-dark);
    word-break: break-word;
}

.summary-value span {
    display: inline-block;
    margin: 2px 6px 2px 0;
    padding: 4px 10px;
    border-radius: 12px;
    background: rgba(255, 122, 168, 0.16);
    color: var(--text);
    font-weight: 600;
}

.summary-value span[data-state="wrong"] {
    background: rgba(255, 118, 118, 0.25);
    color: #c0392b;
}

.modal .primary {
    width: 100%;
    align-self: center;
}

.modal .primary:hover,
.modal .primary:focus-visible {
    transform: translateY(-1px);
}

.modal[data-state="win"] .modal-content {
    background: linear-gradient(180deg, #ffffff 0%, #f0fff6 100%);
    box-shadow: 0 28px 60px rgba(73, 212, 141, 0.25);
}

.modal[data-state="win"] .modal-content h2 {
    color: #2f9f6b;
}

.modal[data-state="win"] .summary-value {
    color: #2f9f6b;
}

.modal[data-state="win"] .summary-value span {
    background: rgba(73, 212, 141, 0.16);
}

.modal[data-state="win"] .modal-content p {
    color: rgba(31, 86, 61, 0.82);
}

.modal[data-state="win"] .primary {
    background: linear-gradient(135deg, #33c17a, #27a162);
    box-shadow: 0 12px 28px rgba(51, 193, 122, 0.35);
}

.modal[data-state="win"] .primary:hover,
.modal[data-state="win"] .primary:focus-visible {
    box-shadow: 0 16px 32px rgba(51, 193, 122, 0.42);
}

.modal[data-state="lose"] .modal-content {
    background: linear-gradient(180deg, #ffffff 0%, #fff2f2 100%);
    box-shadow: 0 28px 60px rgba(255, 79, 79, 0.22);
}

.modal[data-state="lose"] .modal-content h2 {
    color: #d94a4a;
}

.modal[data-state="lose"] .modal-content p {
    color: rgba(120, 37, 37, 0.85);
}

.modal[data-state="lose"] .summary-value {
    color: #d94a4a;
}

.modal[data-state="lose"] .summary-value span {
    background: rgba(255, 105, 105, 0.24);
    color: #a83939;
}

.modal[data-state="lose"] .summary-value span[data-state="wrong"] {
    background: rgba(255, 82, 82, 0.35);
    color: #8a1f1f;
}

.modal[data-state="lose"] .primary {
    background: linear-gradient(135deg, #ff6f61, #f04a4a);
    box-shadow: 0 12px 24px rgba(240, 74, 74, 0.34);
}

.modal[data-state="lose"] .primary:hover,
.modal[data-state="lose"] .primary:focus-visible {
    box-shadow: 0 16px 32px rgba(240, 74, 74, 0.42);
}

@media (max-width: 820px) {
    body {
        padding: 32px 16px 48px;
    }

    .page {
        padding: 28px;
    }

    .game {
        grid-template-columns: 1fr;
        gap: 28px;
    }

    .gallows {
        height: 240px;
    }

    .controls {
        order: 3;
    }

    .keyboard {
        grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
    }
}

@media (max-width: 520px) {
    body {
        padding: 28px 12px 36px;
    }

    .impiccato-topbar {
        justify-content: center;
    }

    .page {
        border-radius: 24px;
        padding: 20px;
        gap: 24px;
    }

    .word {
        gap: 12px;
    }

    .keyboard button {
        font-size: 1rem;
        padding: 10px;
    }

    button.primary {
        width: 100%;
    }
}
