.train-defense-page {
    min-height: 100vh;
    margin: 0;
    color: #e7dcc7;
    background: #171b1d;
    font-family: "Segoe UI", sans-serif;
}

.train-defense-shell {
    width: min(100% - 28px, 1440px);
    margin: 0 auto;
    padding: 18px 0 28px;
}

.command-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 330px;
    gap: 14px;
    align-items: start;
}

.train-defense-game {
    position: relative;
    overflow: hidden;
    min-width: 0;
    border: 1px solid #58615d;
    border-radius: 8px;
    background: #b98952;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
}

#train-defense-canvas {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    height: auto;
    touch-action: manipulation;
}

.command-panel {
    display: grid;
    gap: 10px;
    padding: 16px;
    border: 1px solid #424a47;
    border-radius: 8px;
    background: #242a2c;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.22);
}

.command-header,
.route-title-row,
.route-meta,
.panel-heading,
.route-meta,
.round-tools {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.command-header h1 {
    margin: 3px 0 0;
    color: #fff2d2;
    font-size: 1.35rem;
    line-height: 1.1;
    letter-spacing: 0;
}

.eyebrow,
.log-label {
    color: #9aaf9e;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.08em;
}

.status-chip {
    padding: 5px 8px;
    border: 1px solid #677e6f;
    border-radius: 6px;
    color: #dbe8d6;
    background: #35453d;
    font-size: 0.72rem;
    font-weight: 800;
}

.route-summary,
.resource-card,
.intel-panel,
.build-section,
.command-log {
    border: 1px solid #3d4644;
    border-radius: 6px;
    background: #1d2325;
}

.route-summary {
    padding: 11px 12px 10px;
}

.route-title-row strong {
    color: #fff2d2;
    font-size: 0.95rem;
}

.route-title-row span,
.route-meta,
.selection-readout {
    color: #aab5ae;
    font-size: 0.74rem;
}

.route-progress {
    height: 7px;
    margin: 10px 0 7px;
    overflow: hidden;
    border-radius: 4px;
    background: #111617;
}

.route-progress span {
    display: block;
    width: 0;
    height: 100%;
    background: #d5a94d;
    transition: width 120ms linear;
}

.route-meta b,
.selection-readout b {
    color: #f0d48d;
}

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

.resource-card {
    position: relative;
    min-width: 0;
    padding: 10px 11px;
}

.resource-card span,
.resource-card small,
.selected-detail span {
    display: block;
    color: #9da9a2;
    font-size: 0.72rem;
}

.resource-card strong {
    display: block;
    margin-top: 3px;
    color: #fff2d2;
    font-size: 1.15rem;
}

.resource-card small {
    margin-top: 2px;
    font-size: 0.68rem;
}

.hp-card strong {
    color: #ef9b78;
}

.scrap-card strong {
    color: #ebc86c;
}

.resource-card i {
    display: block;
    height: 4px;
    margin-top: 7px;
    overflow: hidden;
    border-radius: 2px;
    background: #d16046;
    transform-origin: left;
    transition: transform 150ms ease;
}

.resource-card i::after {
    display: block;
    width: 100%;
    height: 100%;
    content: "";
    background: #6dbe83;
    transform-origin: left;
    transform: scaleX(1);
    transition: transform 150ms ease;
}

.intel-panel,
.build-section,
.command-log {
    padding: 11px 12px;
}

.panel-heading > span:first-child {
    color: #d8c79e;
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.04em;
}

.intel-panel .panel-heading strong {
    color: #f0d48d;
    font-size: 0.9rem;
}

.intel-panel p {
    min-height: 2.65em;
    margin: 8px 0 0;
    color: #b9c6bf;
    font-size: 0.78rem;
    line-height: 1.4;
}

.building-tools {
    display: grid;
    gap: 6px;
    margin-top: 9px;
}

.build-button,
.train-button {
    min-height: 40px;
    border: 1px solid #59645e;
    border-radius: 6px;
    color: #e9dfcb;
    background: #30383a;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.build-button {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 7px 9px;
    text-align: left;
}

.build-button:hover,
.train-button:hover {
    border-color: #d4b45e;
    background: #3b4545;
}

.build-button.selected {
    border-color: #d4b45e;
    background: #46574d;
    box-shadow: inset 3px 0 0 #e4bd58;
}

.building-icon {
    display: inline-grid;
    flex: 0 0 30px;
    place-items: center;
    width: 30px;
    height: 30px;
    border: 1px solid #6f7b72;
    border-radius: 5px;
    color: #fff3c7;
    font-size: 1.15rem;
    line-height: 1;
}

.cannon-icon {
    background: #35443f;
}

.signal-icon {
    color: #88d4dc;
    background: #24474c;
}

.repair-icon {
    color: #f0a276;
    background: #56372e;
}

.building-copy {
    display: grid;
    min-width: 0;
    gap: 2px;
}

.building-copy strong {
    color: #fff2d2;
    font-size: 0.85rem;
}

.building-copy small {
    overflow: hidden;
    color: #aebbb2;
    font-size: 0.68rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.selected-detail {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin-top: 9px;
    padding-top: 9px;
    border-top: 1px solid #394241;
}

.selected-detail strong {
    display: block;
    margin-top: 2px;
    overflow: hidden;
    color: #f0d48d;
    font-size: 0.72rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.command-log {
    min-height: 66px;
}

.command-log p {
    margin: 5px 0 0;
    color: #d8dfd5;
    font-size: 0.78rem;
    line-height: 1.42;
}

.round-tools {
    justify-content: stretch;
}

.train-button {
    flex: 1;
    padding: 8px 9px;
    text-align: center;
    text-decoration: none;
    font-size: 0.76rem;
}

.train-button.primary {
    border-color: #c75f47;
    color: #fff7df;
    background: #923f32;
}

.train-button.danger {
    border-color: #815245;
    color: #fff7df;
    background: #58352e;
}

.train-defense-overlay {
    position: absolute;
    left: 24px;
    bottom: 24px;
    width: min(42%, 360px);
    padding: 16px;
    border: 1px solid rgba(255, 239, 194, 0.5);
    border-radius: 7px;
    color: #fff6df;
    background: rgba(31, 36, 36, 0.92);
    box-shadow: 0 16px 44px rgba(0, 0, 0, 0.38);
}

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

.overlay-kicker {
    color: #d5a94d;
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 0.1em;
}

.train-defense-overlay h1 {
    margin: 5px 0 0;
    color: #fff2d2;
    font-size: 1.75rem;
    line-height: 1.1;
}

.train-defense-overlay p {
    margin: 9px 0 13px;
    color: #c9d1c7;
    font-size: 0.82rem;
    line-height: 1.45;
}

@media (max-width: 980px) {
    .command-layout {
        grid-template-columns: minmax(0, 1fr) 300px;
    }

    .command-panel {
        padding: 12px;
    }
}

@media (max-width: 720px) {
    .train-defense-page {
        min-height: 100svh;
    }

    .train-defense-shell {
        width: 100%;
        padding: 0 6px 10px;
        box-sizing: border-box;
    }

    .command-layout {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .train-defense-game {
        width: 100%;
        border-radius: 0;
    }

    #train-defense-canvas {
        aspect-ratio: auto;
        height: 54svh;
        min-height: 330px;
        max-height: 520px;
    }

    .command-panel {
        width: 100%;
        box-sizing: border-box;
        border-radius: 6px;
    }

    .building-tools {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .build-button {
        gap: 5px;
        padding: 6px;
    }

    .building-icon {
        flex-basis: 26px;
        width: 26px;
        height: 26px;
        font-size: 0.95rem;
    }

    .building-copy strong {
        font-size: 0.72rem;
    }

    .building-copy small {
        font-size: 0.58rem;
    }

    .train-defense-overlay {
        left: 8px;
        right: 8px;
        bottom: 8px;
        width: auto;
        padding: 10px;
    }

    .train-defense-overlay h1 {
        font-size: 1.2rem;
    }

    .train-defense-overlay p {
        margin: 5px 0 8px;
        font-size: 0.74rem;
    }
}
