:root {
    font-family: Arial, Helvetica, sans-serif;
    color: #000;
    background: #008080;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    padding:
        max(10px, env(safe-area-inset-top))
        max(10px, env(safe-area-inset-right))
        max(10px, env(safe-area-inset-bottom))
        max(10px, env(safe-area-inset-left));
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #007c7c, #005f5f);
}

body.modal-open {
    overflow: hidden;
}

button,
input {
    font: inherit;
}

button,
input,
.panel,
.window {
    border-radius: 0;
}

button {
    min-height: 42px;
    padding: 7px 12px;
    border-top: 2px solid #fff;
    border-left: 2px solid #fff;
    border-right: 2px solid #404040;
    border-bottom: 2px solid #404040;
    background: #c0c0c0;
    color: #000;
    cursor: pointer;
}

button:active:not(:disabled) {
    border-top-color: #404040;
    border-left-color: #404040;
    border-right-color: #fff;
    border-bottom-color: #fff;
}

button:disabled {
    color: #777;
    cursor: not-allowed;
}

button:focus-visible,
input:focus-visible {
    outline: 3px solid #000080;
    outline-offset: 2px;
}

[hidden] {
    display: none !important;
}

.app-shell {
    width: min(100%, 1060px);
}

.window {
    border-top: 2px solid #fff;
    border-left: 2px solid #fff;
    border-right: 2px solid #404040;
    border-bottom: 2px solid #404040;
    background: #c0c0c0;
    box-shadow: 2px 2px 0 #000;
}

.start-window,
.end-window {
    width: min(100%, 540px);
    margin-inline: auto;
}

.title-bar {
    min-height: 34px;
    display: flex;
    align-items: center;
    padding: 4px 8px;
    color: #fff;
    background: linear-gradient(90deg, #000080, #1084d0);
}

.title-bar h1,
.title-bar h2 {
    margin: 0;
    font-size: 17px;
    line-height: 1.2;
}

.modal-title-bar {
    justify-content: space-between;
    gap: 12px;
}

.window-content {
    padding: 10px;
}

.panel {
    margin-bottom: 12px;
    padding: 10px;
    border-top: 2px solid #808080;
    border-left: 2px solid #808080;
    border-right: 2px solid #fff;
    border-bottom: 2px solid #fff;
    background: #d4d0c8;
}

fieldset.panel {
    min-width: 0;
}

legend {
    padding: 0 5px;
    font-weight: 700;
}

.field-label {
    display: block;
    margin-bottom: 6px;
    font-weight: 700;
}

input[type="text"],
.number-input {
    width: 100%;
    min-height: 44px;
    padding: 7px 9px;
    border-top: 2px solid #404040;
    border-left: 2px solid #404040;
    border-right: 2px solid #fff;
    border-bottom: 2px solid #fff;
    background: #fff;
    color: #000;
}

.number-input {
    min-height: 48px;
    font-size: 20px;
}

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

.length-option {
    position: relative;
    display: block;
}

.length-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.length-option span {
    min-height: 48px;
    display: grid;
    place-items: center;
    padding: 8px;
    border-top: 2px solid #fff;
    border-left: 2px solid #fff;
    border-right: 2px solid #404040;
    border-bottom: 2px solid #404040;
    background: #c0c0c0;
    text-align: center;
    cursor: pointer;
    user-select: none;
}

.length-option input:checked + span {
    border-top-color: #404040;
    border-left-color: #404040;
    border-right-color: #fff;
    border-bottom-color: #fff;
    background: #a8a8a8;
    font-weight: 700;
}

.length-option input:focus-visible + span {
    outline: 3px solid #000080;
    outline-offset: 2px;
}

.fixed-starting-area {
    margin: 0;
    padding: 9px;
    border-top: 2px solid #404040;
    border-left: 2px solid #404040;
    border-right: 2px solid #fff;
    border-bottom: 2px solid #fff;
    background: #fff;
    font-weight: 700;
}

.button-row {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.full-width-button {
    width: 100%;
    margin-top: 10px;
}

.form-error {
    margin: 0 0 12px;
    padding: 8px;
    border: 1px solid #800000;
    background: #fff;
    color: #a00000;
    font-weight: 700;
}

.information-note {
    margin: 0 0 12px;
    padding: 8px;
    border-top: 2px solid #808080;
    border-left: 2px solid #808080;
    border-right: 2px solid #fff;
    border-bottom: 2px solid #fff;
    background: #d4d0c8;
    font-size: 14px;
}

.game-content {
    display: grid;
    gap: 8px;
}

.top-layout {
    display: grid;
    grid-template-columns: minmax(360px, 0.95fr) minmax(360px, 1.05fr);
    gap: 8px;
}

.digital-panel,
.travel-panel,
.event-log,
.trade-panel,
.combat-log {
    border-top: 2px solid #404040;
    border-left: 2px solid #404040;
    border-right: 2px solid #fff;
    border-bottom: 2px solid #fff;
}

.digital-panel {
    padding: 8px;
    background: #000;
    color: #fff;
    font-family: "Courier New", Courier, monospace;
    font-size: clamp(16px, 2vw, 22px);
    font-weight: 700;
}

.digital-heading {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.digital-heading p,
.money-stats p,
.end-summary-panel p {
    margin: 0;
}

.money-stats {
    display: grid;
    gap: 2px;
    margin-top: 7px;
}

.digital-yellow { color: #ffff00; }
.digital-green { color: #00ff48; }
.digital-red { color: #ff2020; }
.digital-white { color: #fff; }

.weapon-rack {
    margin-top: 8px;
    padding: 7px;
    border: 1px solid #fff;
    color: #ffff00;
    text-align: center;
    text-transform: uppercase;
}

.health-row {
    display: grid;
    grid-template-columns: auto minmax(80px, 1fr) auto;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.health-bar,
.boss-health-bar {
    height: 22px;
    padding: 2px;
    border: 2px solid #c0c0c0;
    background: #202020;
}

.health-fill {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #001cff, #00e1ff, #ff0000);
}

.travel-panel {
    padding: 8px;
    background: #d4d0c8;
}

.travel-panel h2 {
    margin: 0 0 5px;
    font-size: 21px;
}

.location-heading {
    margin: 0 0 7px;
    font-weight: 700;
}

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

.destination-grid button {
    min-height: 39px;
}

.destination-grid button.current-location-button {
    font-weight: 700;
    color: #777;
}

.event-log {
    min-height: 105px;
    max-height: 150px;
    overflow-y: auto;
    padding: 7px;
    background: #fff;
}

.event-log p,
.combat-log p {
    margin: 0 0 5px;
}

.event-log p:last-child,
.combat-log p:last-child {
    margin-bottom: 0;
    font-weight: 700;
}

.trading-layout {
    display: grid;
    grid-template-columns: minmax(280px, 1fr) 130px minmax(280px, 1fr);
    gap: 8px;
    min-height: 370px;
}

.trade-panel {
    min-width: 0;
    overflow: hidden;
    background: #fff;
}

.trade-panel-heading {
    min-height: 38px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 8px;
    background: #d4d0c8;
}

.trade-panel-heading h2 {
    margin: 0;
    font-size: 17px;
}

.table-heading,
.history-table-heading {
    min-height: 30px;
    align-items: center;
    padding: 5px 7px;
    border-top: 1px solid #808080;
    border-bottom: 1px solid #808080;
    background: #d4d0c8;
    font-weight: 700;
}

.market-table-grid,
.market-row {
    display: grid;
    grid-template-columns: 26px minmax(90px, 1fr) minmax(80px, auto);
    gap: 5px;
}

.inventory-table-grid,
.inventory-row {
    display: grid;
    grid-template-columns: minmax(90px, 1fr) 60px 90px;
    gap: 5px;
}

.table-heading span:last-child,
.market-row .price-cell,
.inventory-row span:nth-child(n + 2) {
    text-align: right;
}

.trade-list {
    max-height: 330px;
    overflow-y: auto;
}

.market-row,
.inventory-row {
    width: 100%;
    min-height: 32px;
    align-items: center;
    padding: 5px 7px;
    border: 0;
    background: #fff;
    color: #000;
    text-align: left;
    cursor: pointer;
}

.market-row:hover,
.market-row.selected,
.inventory-row:hover,
.inventory-row.selected {
    background: #000080;
    color: #fff;
}

.trend-arrow {
    font-size: 20px;
    font-weight: 900;
    line-height: 1;
    text-align: center;
}

.trend-up { color: #00a828; }
.trend-down { color: #ff1818; }
.trend-neutral { color: #2020d0; }

.market-row:hover .trend-arrow,
.market-row.selected .trend-arrow {
    color: #fff;
}

.empty-list-message {
    margin: 0;
    padding: 14px 8px;
    color: #555;
}

.action-column {
    display: grid;
    grid-auto-rows: minmax(40px, auto);
    align-content: start;
    gap: 6px;
}

.selected-drug-label {
    min-height: 40px;
    margin: 0;
    padding: 7px;
    display: grid;
    place-items: center;
    border-top: 2px solid #404040;
    border-left: 2px solid #404040;
    border-right: 2px solid #fff;
    border-bottom: 2px solid #fff;
    background: #fff;
    text-align: center;
    font-weight: 700;
}

.modal-overlay {
    position: fixed;
    z-index: 9999;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding:
        max(12px, env(safe-area-inset-top))
        max(12px, env(safe-area-inset-right))
        max(12px, env(safe-area-inset-bottom))
        max(12px, env(safe-area-inset-left));
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.68);
}

.modal-overlay[hidden] {
    display: none !important;
}

.transaction-window,
.finances-window,
.hospital-window,
.history-window {
    width: min(100%, 470px);
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
    margin: auto;
    overflow-y: auto;
}

.store-window {
    width: min(100%, 680px);
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
    margin: auto;
    overflow-y: auto;
}

.combat-window {
    width: min(100%, 620px);
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
    margin: auto;
    overflow-y: auto;
}

.title-close-button {
    width: 28px;
    min-width: 28px;
    height: 26px;
    min-height: 26px;
    display: grid;
    place-items: center;
    padding: 0;
    font-size: 21px;
    font-weight: 700;
    line-height: 1;
}

.transaction-summary p,
.hospital-summary p {
    margin: 5px 0;
}

.transaction-drug-name {
    margin-top: 0 !important;
    font-size: 21px;
}

.maximum-quantity {
    margin: 8px 0 0;
}

.quick-quantity-grid,
.finance-action-grid,
.combat-action-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    margin-top: 10px;
}

.quick-quantity-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.quick-quantity-grid button {
    min-width: 0;
}

.finances-summary,
.store-summary,
.score-breakdown {
    display: grid;
    gap: 7px;
}

.finance-balance-row,
.store-summary > div,
.score-breakdown > div {
    display: flex;
    justify-content: space-between;
    gap: 20px;
}

.finance-balance-row {
    font-size: 18px;
}

.modal-section-title {
    margin: 0 0 10px;
    font-size: 19px;
}

.store-weapon-list {
    display: grid;
    gap: 8px;
}

.store-weapon-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    padding: 8px;
    border: 1px solid #808080;
    background: #fff;
}

.store-weapon-card h4,
.store-weapon-card p {
    margin: 0;
}

.store-weapon-card p {
    margin-top: 3px;
    font-size: 14px;
}

.store-weapon-card.current-weapon {
    outline: 3px solid #000080;
}

.store-ammo-description {
    margin-top: 0;
}

.history-drug-name {
    margin: 0 0 8px;
    font-size: 20px;
    font-weight: 700;
}

.history-grid {
    display: grid;
    grid-template-columns: 55px minmax(120px, 1fr) 100px;
    gap: 8px;
}

.history-grid span:last-child {
    text-align: right;
}

.history-list {
    max-height: 340px;
    overflow-y: auto;
}

.history-row {
    padding: 6px 7px;
    border-bottom: 1px solid #ddd;
    background: #fff;
}

.combat-overlay {
    background: rgba(0, 0, 0, 0.82);
}

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

.combat-status-grid > div {
    display: grid;
    gap: 4px;
    text-align: center;
}

.hardass-heading {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 7px;
}

.boss-health-fill {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #cc0000, #ff8c00);
}

.combat-log {
    min-height: 170px;
    max-height: 250px;
    overflow-y: auto;
    padding: 8px;
    background: #fff;
}

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

.end-summary-panel {
    margin-bottom: 12px;
}

.end-summary-panel p + p {
    margin-top: 8px;
}

@media (max-width: 820px) {
    body {
        place-items: start center;
    }

    .top-layout,
    .trading-layout {
        grid-template-columns: 1fr;
    }

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

    .selected-drug-label {
        grid-column: 1 / -1;
    }

    .trade-list {
        max-height: 290px;
    }
}

@media (max-width: 540px) {
    body {
        padding:
            max(5px, env(safe-area-inset-top))
            max(5px, env(safe-area-inset-right))
            max(5px, env(safe-area-inset-bottom))
            max(5px, env(safe-area-inset-left));
    }

    .window-content {
        padding: 6px;
    }

    .digital-heading {
        display: grid;
        gap: 3px;
    }

    .digital-panel {
        font-size: 17px;
    }

    .button-row,
    .transaction-button-row {
        flex-direction: column-reverse;
    }

    .button-row button {
        width: 100%;
    }

    .action-column,
    .destination-grid,
    .finance-action-grid,
    .combat-action-grid {
        grid-template-columns: 1fr 1fr;
    }

    .trade-panel-heading {
        align-items: flex-start;
        flex-direction: column;
        gap: 2px;
    }

    .transaction-window,
    .finances-window,
    .store-window,
    .hospital-window,
    .history-window,
    .combat-window {
        width: 100%;
    }

    .store-weapon-card {
        grid-template-columns: 1fr;
    }

    .combat-status-grid {
        grid-template-columns: 1fr;
    }

    .combat-action-grid button:last-child {
        grid-column: 1 / -1;
    }
}
