:root {
    --frontline-bg: #11140e;
    --frontline-panel: rgba(24, 28, 21, 0.82);
    --frontline-panel-solid: #202518;
    --frontline-border: rgba(221, 190, 124, 0.26);
    --frontline-gold: #d9b66e;
    --frontline-gold-bright: #f0d38b;
    --frontline-olive: #6e7b46;
    --frontline-red: #c9674a;
    --frontline-ink: #f4ead5;
    --frontline-muted: #b9ac90;
    --frontline-shadow: rgba(0, 0, 0, 0.45);
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--frontline-ink);
    font-family: "Outfit", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        linear-gradient(180deg, rgba(7, 9, 7, 0.3), rgba(7, 9, 7, 0.94)),
        url("/games/allied-frontline-defense/assets/thumbnail.webp") center / cover fixed,
        var(--frontline-bg);
    overflow-x: hidden;
}

button,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

.game-page {
    min-height: 100vh;
    padding: 18px;
    background:
        radial-gradient(circle at 12% 10%, rgba(217, 182, 110, 0.15), transparent 28%),
        radial-gradient(circle at 78% 8%, rgba(139, 156, 90, 0.13), transparent 30%),
        linear-gradient(180deg, rgba(13, 16, 11, 0.38), rgba(13, 16, 11, 0.96) 82%);
}

.frontline-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 1560px;
    margin: 0 auto 16px;
    padding: 10px 0;
}

.brand-link {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--frontline-ink);
    text-decoration: none;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.brand-mark {
    display: grid;
    width: 36px;
    height: 36px;
    place-items: center;
    border: 1px solid rgba(240, 211, 139, 0.42);
    border-radius: 8px;
    color: #13160f;
    background: linear-gradient(135deg, var(--frontline-gold-bright), #a9833c);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
}

.header-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    min-width: 42px;
    height: 42px;
    padding: 0 12px;
    border: 1px solid var(--frontline-border);
    border-radius: 8px;
    color: var(--frontline-ink);
    background: rgba(14, 17, 12, 0.72);
    transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.icon-btn:hover,
.icon-btn:focus-visible {
    border-color: rgba(240, 211, 139, 0.72);
    background: rgba(43, 49, 34, 0.9);
    transform: translateY(-1px);
    outline: none;
}

.command-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 18px;
    max-width: 1560px;
    margin: 0 auto;
    align-items: start;
}

.battle-stage,
.command-panel,
.field-manual {
    border: 1px solid var(--frontline-border);
    border-radius: 8px;
    background: var(--frontline-panel);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
    backdrop-filter: blur(16px);
}

.battle-stage {
    overflow: hidden;
}

.stage-heading {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 16px;
    padding: 18px 20px 16px;
    border-bottom: 1px solid var(--frontline-border);
    background: linear-gradient(90deg, rgba(35, 41, 27, 0.88), rgba(17, 20, 14, 0.62));
}

.kicker {
    margin: 0 0 4px;
    color: var(--frontline-gold-bright);
    font-size: 0.74rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.14em;
}

h1,
h2,
h3 {
    margin: 0;
    font-family: "Orbitron", "Outfit", sans-serif;
    letter-spacing: 0;
}

h1 {
    font-size: clamp(1.45rem, 2.7vw, 2.8rem);
    line-height: 1;
}

.title-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.beta-pill {
    display: inline-flex;
    align-items: center;
    height: 24px;
    padding: 0 9px;
    border: 1px solid rgba(245, 158, 11, 0.42);
    border-radius: 999px;
    background: rgba(245, 158, 11, 0.14);
    color: #fde68a;
    font-size: 0.68rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.status-strip {
    display: grid;
    grid-template-columns: repeat(6, minmax(62px, 1fr));
    min-width: min(760px, 100%);
    border: 1px solid rgba(240, 211, 139, 0.22);
    border-radius: 8px;
    overflow: hidden;
    background: rgba(11, 13, 9, 0.38);
}

.status-strip div {
    padding: 8px 12px;
    border-left: 1px solid rgba(240, 211, 139, 0.14);
}

.status-strip div:first-child {
    border-left: 0;
}

.status-strip span,
.intel-row span,
.result-stats span {
    display: block;
    color: var(--frontline-muted);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.status-strip strong,
.intel-row strong,
.result-stats strong {
    display: block;
    margin-top: 3px;
    color: var(--frontline-gold-bright);
    font-size: 1.05rem;
}

.canvas-frame {
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 2;
    background: #070907;
    overflow: hidden;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: manipulation;
}

.loading-panel {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: var(--frontline-gold-bright);
    background: rgba(9, 11, 8, 0.86);
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    pointer-events: none;
    transition: opacity 200ms ease, visibility 200ms ease;
}

.loading-panel.hidden {
    opacity: 0;
    visibility: hidden;
}

.command-panel {
    position: sticky;
    top: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
}

.panel-section {
    padding: 8px;
    border: 1px solid rgba(240, 211, 139, 0.16);
    border-radius: 8px;
    background: rgba(10, 12, 8, 0.28);
}

.panel-section h2 {
    margin-bottom: 8px;
    color: var(--frontline-ink);
    font-size: 0.86rem;
}

.panel-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.panel-title-row h2 {
    margin-bottom: 0;
}

.panel-title-row > span {
    color: var(--frontline-gold-bright);
    font-size: 0.76rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.command-stats {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 4px;
}

.command-stats span {
    min-height: 24px;
    padding: 4px 7px;
    border: 1px solid rgba(240, 211, 139, 0.12);
    border-radius: 6px;
    color: var(--frontline-muted);
    background: rgba(30, 36, 23, 0.46);
    font-size: 0.68rem;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
}

.command-stats strong,
.command-stats #speedValue {
    color: var(--frontline-gold-bright);
}

.setup-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.setup-columns h3 {
    margin: 0 0 6px;
    color: var(--frontline-muted);
    font-family: "Outfit", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.mission-list,
.map-list {
    display: grid;
    gap: 6px;
}

.mission-card,
.map-card {
    display: grid;
    gap: 2px;
    width: 100%;
    min-height: 38px;
    padding: 6px 7px;
    border: 1px solid rgba(240, 211, 139, 0.16);
    border-radius: 8px;
    color: var(--frontline-ink);
    text-align: left;
    background: rgba(30, 36, 23, 0.62);
    transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.mission-card:hover,
.mission-card:focus-visible,
.mission-card.active,
.map-card:hover,
.map-card:focus-visible,
.map-card.active {
    border-color: rgba(240, 211, 139, 0.7);
    background: rgba(75, 83, 49, 0.68);
    outline: none;
    transform: translateY(-1px);
}

.mission-card strong,
.map-card strong {
    display: block;
    color: #fff7e6;
    font-size: 0.78rem;
    line-height: 1.1;
}

.mission-card small,
.map-card small {
    display: block;
    color: var(--frontline-muted);
    font-size: 0.66rem;
    line-height: 1.2;
}

.map-list {
    grid-template-columns: 1fr 1fr;
}

.map-card {
    min-height: 38px;
    padding: 6px 7px;
    background:
        linear-gradient(135deg, rgba(240, 211, 139, 0.08), transparent 45%),
        rgba(30, 36, 23, 0.62);
}

.tower-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
}

.tower-card {
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 7px;
    align-items: center;
    width: 100%;
    min-height: 48px;
    padding: 6px;
    border: 1px solid rgba(240, 211, 139, 0.16);
    border-radius: 8px;
    color: var(--frontline-ink);
    text-align: left;
    background: rgba(30, 36, 23, 0.62);
    transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.tower-card:hover,
.tower-card:focus-visible,
.tower-card.active {
    border-color: rgba(240, 211, 139, 0.7);
    background: rgba(75, 83, 49, 0.68);
    outline: none;
    transform: translateY(-1px);
}

.tower-card strong {
    display: block;
    color: #fff7e6;
    font-size: 0.78rem;
    line-height: 1.12;
}

.tower-card small {
    display: block;
    margin-top: 2px;
    color: var(--frontline-muted);
    font-size: 0.65rem;
    line-height: 1.16;
}

.tower-icon {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 7px;
    overflow: hidden;
    background:
        radial-gradient(circle at 46% 38%, rgba(240, 211, 139, 0.22), transparent 42%),
        rgba(240, 211, 139, 0.12);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08), 0 8px 20px rgba(0, 0, 0, 0.24);
}

.tower-icon canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.action-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.primary-action,
.secondary-action {
    min-height: 34px;
    padding: 0 8px;
    border: 1px solid rgba(240, 211, 139, 0.25);
    border-radius: 8px;
    font-size: 0.84rem;
    font-weight: 800;
    transition: transform 160ms ease, filter 160ms ease, border-color 160ms ease, background 160ms ease;
}

.primary-action {
    color: #15120a;
    background: linear-gradient(135deg, var(--frontline-gold-bright), #b1843d);
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.24);
}

.secondary-action {
    color: var(--frontline-ink);
    background: rgba(35, 42, 26, 0.75);
}

.secondary-action:disabled {
    cursor: not-allowed;
    color: rgba(244, 234, 213, 0.34);
    border-color: rgba(240, 211, 139, 0.08);
    background: rgba(35, 42, 26, 0.28);
}

.primary-action:disabled {
    cursor: not-allowed;
    color: rgba(21, 18, 10, 0.54);
    filter: saturate(0.65);
    box-shadow: none;
}

.primary-action:not(:disabled):hover,
.secondary-action:not(:disabled):hover,
.primary-action:not(:disabled):focus-visible,
.secondary-action:not(:disabled):focus-visible {
    filter: brightness(1.08);
    transform: translateY(-1px);
    outline: none;
}

.wide {
    grid-column: 1 / -1;
}

.field-message {
    min-height: 0;
    margin: 8px 0 0;
    color: var(--frontline-muted);
    font-size: 0.78rem;
    line-height: 1.25;
}

.field-manual {
    max-width: 1560px;
    margin: 18px auto 0;
    padding: 22px;
}

.field-manual h2 {
    margin-bottom: 8px;
    font-size: 1.1rem;
}

.field-manual p {
    max-width: 900px;
    margin: 0;
    color: var(--frontline-muted);
    line-height: 1.6;
}

.manual-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin-top: 18px;
}

.manual-grid div {
    padding-top: 12px;
    border-top: 1px solid rgba(240, 211, 139, 0.18);
}

.manual-grid strong,
.manual-grid span {
    display: block;
}

.manual-grid span {
    margin-top: 5px;
    color: var(--frontline-muted);
    line-height: 1.45;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(0, 0, 0, 0.72);
}

.modal.show {
    display: flex;
}

.modal-content {
    width: min(520px, 100%);
    border: 1px solid rgba(240, 211, 139, 0.28);
    border-radius: 8px;
    color: var(--frontline-ink);
    background: #191e13;
    box-shadow: 0 28px 90px rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 18px;
    border-bottom: 1px solid rgba(240, 211, 139, 0.18);
}

.modal-header h3 {
    font-size: 1.1rem;
}

.modal-close {
    width: 36px;
    height: 36px;
    border: 1px solid rgba(240, 211, 139, 0.2);
    border-radius: 8px;
    color: var(--frontline-ink);
    background: rgba(255, 255, 255, 0.04);
}

.modal-body,
.result-stats,
.modal-actions,
.share-copy {
    padding: 18px;
}

.theme-options {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.theme-option {
    min-height: 96px;
    border: 1px solid rgba(240, 211, 139, 0.16);
    border-radius: 8px;
    color: var(--frontline-ink);
    background: rgba(255, 255, 255, 0.04);
}

.theme-preview {
    display: block;
    width: 40px;
    height: 28px;
    margin: 0 auto 8px;
    border-radius: 6px;
}

.modern-preview {
    background: linear-gradient(135deg, #00f2ff, #0f172a);
}

.classic-preview {
    background: linear-gradient(135deg, #d9b66e, #6e7b46);
}

.dark-preview {
    background: linear-gradient(135deg, #0a0a0a, #333);
}

.rainbow-preview {
    background: linear-gradient(135deg, #ec4899, #22c55e, #38bdf8);
}

.result-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.result-stats div {
    padding: 12px;
    border: 1px solid rgba(240, 211, 139, 0.16);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.04);
}

.modal-actions {
    display: flex;
    gap: 10px;
    padding-top: 0;
}

.modal-actions button {
    flex: 1;
}

.share-copy {
    margin: 0;
    color: var(--frontline-muted);
    line-height: 1.5;
}

@media (max-width: 1180px) {
    .command-layout {
        grid-template-columns: 1fr;
    }

    .command-panel {
        position: static;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .action-panel,
    .build-panel {
        align-self: start;
    }
}

@media (max-width: 840px) {
    .game-page {
        padding: 10px;
    }

    .stage-heading {
        display: block;
    }

    .status-strip {
        grid-template-columns: repeat(2, 1fr);
        margin-top: 14px;
        min-width: 0;
    }

    .command-panel {
        display: flex;
    }

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

    .manual-grid,
    .theme-options,
    .result-stats {
        grid-template-columns: 1fr;
    }

    .canvas-frame {
        aspect-ratio: 3 / 2;
    }
}

@media (max-width: 520px) {
    .frontline-header {
        align-items: start;
    }

    .brand-link span:last-child {
        display: none;
    }

    .header-actions {
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    h1 {
        font-size: 1.3rem;
    }

    .status-strip strong {
        font-size: 0.96rem;
    }

    .tower-card {
        grid-template-columns: 40px 1fr;
    }

    .tower-icon {
        width: 40px;
        height: 40px;
        background-size: auto 50px;
    }

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

    .tower-list {
        grid-template-columns: 1fr;
    }

    .map-list {
        grid-template-columns: 1fr;
    }
}
