:root {
    --bg: #eef2f0;
    --panel: #fffdf7;
    --panel-2: #f6f0df;
    --ink: #18231f;
    --muted: #65736c;
    --line: #d8d1bd;
    --forest: #3f7a55;
    --plain: #b5c96f;
    --hill: #9d8064;
    --water: #5f9bb4;
    --ruin: #7a7380;
    --primary: #32695a;
    --primary-dark: #1f453a;
    --gold: #c58d2b;
    --danger: #b34b35;
    --good: #28744f;
    --shadow: 0 18px 50px rgba(24, 35, 31, 0.13);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    background:
        linear-gradient(120deg, rgba(50, 105, 90, 0.12), transparent 46%),
        linear-gradient(180deg, #fbfaf5 0%, var(--bg) 100%);
}

button {
    min-height: 44px;
    border: 0;
    border-radius: 8px;
    padding: 0 14px;
    color: #fff;
    background: var(--primary);
    box-shadow: 0 4px 0 var(--primary-dark);
    cursor: pointer;
    font: inherit;
    font-weight: 800;
    transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

button:hover,
button:focus-visible {
    background: #3b7d6b;
    outline: 3px solid rgba(50, 105, 90, 0.22);
    outline-offset: 2px;
}

button:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 var(--primary-dark);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.48;
}

h1,
h2,
p {
    margin: 0;
}

.game-shell {
    width: min(1480px, calc(100% - 28px));
    margin: 0 auto;
    padding: 18px 0 26px;
}

.game-header,
.resource-bar,
.panel,
.board-area {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 253, 247, 0.95);
    box-shadow: var(--shadow);
}

.game-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 16px;
    padding: 14px;
}

.title-block {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 14px;
}

.game-mark {
    display: grid;
    width: 64px;
    height: 64px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 8px;
    color: #2b1e08;
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.28), transparent),
        #e2ad43;
    box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.1);
    font-size: 20px;
    font-weight: 900;
}

.eyebrow {
    color: var(--muted);
    font-size: 13px;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

h1 {
    margin-top: 3px;
    font-size: clamp(28px, 4vw, 48px);
    line-height: 1;
}

.turn-panel {
    display: grid;
    gap: 4px;
    min-width: 132px;
    border: 1px solid #e4c67e;
    border-radius: 8px;
    padding: 10px 12px;
    background: #fff4d7;
    text-align: center;
}

.turn-panel span {
    color: #6c5520;
    font-size: 13px;
    font-weight: 900;
    text-transform: uppercase;
}

.turn-panel strong {
    font-size: 19px;
}

.ghost-button {
    color: var(--primary-dark);
    background: #dfebe4;
    box-shadow: 0 4px 0 #bdd2c8;
}

.resource-bar {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 1px;
    overflow: hidden;
    margin-top: 12px;
    background: var(--line);
}

.resource-bar article {
    display: grid;
    gap: 3px;
    min-height: 70px;
    place-items: center;
    background: var(--panel);
}

.resource-bar span,
.status-strip span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
}

.resource-bar strong {
    font-size: 25px;
}

.main-layout {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr) 320px;
    gap: 14px;
    margin-top: 14px;
}

.main-layout > *,
.board-area {
    min-width: 0;
}

.left-panel,
.right-panel {
    display: grid;
    align-content: start;
    gap: 14px;
}

.panel {
    padding: 14px;
}

.panel h2 {
    margin-bottom: 12px;
    font-size: 18px;
}

.build-list,
.tech-list {
    display: grid;
    gap: 10px;
}

.build-card,
.tech-card {
    display: grid;
    gap: 7px;
    width: 100%;
    min-height: 98px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    color: var(--ink);
    background: #fbf8ed;
    box-shadow: none;
    text-align: left;
}

.build-card:hover,
.build-card:focus-visible,
.build-card.is-selected,
.tech-card:hover,
.tech-card:focus-visible {
    color: var(--ink);
    background: #fff2c8;
    outline: 3px solid rgba(197, 141, 43, 0.22);
}

.card-top {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-weight: 900;
}

.card-top span:first-child {
    font-size: 16px;
}

.card-tag {
    color: #5f4712;
    font-size: 12px;
    text-transform: uppercase;
}

.card-desc,
.card-cost {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    line-height: 1.25;
}

.board-area {
    display: grid;
    gap: 12px;
    padding: 14px;
}

.status-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
}

.status-strip div {
    display: grid;
    gap: 4px;
    min-height: 58px;
    border: 1px solid #e2d8bd;
    border-radius: 8px;
    place-items: center;
    background: #fbf6e8;
}

.status-strip strong {
    max-width: 100%;
    overflow: hidden;
    font-size: 19px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(8, minmax(48px, 1fr));
    gap: 6px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    aspect-ratio: 1;
    min-height: 520px;
    border: 1px solid #c5baa2;
    border-radius: 8px;
    padding: 8px;
    background:
        linear-gradient(45deg, rgba(255, 255, 255, 0.28), transparent),
        #d6c7a7;
}

.tile {
    position: relative;
    display: grid;
    min-width: 0;
    min-height: 0;
    grid-template-rows: 1fr auto;
    border: 2px solid rgba(255, 255, 255, 0.38);
    border-radius: 8px;
    padding: 5px;
    color: #11231d;
    background: var(--plain);
    box-shadow: inset 0 -9px 0 rgba(0, 0, 0, 0.08);
}

.tile[data-terrain="forest"] {
    background: var(--forest);
    color: #f6fff9;
}

.tile[data-terrain="hill"] {
    background: var(--hill);
    color: #fff9ef;
}

.tile[data-terrain="water"] {
    background: var(--water);
    color: #f2fbff;
}

.tile[data-terrain="ruin"] {
    background: var(--ruin);
    color: #fff9ff;
}

.tile.is-selected {
    border-color: #ffe08a;
    outline: 3px solid rgba(255, 224, 138, 0.48);
}

.tile.is-invalid {
    filter: grayscale(0.55);
}

.terrain-pattern {
    position: absolute;
    inset: 7px 7px auto auto;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.45);
    box-shadow:
        -18px 15px 0 rgba(255, 255, 255, 0.17),
        -6px 32px 0 rgba(0, 0, 0, 0.09);
}

.building {
    z-index: 1;
    display: grid;
    width: min(52px, 72%);
    aspect-ratio: 1;
    place-self: center;
    place-items: center;
    border: 2px solid rgba(255, 255, 255, 0.76);
    border-radius: 8px;
    color: #1d211e;
    background: #fff8e6;
    box-shadow: 0 7px 16px rgba(0, 0, 0, 0.16);
    font-size: clamp(13px, 2.2vw, 20px);
    font-weight: 900;
}

.building.level-2 {
    background: #f5d87a;
}

.building.level-3 {
    color: #fff8e6;
    background: #5c4a2d;
}

.tile-footer {
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 3px;
    font-size: 11px;
    font-weight: 900;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.25);
}

.command-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

.command-row button {
    min-width: 0;
    white-space: normal;
}

.tile-details {
    display: grid;
    gap: 10px;
}

.detail-name {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 20px;
    font-weight: 900;
}

.detail-name span {
    color: var(--muted);
    font-size: 13px;
    text-transform: uppercase;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.detail-grid div {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px;
    background: #fbf8ed;
}

.detail-grid span,
.objective-list small {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
}

.detail-grid strong {
    display: block;
    margin-top: 4px;
}

.objective-list {
    display: grid;
    gap: 9px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.objective-list li {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px;
    background: #fbf8ed;
}

.objective-list li.is-done {
    border-color: #b5d7c5;
    background: #edf8f1;
}

.objective-list strong {
    display: block;
    margin-bottom: 4px;
}

.log-list {
    display: grid;
    max-height: 270px;
    overflow: auto;
    gap: 8px;
    padding-right: 4px;
}

.log-item {
    border-left: 4px solid var(--gold);
    border-radius: 6px;
    padding: 8px 9px;
    background: #fbf8ed;
    color: #4a473e;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.32;
}

.log-item.danger {
    border-left-color: var(--danger);
}

.log-item.good {
    border-left-color: var(--good);
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 22px;
    z-index: 10;
    width: min(520px, calc(100% - 30px));
    border: 1px solid #c8a552;
    border-radius: 8px;
    padding: 13px 16px;
    color: #2b210d;
    background: #fff3c9;
    box-shadow: var(--shadow);
    font-weight: 900;
    transform: translateX(-50%);
}

@media (max-width: 1320px) {
    .main-layout {
        grid-template-columns: 260px minmax(0, 1fr);
    }

    .right-panel {
        grid-column: 1 / -1;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 840px) {
    .game-shell {
        width: min(100% - 16px, 1480px);
        padding-top: 8px;
    }

    .game-header,
    .main-layout,
    .right-panel {
        grid-template-columns: 1fr;
    }

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

    .status-strip {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .game-board {
        min-height: auto;
        gap: 4px;
        padding: 5px;
    }

    .tile {
        padding: 3px;
        border-radius: 6px;
    }

    .terrain-pattern {
        width: 15px;
        height: 15px;
    }

    .tile-footer {
        font-size: 9px;
    }

    .command-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 500px) {
    .resource-bar {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .game-board {
        grid-template-columns: repeat(8, minmax(33px, 1fr));
    }

    .building {
        width: min(34px, 82%);
        border-radius: 6px;
        font-size: 11px;
    }
}
