* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, sans-serif;
    color: #172033;
    background: #f4f1ea;
}

button {
    min-height: 40px;
    padding: 0 14px;
    border: 1px solid #8a755c;
    border-radius: 6px;
    color: #ffffff;
    background: #5d6f45;
    cursor: pointer;
}

a {
    color: inherit;
}

.danger-button {
    border-color: #9a3c28;
    background: #9a3c28;
}

.start-shell {
    width: min(1040px, calc(100% - 32px));
    margin: 0 auto;
    padding: 36px 0;
}

.start-header {
    margin-bottom: 28px;
}

.start-header h1 {
    margin: 4px 0;
    font-size: 36px;
}

.start-header p {
    margin: 0;
}

.start-board {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
    align-items: stretch;
    gap: 28px;
    padding: 24px;
    border: 1px solid #d2c5b3;
    border-radius: 8px;
    background: #fffaf1;
}

.start-board-login {
    grid-template-columns: minmax(0, 1fr) minmax(260px, 340px);
}

.start-intro h2 {
    margin: 0 0 10px;
    font-size: 28px;
}

.start-intro p {
    max-width: 560px;
    margin: 0;
    color: #756653;
    line-height: 1.5;
}

.start-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 22px;
}

.primary-link,
.secondary-link {
    display: inline-grid;
    place-items: center;
    min-height: 42px;
    padding: 0 16px;
    border: 1px solid #8a755c;
    border-radius: 6px;
    font-weight: 700;
    text-decoration: none;
}

.primary-link {
    color: #ffffff;
    background: #5d6f45;
}

.secondary-link {
    color: #172033;
    background: #ffffff;
}

.auth-form {
    display: grid;
    gap: 12px;
    max-width: 420px;
    margin-top: 20px;
}

.auth-form label {
    display: grid;
    gap: 6px;
    color: #756653;
    font-size: 13px;
    font-weight: 700;
}

.auth-form input {
    min-height: 42px;
    width: 100%;
    padding: 0 12px;
    border: 1px solid #d2c5b3;
    border-radius: 6px;
    background: #ffffff;
    color: #172033;
    font: inherit;
}

.auth-form button {
    width: fit-content;
    min-width: 140px;
}

.auth-message {
    min-height: 20px;
    margin-top: 12px;
    color: #5d6f45;
    font-weight: 700;
}

.start-register {
    display: grid;
    align-items: center;
    padding: 20px;
    border: 1px solid #d2c5b3;
    border-radius: 8px;
    background: #ffffff;
}

.start-symbol {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    margin-bottom: 14px;
    border: 1px solid #d2c5b3;
    border-radius: 6px;
    background: #fffaf1;
    font-size: 26px;
}

.start-register h2 {
    margin: 0 0 8px;
    font-size: 22px;
}

.start-register p {
    margin: 0 0 18px;
    color: #756653;
    line-height: 1.45;
}

.game-shell {
    width: min(1040px, calc(100% - 32px));
    margin: 0 auto;
    padding: 0 0 32px;
}

.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-top: 24px;
    margin-bottom: 24px;
}

.game-header h1 {
    margin: 4px 0;
    font-size: 32px;
}

.game-header p {
    margin: 0;
}

.eyebrow {
    color: #7b4f34;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
}

.resource-bar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    padding: 8px;
    border: 1px solid #d2c5b3;
    border-radius: 8px;
    background: rgba(255, 250, 241, 0.96);
    box-shadow: 0 8px 18px rgba(23, 32, 51, 0.08);
    backdrop-filter: blur(8px);
}

.resource-bar div,
.production-panel,
.gps-panel,
.build-panel {
    border: 1px solid #d2c5b3;
    border-radius: 8px;
    background: #fffaf1;
}

.resource-bar div {
    display: grid;
    grid-template-columns: auto auto auto auto;
    align-items: baseline;
    gap: 4px;
    min-height: 36px;
    padding: 6px 10px;
}

.resource-bar .status-icon {
    font-size: 16px;
    line-height: 1;
}

.resource-bar .status-label {
    color: #756653;
    font-size: 12px;
}

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

.resource-bar small {
    color: #756653;
    font-size: 12px;
}

.resource-bar em {
    grid-column: 2 / -1;
    color: #9a3c28;
    font-size: 12px;
    font-style: normal;
    font-weight: 700;
}

.resource-bar .is-full {
    border-color: #c77b68;
    background: #fff4ef;
}

.recruitment-progress {
    margin-top: 10px;
    color: #756653;
    font-size: 13px;
}

.recruitment-progress p {
    margin: 6px 0 0;
}

.recruitment-progress-bar {
    height: 10px;
    overflow: hidden;
    border: 1px solid #d2c5b3;
    border-radius: 999px;
    background: #f7f1e7;
}

.recruitment-progress-bar span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: #5d6f45;
    transition: width 0.2s linear;
}

.population-growth-message {
    margin-top: 8px;
    color: #5d6f45;
    font-weight: 700;
}

.production-panel {
    margin-bottom: 24px;
    padding: 18px 20px;
}

.gps-panel {
    margin-bottom: 24px;
    padding: 18px 20px;
}

.section-heading {
    margin-bottom: 14px;
}

.section-heading h2 {
    margin: 0 0 8px;
}

.section-heading p {
    margin: 0;
    color: #756653;
}

.production-totals {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.production-total {
    min-height: 62px;
    padding: 12px;
    border: 1px solid #d2c5b3;
    border-radius: 6px;
    background: #ffffff;
}

.production-total span {
    display: block;
    margin-bottom: 6px;
    color: #756653;
    font-size: 13px;
}

.production-total strong {
    color: #5d6f45;
    font-size: 22px;
}

.production-details {
    display: grid;
    gap: 8px;
}

.gps-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
}

.manual-gps {
    display: grid;
    grid-template-columns: repeat(2, minmax(140px, 1fr)) repeat(2, auto);
    align-items: end;
    gap: 10px;
    margin-bottom: 12px;
    padding: 12px;
    border: 1px solid #e3d7c5;
    border-radius: 6px;
    background: #fffdf8;
}

.manual-gps label {
    display: grid;
    gap: 5px;
    color: #756653;
    font-size: 13px;
    font-weight: 700;
}

.manual-gps input {
    min-height: 40px;
    width: 100%;
    padding: 0 10px;
    border: 1px solid #cdbf9e;
    border-radius: 6px;
    color: #172033;
    background: #ffffff;
    font: inherit;
}

.gps-message {
    min-height: 18px;
    margin: 0 0 12px;
    color: #5d6f45;
    font-weight: 700;
}

.gps-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.map-view-switch {
    display: inline-flex;
    gap: 4px;
    margin-bottom: 12px;
    padding: 4px;
    border: 1px solid #d2c5b3;
    border-radius: 8px;
    background: #f7f1e7;
}

.map-view-switch button {
    border-color: transparent;
    color: #756653;
    background: transparent;
}

.map-view-switch button.is-active {
    color: #ffffff;
    border-color: #5d6f45;
    background: #5d6f45;
}

.map-view {
    display: none;
}

.map-view.is-active {
    display: block;
}

.map-view-stack {
    min-width: 0;
}

.real-world-map {
    width: 100%;
    height: 380px;
    margin-bottom: 12px;
    overflow: hidden;
    border: 1px solid #d2c5b3;
    border-radius: 8px;
    background: #e8e1d4;
}

.real-map-building-icon {
    display: grid;
    place-items: center;
    color: #172033;
    font-size: 17px;
}

.real-map-building-icon span {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border: 2px solid #ffffff;
    border-radius: 50%;
    background: #f7f1e7;
    box-shadow: 0 2px 8px rgba(23, 32, 51, 0.28);
}

.gps-stat {
    min-height: 58px;
    padding: 10px 12px;
    border: 1px solid #d2c5b3;
    border-radius: 6px;
    background: #ffffff;
}

.gps-stat span {
    display: block;
    margin-bottom: 6px;
    color: #756653;
    font-size: 13px;
}

.gps-stat strong {
    font-size: 18px;
}

.production-row {
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid #e3d7c5;
    border-radius: 6px;
    background: #fffdf8;
}

.production-main {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.production-main strong {
    display: flex;
    align-items: center;
    gap: 8px;
}

.production-main > span {
    color: #5d6f45;
    font-weight: 700;
}

.production-main small {
    color: #756653;
    font-size: 12px;
}

.worker-controls {
    display: grid;
    grid-template-columns: 32px 32px 32px;
    align-items: center;
    gap: 6px;
}

.worker-controls button {
    display: grid;
    place-items: center;
    width: 32px;
    min-height: 32px;
    padding: 0;
    font-size: 18px;
    font-weight: 700;
}

.worker-controls button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.worker-controls strong {
    text-align: center;
}

.build-panel {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 14px;
    padding: 18px 20px;
}

.build-panel h2 {
    margin: 0 0 8px;
}

.build-panel p {
    margin: 0;
}

.debug-panel {
    margin-top: 24px;
    padding: 14px 16px;
    border: 1px dashed #c9b89f;
    border-radius: 8px;
    background: #fffdf8;
}

.debug-panel summary {
    cursor: pointer;
    color: #756653;
    font-weight: 700;
}

.debug-panel p {
    margin: 10px 0;
    color: #756653;
}

.build-menu {
    display: grid;
    gap: 12px;
    min-width: min(100%, 460px);
}

.production-message {
    margin-top: 8px;
    color: #5d6f45;
    font-weight: 700;
}

.build-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(180px, 1fr));
    gap: 12px;
}

.build-options.is-hidden {
    display: none;
}

.build-option {
    position: relative;
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-height: 72px;
    padding: 12px;
    color: #172033;
    border-color: #cdbf9e;
    background: #ffffff;
    text-align: left;
}

.building-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.building-text strong {
    line-height: 1.15;
}

.building-symbol {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border: 1px solid #e3d7c5;
    border-radius: 6px;
    background: #fffaf1;
    font-size: 24px;
    line-height: 1;
}

.build-option.is-selected {
    color: #ffffff;
    border-color: #5d6f45;
    background: #5d6f45;
}

.build-option.is-selected .building-symbol {
    border-color: #eef3e7;
    background: rgba(255, 255, 255, 0.14);
}

.build-option::after {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 8px);
    z-index: 2;
    width: max-content;
    max-width: 240px;
    padding: 8px 10px;
    border-radius: 6px;
    color: #ffffff;
    background: #172033;
    box-shadow: 0 8px 18px rgba(23, 32, 51, 0.18);
    content: attr(data-tooltip);
    font-size: 12px;
    line-height: 1.3;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 4px);
    transition: opacity 120ms ease, transform 120ms ease;
    white-space: normal;
}

.build-option:hover::after,
.build-option:focus-visible::after {
    opacity: 1;
    transform: translate(-50%, 0);
}

.city-map-header {
    margin-bottom: 12px;
}

.city-map-header h2 {
    margin: 0 0 8px;
}

.city-map-header p {
    margin: 0;
    color: #756653;
}

.city-layout {
    display: grid;
    grid-template-columns: minmax(0, 720px) minmax(260px, 1fr);
    align-items: start;
    gap: 18px;
    margin-top: 18px;
}

.city-map-panel {
    min-width: 0;
}

.city-map-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
    color: #756653;
    font-size: 13px;
    font-weight: 700;
}

.city-map-toolbar input {
    width: min(260px, 100%);
}

.city-map-scroll {
    max-width: 100%;
    max-height: min(70vh, 760px);
    overflow: auto;
    padding: 4px;
    border: 1px solid #d2c5b3;
    border-radius: 8px;
    background: #f7f1e7;
}

.city-grid {
    display: grid;
    gap: 3px;
    width: max-content;
    min-width: min-content;
    --city-tile-size: 42px;
}

.city-empty {
    margin: 0;
    color: #756653;
}

.city-tile {
    width: var(--city-tile-size);
    aspect-ratio: 1;
    min-width: 0;
    border: 1px solid #cdbf9e;
    border-radius: 3px;
    background: #dce9bd;
    cursor: pointer;
    display: grid;
    place-items: center;
    color: #172033;
    font-size: 16px;
    font-weight: 700;
    position: relative;
}

.city-tile.is-selected {
    border-color: #172033;
    box-shadow: 0 0 0 2px rgba(23, 32, 51, 0.28);
}

.city-tile.has-building {
    border-color: #7b4f34;
    color: #ffffff;
    background: #7b4f34;
}

.city-tile.has-town-hall {
    border-color: #172033;
    box-shadow: inset 0 0 0 2px rgba(23, 32, 51, 0.24);
}

.city-tile.terrain-forest {
    background: #c9dfbd;
}

.city-tile.terrain-stone {
    background: #d5d2ca;
}

.city-tile.terrain-water {
    background: #c8dfeb;
}

.city-tile.terrain-grass {
    background: #e2edc4;
}

.city-tile.has-building {
    color: #ffffff;
    background: #7b4f34;
}

.tile-info-panel {
    min-height: 220px;
    padding: 16px;
    border: 1px solid #d2c5b3;
    border-radius: 8px;
    background: #fffdf8;
}

.tile-info-panel h3 {
    margin: 0 0 8px;
    font-size: 20px;
}

.tile-info-panel h4 {
    margin: 16px 0 6px;
    font-size: 15px;
}

.tile-info-panel p {
    margin: 0 0 12px;
    color: #756653;
}

.info-list {
    display: grid;
    grid-template-columns: minmax(82px, auto) minmax(0, 1fr);
    gap: 8px 12px;
    margin-bottom: 14px;
}

.info-list span {
    color: #756653;
    font-size: 13px;
}

.info-list strong {
    min-width: 0;
    font-size: 13px;
}

.tile-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.tile-actions button:disabled,
.tile-info-panel button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.worker-panel {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e3d7c5;
}

.town-hall-panel {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e3d7c5;
}

.town-hall-panel button {
    margin-top: 8px;
}

.tile-symbol {
    line-height: 1;
}

.tile-level {
    position: absolute;
    right: 2px;
    bottom: 1px;
    min-width: 13px;
    height: 13px;
    border-radius: 7px;
    color: #172033;
    background: #fffaf1;
    font-size: 9px;
    line-height: 13px;
    text-align: center;
}

@media (max-width: 680px) {
    .game-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .start-board {
        grid-template-columns: 1fr;
        padding: 18px;
    }

    .auth-form button,
    .primary-link,
    .secondary-link {
        width: 100%;
    }

    .resource-bar {
        top: 0;
        gap: 6px;
    }

    .resource-bar div {
        flex: 1 1 calc(50% - 6px);
        min-width: 140px;
    }

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

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

    .manual-gps {
        grid-template-columns: 1fr;
    }

    .real-world-map {
        height: 320px;
    }

    .worker-controls {
        width: 100%;
        justify-content: start;
    }

    .build-panel {
        flex-direction: column;
    }

    .build-options {
        grid-template-columns: 1fr;
        width: 100%;
    }

    .build-menu {
        width: 100%;
    }

    .build-option::after {
        left: 12px;
        right: 12px;
        width: auto;
        max-width: none;
        transform: translateY(4px);
    }

    .build-option:hover::after,
    .build-option:focus-visible::after {
        transform: translateY(0);
    }

    .city-grid {
        gap: 2px;
    }

    .city-layout {
        grid-template-columns: 1fr;
    }

    .city-tile.has-building {
        font-size: 12px;
    }

    .tile-level {
        right: 1px;
        bottom: 1px;
        min-width: 11px;
        height: 11px;
        font-size: 8px;
        line-height: 11px;
    }
}
