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

:root {
    --panel-bg: rgba(21, 24, 22, 0.84);
    --panel-bg-soft: rgba(28, 31, 28, 0.72);
    --panel-border: rgba(225, 178, 70, 0.78);
    --panel-border-soft: rgba(225, 178, 70, 0.38);
    --text-main: #fff7e8;
    --text-muted: #d5d0c6;
    --gold: #f0c84c;
    --gold-soft: #ffe6a7;
    --danger: #ffd1c8;
    --good: #c9f6be;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.42);
}

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

body {
    overflow: hidden;
    background: #222b27;
    font-family: "Courier New", monospace;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    min-height: 100vh;
    min-height: 100svh;
}

canvas {
    display: block;
    touch-action: none;
}

body > canvas {
    filter: saturate(1.12) contrast(1.04);
}

#ui {
    position: fixed;
    inset: 0;
    height: 100svh;
    pointer-events: none;
    z-index: 10;
    color: var(--text-main);
}

#ui::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(90deg, rgba(0, 0, 0, 0.22), transparent 22%, transparent 78%, rgba(0, 0, 0, 0.18)),
        linear-gradient(180deg, rgba(0, 0, 0, 0.26), transparent 30%, transparent 70%, rgba(0, 0, 0, 0.28));
}

.hud-panel,
.modal-panel {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px) saturate(1.12);
    -webkit-backdrop-filter: blur(10px) saturate(1.12);
}

.language-switcher {
    pointer-events: auto;
    display: inline-grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 3px;
    padding: 4px;
    border: 1px solid var(--panel-border-soft);
    border-radius: 8px;
    background: rgba(21, 24, 22, 0.68);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(10px) saturate(1.08);
    -webkit-backdrop-filter: blur(10px) saturate(1.08);
}

.game-language-switcher {
    position: absolute;
    top: max(26px, env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    z-index: 22;
}

.language-switcher button {
    display: grid;
    place-items: center;
    min-width: 34px;
    min-height: 28px;
    margin: 0;
    padding: 5px 8px;
    color: var(--text-muted);
    border: 0;
    border-radius: 5px;
    background: transparent;
    font-size: 12px;
    letter-spacing: 0;
    text-shadow: none;
}

.language-switcher button:hover,
.language-switcher button.is-active {
    color: #1f1b12;
    background: var(--gold);
    transform: none;
}

#score-panel {
    position: absolute;
    top: max(26px, env(safe-area-inset-top));
    right: max(28px, env(safe-area-inset-right));
    width: 190px;
    min-height: 116px;
    padding: 21px 18px 18px;
    text-align: center;
}

.score-label {
    font-size: 13px;
    font-weight: bold;
    letter-spacing: 1.8px;
    color: var(--gold-soft);
    text-transform: uppercase;
    text-shadow: 0 2px 2px rgba(0, 0, 0, 0.8);
}

#score-display {
    margin-top: 8px;
    font-size: 48px;
    line-height: 1;
    font-weight: bold;
    color: #fff;
    text-shadow: 0 4px 8px rgba(0, 0, 0, 0.72);
}

#direction-hud {
    position: absolute;
    top: max(26px, env(safe-area-inset-top));
    left: max(26px, env(safe-area-inset-left));
    width: min(350px, calc(100vw - 52px));
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

#landmark-card {
    min-height: 74px;
    display: grid;
    grid-template-columns: 56px 1fr 28px;
    align-items: center;
    gap: 12px;
    padding: 10px 14px 10px 10px;
}

#landmark-avatar {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    border: 2px solid rgba(255, 255, 255, 0.52);
    border-radius: 50%;
    background: linear-gradient(145deg, rgba(81, 114, 130, 0.95), rgba(26, 42, 44, 0.95));
    color: #fff;
    font-size: 26px;
    line-height: 1;
    box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.18);
}

.landmark-copy {
    min-width: 0;
}

#destination-info {
    color: var(--text-main);
    font-size: 17px;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.75);
}

.landmark-subtitle {
    margin-top: 3px;
    color: var(--text-muted);
    font-size: 11px;
    letter-spacing: 1px;
    text-transform: uppercase;
}

#direction-arrow {
    justify-self: end;
    display: inline-block;
    color: var(--gold);
    font-size: 22px;
    line-height: 1;
    text-shadow: 0 0 12px rgba(240, 200, 76, 0.75);
    transform-origin: 50% 50%;
}

#direction-arrow.pulse {
    animation: arrow-pulse 0.6s ease-in-out infinite;
}

#alert-card {
    display: grid;
    grid-template-columns: 48px 1fr;
    gap: 10px;
    padding: 14px 16px;
    background: var(--panel-bg-soft);
}

.alert-icon {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    color: #1f1b12;
    background: var(--gold);
    border-radius: 5px;
    font-size: 24px;
    font-weight: bold;
}

#poop-pressure {
    color: var(--gold-soft);
    font-size: 13px;
    font-weight: bold;
    line-height: 1.35;
}

#poop-pressure.calm {
    color: var(--good);
}

#poop-pressure.warning {
    color: var(--gold-soft);
}

#poop-pressure.danger {
    color: var(--danger);
    animation: pressure-blink 0.8s ease-in-out infinite;
}

#landmark-message {
    margin-top: 14px;
    color: var(--text-main);
    font-size: 14px;
    line-height: 1.5;
}

#controls-panel {
    position: absolute;
    left: 26px;
    bottom: 24px;
    width: 194px;
    padding: 15px 17px;
}

.mobile-control {
    display: none;
}

.control-row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 12px;
    color: var(--text-main);
    font-size: 13px;
    line-height: 1;
}

.control-row + .control-row {
    margin-top: 15px;
}

.key-group {
    display: flex;
    justify-content: flex-end;
    gap: 2px;
}

kbd {
    display: inline-grid;
    place-items: center;
    min-width: 18px;
    height: 18px;
    margin-left: 2px;
    padding: 0 3px;
    color: var(--text-main);
    border: 1px solid rgba(255, 255, 255, 0.72);
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.08);
    font-family: inherit;
    font-size: 11px;
    font-weight: bold;
    line-height: 1;
    box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.4);
}

#minimap-panel {
    position: absolute;
    right: 28px;
    bottom: 24px;
    width: 216px;
    height: 164px;
    padding: 10px;
    overflow: hidden;
    pointer-events: auto;
    cursor: pointer;
}

#minimap-canvas {
    width: 100%;
    height: 100%;
    border-radius: 5px;
    background: rgba(230, 220, 190, 0.18);
}

body.map-expanded #minimap-panel {
    width: min(520px, calc(100vw - 56px));
    height: min(380px, calc(100vh - 180px));
    z-index: 18;
}

.modal-panel {
    position: absolute;
    top: 50%;
    left: 50%;
    width: min(520px, calc(100vw - 36px));
    max-height: calc(100svh - 36px);
    overflow: auto;
    transform: translate(-50%, -50%);
    padding: 34px 38px 28px;
    text-align: left;
    pointer-events: auto;
    scrollbar-width: none;
}

.modal-panel::-webkit-scrollbar {
    display: none;
}

#start-screen {
    text-align: center;
}

#pause-screen {
    text-align: center;
}

#start-screen h1,
#pause-screen h1,
#game-over-screen h1 {
    margin-bottom: 14px;
    color: #fff;
    font-size: clamp(34px, 7vw, 44px);
    line-height: 1.05;
    letter-spacing: 1px;
    text-align: center;
    text-shadow: 0 4px 0 rgba(0, 0, 0, 0.58), 0 8px 16px rgba(0, 0, 0, 0.52);
}

#start-screen h1 {
    font-size: clamp(40px, 8vw, 54px);
}

.location {
    color: var(--gold-soft);
    font-size: 15px !important;
    font-weight: bold;
    letter-spacing: 1.4px;
    text-transform: uppercase;
}

.subtitle,
#start-screen p,
#pause-screen p,
#game-over-screen p {
    color: var(--text-main);
    font-size: 15px;
    line-height: 1.5;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.78);
}

.subtitle {
    max-width: 430px;
    margin: 10px auto 0 !important;
    color: var(--text-muted);
}

.landmarks {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 7px;
    max-width: 430px;
    margin: 18px auto 4px;
}

.landmarks span {
    max-width: 100%;
    padding: 6px 9px;
    color: var(--text-main);
    border: 1px solid var(--panel-border-soft);
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.07);
    font-size: 11px;
    line-height: 1.1;
    white-space: nowrap;
    text-shadow: none;
}

.controls-hint {
    margin-top: 18px !important;
    color: var(--text-muted) !important;
    font-size: 13px !important;
}

.civic-divider {
    width: 100%;
    height: 1px;
    margin: 13px 0 16px;
    background:
        linear-gradient(90deg, transparent, var(--panel-border), transparent);
}

#game-over-roast {
    color: var(--gold-soft);
    font-size: 16px !important;
    font-weight: bold;
}

#success-medal,
#success-burst {
    display: none;
}

#game-over-screen.is-success {
    overflow: visible;
    border-color: rgba(201, 246, 190, 0.88);
    box-shadow:
        var(--shadow),
        0 0 32px rgba(101, 211, 126, 0.24);
}

#game-over-screen.is-success #success-medal {
    display: grid;
    place-items: center;
    width: 76px;
    height: 76px;
    margin: -74px auto 14px;
    color: #17361d;
    border: 3px solid rgba(255, 255, 255, 0.72);
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #f7ffe3, #8ee98e 62%, #3aa953);
    font-size: 46px;
    font-weight: bold;
    line-height: 1;
    box-shadow: 0 16px 32px rgba(0, 0, 0, 0.38), 0 0 36px rgba(142, 233, 142, 0.5);
    animation: success-pop 0.72s cubic-bezier(0.22, 1.4, 0.36, 1) both;
}

#game-over-screen.is-success #success-burst {
    display: block;
    position: absolute;
    inset: -32px 10px auto;
    height: 130px;
    pointer-events: none;
}

#game-over-screen.is-success #success-burst span {
    position: absolute;
    top: 54px;
    left: 50%;
    width: 8px;
    height: 24px;
    border-radius: 2px;
    background: var(--gold);
    animation: success-spark 0.95s ease-out both;
}

#game-over-screen.is-success #success-burst span:nth-child(1) { --spark-x: -178px; --spark-y: -46px; rotate: -28deg; }
#game-over-screen.is-success #success-burst span:nth-child(2) { --spark-x: -108px; --spark-y: -84px; rotate: 18deg; background: var(--good); animation-delay: 0.05s; }
#game-over-screen.is-success #success-burst span:nth-child(3) { --spark-x: -34px; --spark-y: -98px; rotate: -8deg; animation-delay: 0.1s; }
#game-over-screen.is-success #success-burst span:nth-child(4) { --spark-x: 52px; --spark-y: -92px; rotate: 24deg; background: var(--good); animation-delay: 0.08s; }
#game-over-screen.is-success #success-burst span:nth-child(5) { --spark-x: 124px; --spark-y: -64px; rotate: -18deg; animation-delay: 0.14s; }
#game-over-screen.is-success #success-burst span:nth-child(6) { --spark-x: 184px; --spark-y: -30px; rotate: 32deg; background: var(--good); animation-delay: 0.03s; }

#civic-summary {
    color: var(--text-muted);
    font-size: 13px !important;
}

.stats-grid {
    display: grid;
    gap: 8px;
    margin: 24px auto 4px;
    max-width: 330px;
}

.stats-grid p {
    display: grid;
    grid-template-columns: 24px 1fr;
    align-items: center;
    gap: 8px;
    margin: 0;
    color: var(--text-main);
    font-size: 16px !important;
}

.stats-grid strong {
    font-weight: bold;
}

button {
    display: block;
    min-width: min(276px, 100%);
    min-height: 70px;
    margin: 28px auto 0;
    padding: 16px 30px;
    color: var(--gold-soft);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    background: linear-gradient(180deg, rgba(42, 61, 47, 0.96), rgba(26, 44, 36, 0.96));
    font-family: "Courier New", monospace;
    font-size: clamp(16px, 4vw, 20px);
    font-weight: bold;
    letter-spacing: 1px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.85);
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

button:hover {
    transform: translateY(-1px);
    border-color: var(--gold-soft);
    background: linear-gradient(180deg, rgba(51, 74, 57, 0.98), rgba(30, 52, 42, 0.98));
}

button:active {
    transform: translateY(1px);
}

.hidden {
    display: none !important;
}

.anim-slide-down {
    animation: slide-down 0.6s ease-out both;
}

.anim-fade-in {
    animation: fade-in 0.8s ease-out both;
}

.anim-fade-in:nth-child(2) { animation-delay: 0.15s; }
.anim-fade-in:nth-child(3) { animation-delay: 0.3s; }
.anim-fade-in:nth-child(4) { animation-delay: 0.45s; }
.anim-fade-in:nth-child(5) { animation-delay: 0.6s; }
.anim-fade-in:nth-child(6) { animation-delay: 0.75s; }

@keyframes slide-down {
    from {
        opacity: 0;
        transform: translateY(-18px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes arrow-pulse {
    0%, 100% { scale: 1; }
    50% { scale: 1.26; }
}

@keyframes pressure-blink {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.03); }
}

@keyframes success-pop {
    0% {
        opacity: 0;
        transform: scale(0.35) rotate(-16deg);
    }
    70% {
        opacity: 1;
        transform: scale(1.12) rotate(4deg);
    }
    100% {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
}

@keyframes success-spark {
    0% {
        opacity: 0;
        transform: translate(-50%, 0) scaleY(0.3);
    }
    18% {
        opacity: 1;
    }
    100% {
        opacity: 0;
        transform: translate(calc(-50% + var(--spark-x)), var(--spark-y)) scaleY(1);
    }
}

@keyframes swipe-pulse {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

@media (max-width: 760px) {
    #score-panel {
        top: max(12px, env(safe-area-inset-top));
        right: max(12px, env(safe-area-inset-right));
        width: 130px;
        min-height: 78px;
        padding: 13px 10px 10px;
    }

    .score-label {
        font-size: 9px;
        letter-spacing: 1px;
    }

    #score-display {
        font-size: 32px;
    }

    #direction-hud {
        top: max(12px, env(safe-area-inset-top));
        left: max(12px, env(safe-area-inset-left));
        width: calc(100vw - 160px);
        min-width: 176px;
    }

    #landmark-card {
        grid-template-columns: 38px 1fr 18px;
        min-height: 56px;
        gap: 8px;
        padding: 8px;
    }

    #landmark-avatar {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }

    #destination-info {
        font-size: 12px;
    }

    .landmark-subtitle {
        font-size: 9px;
    }

    #direction-arrow {
        font-size: 18px;
    }

    #alert-card {
        display: none;
    }

    .game-language-switcher {
        top: max(96px, calc(env(safe-area-inset-top) + 96px));
        left: auto;
        right: max(12px, env(safe-area-inset-right));
        transform: none;
    }

    .language-switcher {
        gap: 2px;
        padding: 3px;
    }

    .language-switcher button {
        min-width: 28px;
        min-height: 24px;
        padding: 4px 6px;
        font-size: 10px;
    }

    #controls-panel {
        left: 12px;
        bottom: 12px;
        width: 170px;
        padding: 11px 12px;
    }

    .desktop-control {
        display: none;
    }

    .mobile-control {
        display: grid;
        grid-template-columns: 44px 1fr;
        align-items: center;
        gap: 9px;
        margin-bottom: 10px;
        color: var(--text-main);
        font-size: 11px;
        line-height: 1.2;
    }

    .mobile-control strong,
    .mobile-control span {
        display: block;
    }

    .mobile-control strong {
        color: var(--gold-soft);
        font-size: 13px;
        text-transform: uppercase;
    }

    .swipe-icon {
        display: grid;
        grid-template-columns: repeat(3, 12px);
        grid-template-rows: repeat(3, 12px);
        place-content: center;
        width: 42px;
        height: 42px;
        border: 1px solid var(--panel-border-soft);
        border-radius: 6px;
        background: rgba(255, 255, 255, 0.08);
        color: var(--gold);
        font-size: 13px;
        font-weight: bold;
        line-height: 1;
        animation: swipe-pulse 1.15s ease-in-out infinite;
    }

    .swipe-icon span {
        display: grid;
        place-items: center;
    }

    .swipe-icon span:nth-child(1) { grid-column: 2; grid-row: 1; }
    .swipe-icon span:nth-child(2) { grid-column: 1; grid-row: 2; }
    .swipe-icon span:nth-child(3) { grid-column: 3; grid-row: 2; }
    .swipe-icon span:nth-child(4) { grid-column: 2; grid-row: 3; }

    .control-row {
        gap: 6px;
        font-size: 11px;
    }

    .control-row + .control-row {
        margin-top: 10px;
    }

    kbd {
        min-width: 16px;
        height: 16px;
        font-size: 9px;
    }

    #minimap-panel {
        right: 12px;
        bottom: 12px;
        width: 132px;
        height: 106px;
        padding: 7px;
    }

    body.map-expanded #minimap-panel {
        width: calc(100vw - 24px);
        height: min(52vh, 360px);
    }

    .modal-panel {
        width: calc(100vw - 28px);
        max-height: calc(100svh - 28px);
        overflow: auto;
        padding: 24px 20px 20px;
    }

    #start-screen h1,
    #pause-screen h1,
    #game-over-screen h1 {
        font-size: 34px;
    }

    #start-screen h1 {
        font-size: 40px;
    }

    .location {
        font-size: 12px !important;
        letter-spacing: 1px;
    }

    .subtitle,
    #start-screen p,
    #pause-screen p,
    #game-over-screen p {
        font-size: 13px;
    }

    .landmarks {
        max-width: 300px;
        gap: 5px;
        margin-top: 14px;
    }

    .landmarks span {
        max-width: 140px;
        font-size: 9px;
        white-space: normal;
    }

    .stats-grid p {
        font-size: 13px !important;
    }

    #game-over-screen.is-success #success-medal {
        width: 62px;
        height: 62px;
        margin-top: -56px;
        font-size: 38px;
    }

    #game-over-screen.is-success #success-burst span:nth-child(1) { --spark-x: -118px; --spark-y: -34px; }
    #game-over-screen.is-success #success-burst span:nth-child(2) { --spark-x: -72px; --spark-y: -64px; }
    #game-over-screen.is-success #success-burst span:nth-child(3) { --spark-x: -22px; --spark-y: -78px; }
    #game-over-screen.is-success #success-burst span:nth-child(4) { --spark-x: 34px; --spark-y: -72px; }
    #game-over-screen.is-success #success-burst span:nth-child(5) { --spark-x: 78px; --spark-y: -46px; }
    #game-over-screen.is-success #success-burst span:nth-child(6) { --spark-x: 116px; --spark-y: -22px; }

    button {
        min-width: min(220px, 100%);
        min-height: 58px;
        margin-top: 20px;
        padding: 13px 22px;
        font-size: 16px;
    }
}

@media (max-width: 420px) {
    #direction-hud {
        width: calc(100vw - 168px);
        min-width: 140px;
    }

    .game-language-switcher {
        top: max(86px, calc(env(safe-area-inset-top) + 86px));
    }

    #controls-panel {
        width: 156px;
    }
}

@media (max-height: 520px) {
    .modal-panel {
        top: 12px;
        max-height: calc(100svh - 24px);
        transform: translateX(-50%);
        padding: 18px 22px 16px;
    }

    #start-screen h1,
    #pause-screen h1,
    #game-over-screen h1 {
        margin-bottom: 8px;
        font-size: clamp(30px, 7vw, 38px);
    }

    #start-screen h1 {
        font-size: clamp(34px, 8vw, 44px);
    }

    .subtitle,
    #start-screen p,
    #pause-screen p,
    #game-over-screen p {
        font-size: 12px;
        line-height: 1.35;
    }

    .landmarks {
        margin-top: 10px;
        gap: 5px;
    }

    .landmarks span {
        padding: 5px 8px;
        font-size: 9px;
    }

    button {
        min-height: 50px;
        margin-top: 14px;
        padding: 11px 22px;
    }

    .game-language-switcher {
        top: auto;
        right: max(12px, env(safe-area-inset-right));
        bottom: max(132px, calc(env(safe-area-inset-bottom) + 132px));
    }

    .controls-hint {
        margin-top: 10px !important;
    }
}

@media (max-height: 420px) and (orientation: landscape) {
    .modal-panel {
        top: 8px;
        max-height: calc(100svh - 16px);
        min-height: calc(100svh - 16px);
        padding: 14px 22px 12px;
    }

    #start-screen h1,
    #pause-screen h1,
    #game-over-screen h1 {
        margin-bottom: 6px;
        font-size: clamp(28px, 6vw, 36px);
    }

    #start-screen h1 {
        font-size: clamp(32px, 7vw, 42px);
    }

    .landmarks {
        margin-top: 8px;
    }

    button {
        min-height: 48px;
        margin-top: 14px;
    }

    .controls-hint {
        display: none;
    }
}
