* {
    box-sizing: border-box;
}

:root {
    color-scheme: dark;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: #090d18;
    touch-action: none;
    overscroll-behavior: none;
}

button {
    font: inherit;
}

#app {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 100svh;
    background:
        radial-gradient(circle at center, rgba(49, 72, 111, 0.18), transparent 60%),
        #090d18;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.hidden {
    display: none !important;
}

.hud {
    position: absolute;
    z-index: 10;
    top: max(12px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    right: max(58px, env(safe-area-inset-right));
    display: flex;
    gap: 16px;
    align-items: flex-start;
    pointer-events: none;
}

.hud__group {
    width: min(340px, 52vw);
    padding: 10px 12px;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 14px;
    background: rgba(9, 13, 24, 0.72);
    backdrop-filter: blur(10px);
}

.hud__label,
.hud__value {
    font-size: 12px;
    color: #d7e2f2;
}

.hud__value {
    margin-top: 5px;
    text-align: right;
}

.bar {
    height: 11px;
    margin-top: 6px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(255,255,255,0.12);
}

.bar__fill {
    width: 100%;
    height: 100%;
    transition: width 120ms linear;
}

.bar__fill--health {
    background: linear-gradient(90deg, #ef4444, #f97316);
}

.hud__stats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-left: auto;
}

.hud__stats span {
    padding: 8px 10px;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 12px;
    background: rgba(9, 13, 24, 0.72);
    color: #d7e2f2;
    font-size: 13px;
    backdrop-filter: blur(10px);
}

.announcement {
    position: absolute;
    z-index: 20;
    top: 22%;
    left: 50%;
    transform: translateX(-50%);
    width: min(680px, calc(100% - 32px));
    padding: 18px 22px;
    border: 1px solid rgba(255,255,255,0.14);
    border-radius: 18px;
    background: rgba(9, 13, 24, 0.88);
    text-align: center;
    font-size: clamp(22px, 5vw, 40px);
    font-weight: 800;
    letter-spacing: 0.03em;
    box-shadow: 0 18px 60px rgba(0,0,0,0.35);
}

.overlay {
    position: absolute;
    z-index: 30;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(3, 7, 18, 0.76);
    backdrop-filter: blur(8px);
}

.panel {
    width: min(900px, 100%);
    max-height: calc(100svh - 40px);
    overflow: auto;
    padding: clamp(22px, 4vw, 38px);
    border: 1px solid rgba(255,255,255,0.14);
    border-radius: 24px;
    background: linear-gradient(180deg, rgba(25, 34, 54, 0.98), rgba(12, 18, 31, 0.98));
    box-shadow: 0 28px 90px rgba(0,0,0,0.45);
}

.panel--narrow {
    max-width: 560px;
}

.panel h1,
.panel h2 {
    margin-top: 0;
}

.panel h1 {
    font-size: clamp(36px, 8vw, 68px);
    margin-bottom: 12px;
}

.panel p {
    color: #bac7da;
    line-height: 1.65;
}

.controls {
    display: grid;
    gap: 8px;
    margin: 20px 0 26px;
    color: #dce6f5;
}

.button {
    min-height: 48px;
    padding: 12px 20px;
    border: 0;
    border-radius: 14px;
    cursor: pointer;
    font-weight: 800;
}

.button--primary {
    background: linear-gradient(135deg, #38bdf8, #6366f1);
    color: white;
    box-shadow: 0 10px 30px rgba(59, 130, 246, 0.28);
}

.upgrade-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-top: 20px;
}

.upgrade-card {
    display: flex;
    min-height: 180px;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 18px;
    border: 1px solid rgba(255,255,255,0.14);
    border-radius: 18px;
    background: rgba(255,255,255,0.06);
    color: white;
    cursor: pointer;
    text-align: left;
    transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.upgrade-card:hover,
.upgrade-card:focus-visible {
    transform: translateY(-3px);
    border-color: rgba(56, 189, 248, 0.75);
    background: rgba(56, 189, 248, 0.12);
}

.upgrade-card__icon {
    font-size: 28px;
}

.upgrade-card__title {
    font-size: 18px;
    font-weight: 800;
}

.upgrade-card__description {
    color: #b7c4d7;
    line-height: 1.45;
}

.joystick {
    position: absolute;
    z-index: 12;
    left: max(22px, env(safe-area-inset-left));
    bottom: max(22px, env(safe-area-inset-bottom));
    width: 132px;
    height: 132px;
    border: 2px solid rgba(255,255,255,0.18);
    border-radius: 50%;
    background: rgba(255,255,255,0.06);
    backdrop-filter: blur(8px);
    opacity: 0;
    pointer-events: none;
}

.joystick__knob {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 58px;
    height: 58px;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: rgba(125, 211, 252, 0.8);
    box-shadow: 0 0 28px rgba(56, 189, 248, 0.4);
}

.pause-button {
    position: absolute;
    z-index: 15;
    top: max(12px, env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
    width: 42px;
    height: 42px;
    border: 1px solid rgba(255,255,255,0.14);
    border-radius: 12px;
    background: rgba(9,13,24,0.72);
    color: white;
    cursor: pointer;
    backdrop-filter: blur(10px);
}

@media (pointer: coarse) {
    .joystick {
        opacity: 1;
        pointer-events: auto;
    }
}

@media (max-width: 760px) {
    .hud {
        flex-direction: column;
        gap: 8px;
        right: 58px;
    }

    .hud__group {
        width: min(100%, 360px);
    }

    .hud__stats {
        margin-left: 0;
    }

    .upgrade-grid {
        grid-template-columns: 1fr;
    }

    .upgrade-card {
        min-height: 130px;
    }
}


/* Talentbaum */
.talent-panel { width: min(1080px, 100%); }
.talent-header, .talent-actions {
    display: flex; gap: 18px; align-items: center; justify-content: space-between;
}
.talent-header h2 { margin-bottom: 4px; }
.talent-header p { margin: 0; }
.talent-points {
    flex: 0 0 auto; padding: 12px 16px;
    border: 1px solid rgba(125,211,252,.35);
    border-radius: 14px; background: rgba(56,189,248,.1); font-weight: 700;
}
.talent-tree { display: grid; gap: 18px; margin: 26px 0; }
.talent-root { display: flex; justify-content: center; position: relative; padding-bottom: 20px; }
.talent-root::after {
    content: ""; position: absolute; bottom: 0; left: 50%;
    width: 2px; height: 20px; background: rgba(148,163,184,.4);
}
.talent-branches { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 22px; }
.talent-branch {
    position: relative; padding: 18px; border: 1px solid rgba(255,255,255,.11);
    border-radius: 20px; background: rgba(255,255,255,.035);
}
.talent-branch::before {
    content: ""; position: absolute; top: -18px; left: 50%;
    width: 2px; height: 18px; background: rgba(148,163,184,.4);
}
.talent-branch__title { margin: 0 0 16px; text-align: center; font-size: 20px; }
.talent-branch__title--endurance { color: #67e8f9; }
.talent-branch__title--damage { color: #fca5a5; }
.talent-list { display: grid; gap: 12px; }
.talent-node {
    position: relative; display: grid; grid-template-columns: 42px 1fr auto;
    gap: 12px; align-items: center; width: 100%; min-height: 88px; padding: 13px;
    border: 1px solid rgba(255,255,255,.12); border-radius: 16px;
    background: rgba(255,255,255,.055); color: white; cursor: pointer; text-align: left;
}
.talent-node:not(:first-child)::before {
    content: ""; position: absolute; top: -13px; left: 32px;
    width: 2px; height: 13px; background: rgba(148,163,184,.32);
}
.talent-node:hover:not(:disabled), .talent-node:focus-visible:not(:disabled) {
    border-color: rgba(125,211,252,.75); background: rgba(56,189,248,.12);
}
.talent-node:disabled { cursor: not-allowed; }
.talent-node--locked { opacity: .43; filter: grayscale(.65); }
.talent-node--available { border-color: rgba(250,204,21,.62); box-shadow: 0 0 0 1px rgba(250,204,21,.12); }
.talent-node--owned { border-color: rgba(34,197,94,.62); background: rgba(34,197,94,.1); }
.talent-node__icon { font-size: 27px; text-align: center; }
.talent-node__name { display: block; font-weight: 800; }
.talent-node__description { display: block; margin-top: 4px; color: #b9c6d8; font-size: 13px; line-height: 1.4; }
.talent-node__state { font-size: 12px; font-weight: 800; color: #dbeafe; }
.talent-actions { padding-top: 16px; border-top: 1px solid rgba(255,255,255,.1); }
.talent-actions .button:disabled { opacity: .45; cursor: not-allowed; }

@media (max-width: 760px) {
    .talent-header, .talent-actions { align-items: stretch; flex-direction: column; }
    .talent-branches { grid-template-columns: 1fr; }
    .talent-root::after, .talent-branch::before { display: none; }
}


/* Version 3: kompakter Talentbaum */
.talent-panel {
    width: min(980px, 100%);
    padding: 20px;
}

.talent-header {
    min-height: 38px;
}

.talent-header h2 {
    margin: 0;
    font-size: 25px;
}

.talent-points {
    padding: 7px 11px;
    border-radius: 10px;
    font-size: 14px;
}

.talent-tree {
    max-height: min(66svh, 610px);
    margin: 14px 0;
    padding: 2px;
    overflow: auto;
}

.talent-root {
    padding-bottom: 12px;
}

.talent-root::after {
    height: 12px;
}

.talent-root .talent-node {
    width: min(250px, 100%);
}

.talent-branches {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.talent-branch {
    padding: 10px;
    border-radius: 14px;
}

.talent-branch::before {
    top: -12px;
    height: 12px;
}

.talent-branch__title {
    margin-bottom: 8px;
    font-size: 15px;
}

.talent-branch__title--weapons {
    color: #fde047;
}

.talent-list {
    gap: 7px;
}

.talent-node {
    grid-template-columns: 30px minmax(0, 1fr) auto;
    gap: 7px;
    min-height: 58px;
    padding: 7px 8px;
    border-radius: 11px;
}

.talent-node:not(:first-child)::before {
    top: -8px;
    left: 22px;
    height: 8px;
}

.talent-node__icon {
    font-size: 20px;
}

.talent-node__name {
    font-size: 13px;
    line-height: 1.15;
}

.talent-node__description {
    margin-top: 2px;
    font-size: 11px;
    line-height: 1.25;
}

.talent-node__state {
    min-width: 28px;
    font-size: 10px;
    text-align: right;
}

.talent-node--maxed {
    border-color: rgba(34, 197, 94, .62);
    background: rgba(34, 197, 94, .1);
}

.talent-actions {
    padding-top: 10px;
    font-size: 13px;
}

.button--secondary {
    margin-top: 14px;
    background: rgba(255, 255, 255, .09);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, .14);
}

/* Highscores */
.start-highscores {
    margin: 18px 0;
    padding: 12px 14px;
    border: 1px solid rgba(255,255,255,.1);
    border-radius: 14px;
    background: rgba(255,255,255,.035);
}

.start-highscores h2,
.highscore-heading {
    margin: 0 0 8px;
    font-size: 16px;
}

.highscore-list {
    display: grid;
    gap: 5px;
    max-height: 190px;
    margin: 0;
    padding-left: 30px;
    overflow: auto;
    color: #dce6f5;
}

.highscore-list li {
    padding: 5px 7px;
    border-radius: 8px;
    background: rgba(255,255,255,.045);
}

.highscore-entry {
    display: grid;
    grid-template-columns: minmax(70px, 1fr) auto auto;
    gap: 10px;
    align-items: center;
}

.highscore-entry__score {
    font-weight: 800;
    color: #fde68a;
}

.highscore-entry__wave {
    color: #94a3b8;
    font-size: 12px;
}

.highscore-list--start {
    max-height: 132px;
}

.highscore-form {
    margin: 18px 0;
}

.highscore-form label {
    display: block;
    margin-bottom: 6px;
    color: #dce6f5;
    font-size: 13px;
    font-weight: 700;
}

.highscore-form__row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}

.highscore-form input {
    min-width: 0;
    min-height: 48px;
    padding: 10px 12px;
    border: 1px solid rgba(255,255,255,.16);
    border-radius: 12px;
    outline: none;
    background: rgba(255,255,255,.07);
    color: #fff;
    font: inherit;
}

.highscore-form input:focus {
    border-color: rgba(56,189,248,.8);
}

.score-status {
    min-height: 20px;
    margin-top: 6px;
    color: #a5f3fc;
    font-size: 12px;
}

@media (max-width: 760px) {
    .talent-panel {
        padding: 14px;
    }

    .talent-tree {
        max-height: 70svh;
        overflow-x: auto;
    }

    .talent-branches {
        grid-template-columns: repeat(3, minmax(168px, 1fr));
        min-width: 524px;
    }

    .talent-header,
    .talent-actions {
        flex-direction: row;
        align-items: center;
    }

    .talent-node {
        min-height: 54px;
    }
}
