html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

body {
    font-family: Arial, sans-serif;
    background-color: #f0efef;
    font-size: 14;
    margin: 0;
    padding: 0;
}

table {
    width: 100%;
    max-width: 600px;
    margin: 6px auto;
    border-collapse: collapse;
}

th, td {
    border: 1px solid #777777;
    text-align: center;
    padding: 2px;
    /* Allow wrapping so tables fit the screen instead of forcing sideways scroll */
    white-space: normal;
    word-break: break-word;
    /* Avoid constraining table cells so tightly that buttons/inputs become unusable. */
}

th {
    background-color: #cccccc;
}

/* Spreadsheet table column widths */
#spreadsheet th:nth-child(3),
#spreadsheet td:nth-child(3) {
    width: 120px; /* Qty column - wider */
}

#spreadsheet th:nth-child(4),
#spreadsheet td:nth-child(4) {
    width: 80px; /* Cost column - narrower */
}

td.editable {
    background-color: #b4d0fb;
}

input[type="number"] {
    width: 100%;
    padding: 8px;
    border: 1px solid #ccc;
    box-sizing: border-box;
    background-color: #b4d0fb;
    font-size: 16px; /* Prevents zoom on iOS */
    min-height: 44px; /* Minimum touch target size */
}

/* Cash/loan transaction inputs are text (not number) so mobile keyboards
   can enter a minus sign; inputmode="decimal" keeps the numeric keypad. */
.small-input {
    white-space: nowrap;
}
#cashInput, #loanInput {
    width: calc(100% - 58px);
    padding: 8px;
    border: 1px solid #ccc;
    box-sizing: border-box;
    background-color: #b4d0fb;
    font-size: 16px; /* Prevents zoom on iOS */
    min-height: 44px;
    vertical-align: middle;
}
/* +/- sign toggle: phone keypads have no minus key */
.sign-toggle {
    width: 50px;
    padding: 8px 4px;
    margin-left: 4px;
    min-height: 44px;
    border: 1px solid #777;
    border-radius: 4px;
    box-sizing: border-box;
    background-color: #e0e0e0;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    vertical-align: middle;
}
.sign-toggle:active {
    background-color: #c0c0c0;
}

.input-cell {
    padding: 0;
}

.input-cell input {
    border: 1px solid #dddddd;
    margin-top: -1px;
    border-radius: 0;
    
}

.highlight {
    background-color: #5fd7a9;
}

.tables-container {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    box-sizing: border-box;
    padding: 0 8px;
}

.leaderboard-wrapper {
    width: 100%;
    margin: 6px 0;
    text-align: center;
}

#leaderboard {
    width: 100%;
    margin: 6px 0;
    table-layout: fixed;
}

#leaderboard th,
#leaderboard td {
    padding: 1px 2px;
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Column sizing to keep cells compact (percentages so it scales on mobile) */
#leaderboard th:nth-child(1),
#leaderboard td:nth-child(1) {
    width: 28%;
}

#leaderboard th:nth-child(2),
#leaderboard td:nth-child(2) {
    width: 18%;
}

#leaderboard th:nth-child(3),
#leaderboard td:nth-child(3) {
    width: 15%;
}

#leaderboard th:nth-child(n+4),
#leaderboard td:nth-child(n+4) {
    width: 9.75%;
}

/* Buy modal slider: keep thumb directly over progress bar */
#downPaymentSlider {
    position: relative;
    z-index: 2;
    background: transparent;
}

/* The progress bar wrapper is the immediate next div after the slider input */
#downPaymentSlider + div {
    margin-top: -10px; /* pull bar up under the thumb */
    pointer-events: none;
    position: relative;
    z-index: 1;
}

/* .roll-table th, .roll-table td {
    border: 1px solid #777777;
    text-align: center;
    padding: 4px;
} */

.roll-table th {
    background-color: #cccccc;
}

.roll-table button.roll-cell-button {
    width: 100%;
    display: block;
    border: 0;
    background-color: #e0e0e0;
    cursor: pointer;
    padding: 2px;
    font: inherit;
}

.roll-table button.roll-cell-button:hover {
    background-color: #d0d0d0;
}

.roll-table button.roll-cell-button:active {
    background-color: #c0c0c0;
}
.editable {
    cursor: text;
    /* Additional styles here */
  }

.qty-cell {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 2px !important;
    gap: 2px;
    background-color: #b4d0fb;
}

.qty-cell span {
    flex: 1;
    text-align: center;
    min-width: 20px;
    background-color: inherit !important;
    color: inherit;
    border: none;
    outline: none;
    display: inline-block;
    padding: 0 4px;
    margin: 0;
}

.qty-btn {
    padding: 1px 5px;
    border: 1px solid #777;
    background-color: #e0e0e0;
    cursor: pointer;
    font-size: 12px;
    border-radius: 2px;
    flex-shrink: 0;
}

.qty-btn:hover {
    background-color: #d0d0d0;
}

.qty-btn:active {
    background-color: #c0c0c0;
}

.ranch-ridge-cell {
    position: relative;
}

.ranch-ridge-cell .ranch-ridge-dropdown {
    position: absolute;
    right: 2px;
    top: 2px;
}

/* Thumb actions + prevent double-tap zoom/selection while spamming */
button, .qty-btn, .buy-btn, .pay-acre-button, .roll-cell-button, .lb-toggle-btn {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}
input, .editable {
    touch-action: manipulation;
}

/* Fit-to-screen table wrappers — never force sideways scroll.
   Tables shrink to fit the viewport; columns wrap instead of overflowing. */
.table-wrap {
    overflow-x: hidden;
    max-width: 100%;
}
.table-wrap table {
    min-width: 0;
    width: 100%;
    max-width: 100%;
    table-layout: fixed;
}
/* Spreadsheet qty cells need auto layout for the +/- buttons */
#spreadsheet {
    table-layout: fixed;
}

/* Room lobby always wraps inside the screen */
#roomLobby, #roomControls, #hostControls {
    max-width: 100%;
    flex-wrap: wrap;
}
#roomControls input, #roomControls button,
#hostControls button {
    max-width: 100%;
    white-space: normal;
}

/* Quick-transaction buttons: 6 cols on desktop, reflow to 3 cols on small screens */
@media screen and (max-width: 600px) {
    #quickTransactionButtons .grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        width: 100%;
    }
    #quickTransactionButtons button {
        width: auto !important;
    }
}

@media screen and (max-width: 600px) {
    html { -webkit-text-size-adjust: 100%; }
    body {
        font-size: 2vw; /* pre-rooms sizing */
        overscroll-behavior-y: contain;
    }
    table {
        width: 100%;
        max-width: 100%;
    }
    th, td {
        padding: 2px; /* pre-rooms sizing */
    }
    .roll-table th, .roll-table td {
        border: 1px solid #777777;
        text-align: center;
        padding: 2px;
    }

    .roll-table th {
        background-color: #f2f2f2;
    }

    .input-cell input, .small-input input {
        padding: 1px; /* pre-rooms sizing */
    }

    .roll-table, .financial-table {
        margin-top: 10px;
        margin-bottom: 5px;
    }

    /* Modals: fit small screens + safe-area + scroll */
    #buyModal > div, #customBuyModal > div, #payPerAcreModal > div, #payOffLoanModal > div, #resetModal > div, #extraRulesModal > div {
        width: min(92vw, 32rem) !important;
        max-height: 90dvh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        margin: 0 auto;
    }
    #buyModal, #customBuyModal, #payPerAcreModal, #payOffLoanModal, #resetModal, #extraRulesModal {
        padding-bottom: env(safe-area-inset-bottom);
    }
    .tables-container {
        padding-left: max(8px, env(safe-area-inset-left));
        padding-right: max(8px, env(safe-area-inset-right));
    }
    /* Pay-per-acre modal table fits the screen */
    .pay-per-acre-table {
        width: 100%;
        max-width: 100%;
        table-layout: fixed;
    }
    .pay-per-acre-table th, .pay-per-acre-table td {
        padding: 4px; /* pre-rooms sizing */
        white-space: normal;
        word-break: break-word;
    }
}

.buy-btn {
    margin-right: 5px;
    padding: 2px 6px;
    font-size: 12px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
}

.buy-btn:hover {
    background-color: #45a049;
}

/* Pay buttons — red (user request) */
#payPerAcreBtn, #payInterestBtn, #payOffLoanBtn {
    background-color: #dc2626;
}
#payPerAcreBtn:hover, #payInterestBtn:hover, #payOffLoanBtn:hover {
    background-color: #b91c1c;
}

.buy-btn.is-disabled {
    opacity: 0.45;
    filter: grayscale(1);
    cursor: not-allowed;
}

/* Buy modal confirm button when purchase isn't affordable */
#confirmBuy:disabled,
#confirmBuy.is-disabled {
    opacity: 0.45;
    filter: grayscale(1);
    cursor: not-allowed;
}

.asset-cell {
    text-align: left;
}

/* Slider styles */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    height: 20px;
    width: 20px;
    border-radius: 50%;
    background: #4CAF50;
    cursor: pointer;
    margin-top: -12px;
    opacity: 0.5;
}

input[type="range"]::-moz-range-thumb {
    height: 20px;
    width: 20px;
    border-radius: 50%;
    background: #4CAF50;
    cursor: pointer;
    border: none;
    margin-top: -12px;
    opacity: 0.5;
}

#ranchRidgeMenu {
    text-align: left;
}

.roll-help {
    font-size: 10px;
    line-height: 1.1;
    margin: 0 auto -2px;
    max-width: 600px;
}

.roll-table {
    margin-top: 2px;
}

.pay-per-acre-table th, .pay-per-acre-table td {
    border: 1px solid #777777;
    text-align: center;
    padding: 4px;
}

.pay-per-acre-table th {
    background-color: #cccccc;
}

.pay-per-acre-table button.pay-acre-button {
    width: 100%;
    display: block;
    border: 0;
    background-color: #e0e0e0;
    cursor: pointer;
    padding: 2px;
    font: inherit;
}

.pay-per-acre-table button.pay-acre-button:hover {
    background-color: #d0d0d0;
}

.pay-per-acre-table button.pay-acre-button:active {
    background-color: #c0c0c0;
}

.pay-per-acre-table button.pay-acre-button.selected {
    background-color: #90ee90;
}

.undo-hint {
    font-size: 10px;
    line-height: 1.05;
}

/* Leaderboard header: title + table/chart toggle */
.leaderboard-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.lb-view-toggle {
    display: inline-flex;
    border: 1px solid #d1d5db;
    border-radius: 9999px;
    overflow: hidden;
}

.lb-toggle-btn {
    padding: 2px 12px;
    font-size: 12px;
    line-height: 1.4;
    background-color: #f9fafb;
    color: #374151;
    border: 0;
    cursor: pointer;
}

.lb-toggle-btn.active {
    background-color: #16a34a;
    color: #ffffff;
}

/* Chart view: fixed-height box so Chart.js can size the canvas */
#leaderboardChartWrap {
    position: relative;
    height: 260px;
    margin-top: 8px;
}
