/* ===== VARIABLES & CORE ===== */
:root {
    --border-thick: 4px solid var(--ink-black);
}

/* ===== BOARD & GRID ===== */
.stocks_display {
    overflow-x: auto;
    margin: 20px 0;
    background: var(--cardboard);
    border: var(--border-thick) !important;
    box-shadow: 6px 6px 0 rgba(0,0,0,0.3);
}

.stock-price-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--cardboard);
}

.corner-cell {
    border-right: 1px solid rgba(0,0,0,0.15);
    border-bottom: var(--border-thick);
}

.price-header, .price-header-special {
    padding: 10px;
    border-right: 1px solid rgba(0,0,0,0.15);
    border-bottom: var(--border-thick);
    font-family: var(--ticker-font);
}

.price-header {
    background: #e0d1b8;
    color: var(--ink-black);
    font-weight: bold;
}

.price-header-special {
    background: #c5b498 !important;
    color: #fdf6e3 !important;
    font-weight: 900 !important;
    font-size: 1.1em;
    text-shadow: 1px 1px 0px rgba(0, 0, 0, 0.2);
    position: relative;
    text-align: center;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

.price-cell {
    padding: 10px 5px;
    text-align: center;
    min-width: 50px;
    border-right: 1px solid rgba(0, 0, 0, 0.15);
    border-bottom: 1px solid rgba(0, 0, 0, 0.15);
    font-family: var(--ticker-font);
}

.price-cell-special {
    background-color: rgba(0, 0, 0, 0.1) !important;
    position: relative;
}

.price-cell-special::after {
    content: attr(data-label);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 12px;
    color: rgba(0, 0, 0, 0.4);
    font-family: var(--ticker-font);
    font-weight: bold;
    pointer-events: none;
    z-index: 1;
}

.price-cell.current-price {
    background-color: #ffffff !important;
    border: 1px solid var(--ink-black) !important;
    box-shadow: 3px 3px 0 rgba(0,0,0,0.2) !important;
    color: #000 !important;
    z-index: 5;
    position: relative;
}

.price-marker {
    background-color: #ffffff;
    z-index: 5;
    position: relative;
}

.price-marker-animate {
    animation: priceSlide 0.5s ease-out;
}

@keyframes priceSlide {
    0% { transform: scale(0.5); opacity: 0; }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

/* ===== STOCK THEMES ===== */
.stock-header {
    padding: 10px 13px;
    text-align: right;
    font-weight: bold;
    color: #fff !important;
    position: sticky;
    left: 0;
    z-index: 10;
    text-transform: uppercase;
    border-right: var(--border-thick) !important;
    border-bottom: 1px solid rgb(0, 0, 0) !important;
    letter-spacing: 1px;

    text-shadow:
            1px 1px 1px rgba(0, 0, 0, 1),
            -1px -1px 1px rgba(0, 0, 0, 1),
            1px -1px 1px rgba(0, 0, 0, 1),
            -1px 1px 1px rgba(0, 0, 0, 1);
}

.gold-header { background-color: #f1c40f !important; }
.gold-row { background-color: #fde68a; }
.silver-header { background-color: #bdc3c7 !important; }
.silver-row { background-color: #d8dcdf; }
.oil-header { background-color: #2c3e50 !important; }
.oil-row { background-color: #b3bce5; }
.bonds-header { background-color: #2980b9 !important; }
.bonds-row { background-color: #a8d2f0; }
.industrials-header { background-color: #8e44ad !important; }
.industrials-row { background-color: #dcc2e8; }
.grain-header { background-color: #d35400 !important; }
.grain-row { background-color: #f6bfa6; }

/* ===== GAME HEADER ===== */
.game-header {
    background: var(--cardboard);
    border: var(--border-thick);
    border-bottom: 2px dashed rgba(0,0,0,0.6);
    box-shadow: 6px 6px 0 rgba(0,0,0,0.3);
    margin-bottom: 0;
    padding: 8px 15px;
}

.game-header.done-trading-state {
    filter: grayscale(35%);
    opacity: 0.85;
}

.header-unified-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.header-section {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-section.identity { min-width: 250px; }
.header-section.phase-logic {
    flex-grow: 1;
    justify-content: center;
    background: rgba(0,0,0,0.05);
    padding: 4px 20px;
    border-radius: 4px;
}
.header-section.progress-exit {
    min-width: 220px;
    justify-content: flex-end;
}

.game-id, .player-name-display, .round-display, .players-status, .turn-status, .timer {
    padding: 4px 10px;
    font-size: 14px;
    white-space: nowrap;
}

.phase-label {
    padding: 4px 12px;
    font-weight: bold;
    border: 3px solid var(--ink-black);
    background: #ffffff;
    color: var(--ink-black);
    box-shadow: 3px 3px 0 rgba(0,0,0,0.3);
    font-family: var(--retro-font);
    text-transform: uppercase;
}

.phase-label.dice { background: #fdebd0; }

.timer {
    font-weight: bold;
    min-width: 60px;
    text-align: center;
    background: #ffffff;
    color: var(--ink-black);
    border: 3px solid var(--ink-black);
    box-shadow: inset 2px 2px 0 rgba(0,0,0,0.2);
}

.players-status, .turn-status {
    background: #fff;
    border: 3px solid var(--ink-black);
    box-shadow: 3px 3px 0 rgba(0,0,0,0.25);
    font-family: var(--ticker-font);
}

.game-id, .player-name-display {
    background: #fdf6e3;
    border: 2px solid var(--ink-black);
    padding: 4px 12px;
    font-family: var(--ticker-font);
    font-weight: bold;
    color: var(--ink-black);
    box-shadow: inset 2px 2px 0 rgba(0,0,0,0.2);
    display: inline-flex;
    align-items: center;
}

.player-name-display { background: #eef3f6; }

.your-turn-pulse {
    color: #000;
    padding: 2px 8px;
    font-weight: bold;
    animation: pulse 1.5s infinite;
}

.round-display {
    background: #fdf6e3;
    border: 2px solid var(--ink-black);
    padding: 4px 12px;
    font-family: var(--ticker-font);
    font-weight: bold;
    color: var(--ink-black);
    box-shadow: inset 2px 2px 0 rgba(0,0,0,0.2);
    display: inline-flex;
    align-items: center;
}

.btn-leave {
    background: #c0392b;
    border: 3px solid var(--ink-black);
    color: #fff;
    font-family: var(--retro-font);
    font-weight: bold;
    text-transform: uppercase;
    text-decoration: none;
    letter-spacing: 1px;
    padding: 6px 14px;
    display: inline-block;
    cursor: pointer;
    transition: all 0.1s;
    font-size: 13px;
    box-shadow:
            inset 2px 2px 0 rgba(255,255,255,0.25),
            inset -2px -2px 0 rgba(0,0,0,0.25),
            3px 3px 0 rgba(0,0,0,0.4);
}

.btn-leave:hover {
    background: #d64533;
    color: white;
    transform: translate(-1px, -1px);
    box-shadow:
            inset 2px 2px 0 rgba(255,255,255,0.25),
            inset -2px -2px 0 rgba(0,0,0,0.25),
            4px 4px 0 rgba(0,0,0,0.4);
}

.btn-leave:active {
    background: #a93226;
    transform: translate(2px, 2px);
    box-shadow: inset 2px 2px 0 rgba(0,0,0,0.2), 1px 1px 0 rgba(0,0,0,0.4);
}

/* ===== HISTORY BAR ===== */
.history-bar {
    background: var(--paper-white);
    border: var(--border-thick);
    box-shadow: 6px 6px 0 rgba(0,0,0,0.35);
    border-radius: 0;
}

.history-header {
    background: #e7d7b8;
    border-bottom: var(--border-thick);
    font-family: var(--retro-font);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.history-title { color: var(--ink-black); }

.history-toggle {
    color: #3498db;
    font-size: 14px;
    transition: transform 0.3s;
}

.history-bar.expanded .history-toggle { transform: rotate(180deg); }

.history-content {
    background: #fffdf6;
    color: var(--ink-black);
    padding: 15px 20px 0;
    font-family: var(--ticker-font);
    font-size: 13px;
    max-height: 90px;
    overflow-y: auto;
    transition: max-height 0.3s ease;
    line-height: 1.4;
    scroll-behavior: smooth;
    border-top: 2px dashed rgba(0,0,0,0.3);
}

.history-bar.expanded .history-content { max-height: 300px; }

.history-entry {
    padding: 6px 0;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-entry:last-child { border-bottom: none; }

.history-entry.event-roll { color: #f39c12; background: rgba(243, 156, 18, 0.1); border-left: 3px solid #f39c12; }
.history-entry.event-phase { color: #3498db; background: rgba(52, 152, 219, 0.1); border-left: 3px solid #3498db; }
.history-entry.event-trade { color: #2ecc71; background: rgba(46, 204, 113, 0.1); border-left: 3px solid #2ecc71; }
.history-entry.event-player_joined, .history-entry.event-player_left { color: #95a5a6; background: rgba(149, 165, 166, 0.1); border-left: 3px solid #95a5a6; }
.history-entry.event-game_start, .history-entry.event-game_end { color: #9b59b6; background: rgba(155, 89, 182, 0.1); border-left: 3px solid #9b59b6; }
.history-entry.event-round_start, .history-entry.event-round_end { color: #e74c3c; background: rgba(231, 76, 60, 0.1); border-left: 3px solid #e74c3c; }

.history-entry.event-roll, .history-entry.event-phase, .history-entry.event-game_start,
.history-entry.event-game_end, .history-entry.event-round_start, .history-entry.event-round_end {
    font-weight: bold;
    padding: 6px 10px;
    margin: 2px -10px;
    border-bottom: 1px solid rgba(0,0,0,0.1);
}

.history-empty { color: #7f8c8d; font-style: italic; text-align: center; padding: 20px; }

.history-content::-webkit-scrollbar { width: 8px; }
.history-content::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.1); }
.history-content::-webkit-scrollbar-thumb { background: #3498db; border-radius: 4px; }
.history-content::-webkit-scrollbar-thumb:hover { background: #2980b9; }

/* ===== PLAYER DISPLAY ===== */
.players-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 25px;
    margin: 30px 0;
}

.player-card {
    background: var(--paper-white);
    border: var(--border-thick);
    padding: 10px;
    box-shadow: 6px 6px 0 rgba(0,0,0,0.3);
}

.player-card.current-player {
    border-color: #2ecc71 !important;
}

.player-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--ink-black);
    padding-bottom: 5px;
    margin-bottom: 8px;
}

.player-name {
    font-family: var(--retro-font);
    font-weight: bold;
    font-size: 16px;
    text-transform: uppercase;
}

.player-cash {
    font-family: var(--ticker-font);
    font-weight: 900;
    color: #2e7d32;
    font-size: 16px;
    background: rgba(46, 125, 50, 0.1);
    padding: 2px 8px;
    border: 1px solid rgba(46, 125, 50, 0.2);
}

.player-summary {
    background: #f0fff0;
    padding-left: 4px;
    border: 1px dashed #2e7d32;
}

.you-badge {
    background: #2ecc71;
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    margin-left: 8px;
    vertical-align: middle;
}

.disconnected-badge {
    background: #e74c3c;
    color: white;
    padding: 4px 12px;
    border-radius: 15px;
    font-size: 11px;
    margin-left: 8px;
    vertical-align: middle;
    text-transform: uppercase;
    font-weight: bold;
    display: inline-block;
}

.portfolio-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--ticker-font);
}

.portfolio-table th {
    text-align: left;
    border-bottom: 2px solid var(--ink-black);
    padding: 8px 0;
}

.portfolio-table tr {
    border-bottom: 1px dashed rgba(0, 0, 0, 0.3);
}

.portfolio-totals {
    border-bottom: None !important;
    border-top: 1px solid rgba(0, 0, 0, 0.6);
}

.stock-qty, .stock-val {
    text-align: right;
}

/* ===== ACTION FORM ===== */
.action-form {
    background: var(--cardboard);
    padding: 5px;
    border: var(--border-thick);
    border-top: none;
    box-shadow: 6px 6px 0 rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.form-row.three-columns {
    display: grid;
    grid-template-columns: 1fr 2fr 1fr;
    align-items: stretch;
    width: 100%;
}

.form-column {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* --- Roll Column --- */
.column-roll { align-items: center; text-align: center; padding: 10px;}

.btn-roll-ready {
    background: #f1c40f !important;
    color: var(--ink-black) !important;
    border: 3px solid var(--ink-black) !important;
    padding: 0 10px;
    cursor: pointer;
    font-weight: 900;
    font-size: 14px;
    font-family: var(--retro-font);
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 4px 4px 0 rgba(0,0,0,0.3) !important;
    transition: all 0.1s;
    width: 80%;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1.2;
    border-radius: 4px;
    height: 42px !important;
}

.btn-roll-ready:hover:not(:disabled) {
    background: #f39c12 !important;
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 rgba(0,0,0,0.3) !important;
}

.btn-roll-ready:active:not(:disabled) {
    transform: translate(2px, 2px);
    box-shadow: 2px 2px 0 rgba(0,0,0,0.3) !important;
}

.btn-roll-ready:disabled {
    background: #bdc3c7 !important;
    color: #7f8c8d !important;
    cursor: not-allowed;
    box-shadow: 2px 2px 0 rgba(0,0,0,0.1) !important;
    transform: none !important;
    filter: grayscale(1);
    opacity: 0.7;
}

.roll-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100px;
    border: 2px dashed rgba(0,0,0,0.1);
    background: rgba(0,0,0,0.02);
}

.roll-preview-icon { font-size: 20px; margin-bottom: 0; margin-right: 8px; }
.roll-preview-text { font-family: var(--ticker-font); font-size: 11px; color: #666; font-weight: bold; text-align: center; line-height: 1.2; }

/* --- Trade Column --- */
.trade-form .trade-controls {
    display: flex;
    flex-direction: row;
    gap: 10px;
    width: 100%;
    align-items: center;
    justify-content: center;
}
.trade-row { display: flex; justify-content: center; align-items: center; }

.amount-controls {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    width: auto;
}

.custom-number-input {
    position: relative;
    width: 100px; /* Slightly reduced width to make room */
}

.amount-input {
    width: 100%;
    height: 42px !important; /* Matches height of grid */
    font-size: 16px;
}
.spin-buttons {
    position: absolute;
    right: 3px;
    top: 3px;
    bottom: 3px;
    width: 20px;
    display: flex;
    flex-direction: column;
}
.spin-btn {
    flex: 1;
    background: #eee;
    border: 1px solid var(--ink-black);
    cursor: pointer;
    font-size: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    padding: 0;
}
.spin-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.share-quick-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr; /* 2 Columns */
    gap: 2px;
    width: 80px; /* Fixed width for the grid */
}

.share-quick-buttons .qty-btn {
    flex: 1;
    min-width: 0;
    padding: 0;
    font-size: 11px;
    height: 20px; /* Half height of the input box */
}

.qty-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 3px 3px 0 rgba(0,0,0,0.4) !important;
}

.qty-btn.active {
    background-color: #ADD8E6  !important;
    color: var(--ink-black) !important;
    box-shadow: inset 3px 3px 0 rgba(0,0,0,0.2) !important; /* Pressed effect */
    transform: translate(1px, 1px);
}

.cost-display-container { width: 100%; max-width: 200px; }
.trade-action-buttons {
    display: flex;
    gap: 10px;
    width: 100%;
    max-width: 160px;
    justify-content: center;
}
.trade-action-buttons .btn-buy, .trade-action-buttons .btn-sell {
    flex: 1;
    height: 42px;
    font-size: 15px;
    font-weight: bold;
}

/* --- Done Column --- */
.column-done { align-items: center; text-align: center; }
.done-trading-section { width: 100%; }
.done-trading-control { display: flex; flex-direction: column; align-items: center; }
.done-trading-control.checked { opacity: 0.9; }

.checkbox-header { font-family: var(--retro-font); font-size: 13px; font-weight: bold; color: var(--ink-black); margin-bottom: 2px; }
.checkbox-box { cursor: pointer; width: 32px !important; height: 32px !important; border: 3px solid var(--ink-black); background: white; display: flex; align-items: center; justify-content: center; box-shadow: 3px 3px 0 rgba(0,0,0,0.2); transition: all 0.2s; }
.checkbox-box.checked { background: #2ecc71; border-color: #27ae60; }
.checkbox-box .checkmark { font-size: 24px; color: white; font-weight: bold; opacity: 0; transition: opacity 0.2s; }
input[type="checkbox"]:checked + .checkbox-label .checkbox-box .checkmark { opacity: 1; }

.checkbox-text { font-family: var(--ticker-font); font-size: 14px; font-weight: bold; color: var(--ink-black); }
.checkbox-note { font-family: var(--ticker-font); font-size: 11px; color: #666; font-style: italic; margin-top: 5px; text-align: center; }

/* --- Shared Form States --- */
.form-disabled .column-trade .stock-select,
.form-disabled .column-trade .amount-input,
.form-disabled .column-trade .qty-btn,
.form-disabled .column-trade .spin-btn,
.form-disabled .column-trade .btn-buy,
.form-disabled .column-trade .btn-sell {
    opacity: 0.6;
    cursor: not-allowed;
    background-color: #f5f5f5 !important;
}

.select-gold { background-color: #fde68a !important; }
.select-silver { background-color: #d8dcdf !important; }
.select-oil { background-color: #b3bce5 !important; }
.select-bonds { background-color: #a8d2f0 !important; }
.select-industrials { background-color: #dcc2e8 !important; }
.select-grain { background-color: #f6bfa6 !important; }

.stock-select option {
    padding: 10px;
    font-weight: bold;
}

/* ===== TACTILE UI ELEMENTS ===== */
.btn-buy, .btn-sell, .qty-btn {
    border: 3px solid var(--ink-black) !important;
    font-family: var(--retro-font);
    text-transform: uppercase;
    font-weight: bold;
    color: white;
    cursor: pointer;
    transition: all 0.1s;
    box-shadow: 4px 4px 0 rgba(0,0,0,0.4);
}

.btn-buy { background: #27ae60 !important; }
.btn-sell { background: #e74c3c !important; }
.qty-btn { background: #5d7d8a !important; }

.btn-buy:active:not(:disabled), .btn-sell:active:not(:disabled), .qty-btn:active:not(:disabled) {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 rgba(0,0,0,0.4);
}

.stock-select, .amount-input, .cost-display {
    background: #ffffff;
    border: 3px solid var(--ink-black) !important;
    color: var(--ink-black) !important;
    font-family: var(--ticker-font);
    font-weight: bold;
    box-shadow: inset 3px 3px 0 rgba(0,0,0,0.2) !important;
    text-align: center;
    text-align-last: center;
    box-sizing: border-box;
}

.stock-select { width: 150px; height: 42px !important; }
.cost-display {
    background: #eef3f6 !important;
    height: 42px !important;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
}

/* ===== DICE OVERLAY & ANIMATION ===== */
.dice-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: radial-gradient(circle, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0.95) 100%);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    z-index: 1000;
}

.dice-tray {
    display: flex;
    gap: 30px; /* Increased gap for better visual separation */
    margin-bottom: 40px;
}

.die {
    width: 100px; height: 100px; /* Slightly larger for impact */
    background: #fdf6e3;
    border: 6px solid var(--ink-black); /* Thicker cardboard edge */
    box-shadow: 6px 6px 0 rgba(0,0,0,0.6);
    display: flex; align-items: center; justify-content: center;
    font-family: var(--retro-font);
    font-size: 16px; text-align: center; font-weight: bold;
    transition: background-color 0.2s;
}

/* Stand-out Result Text */
.dice-result-text {
    font-family: var(--retro-font);
    font-size: 2.5rem;
    font-weight: 900;
    text-transform: uppercase;
    text-align: center;
    letter-spacing: 2px;
    color: #fff;
    /* Retro "Sticker" outline effect */
    text-shadow:
            3px 3px 0 #000,
            -2px -2px 0 #000,
            2px -2px 0 #000,
            -2px  2px 0 #000,
            2px  2px 0 #000;
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Triggered by JS when the final die lands */
.dice-result-text.reveal-text {
    opacity: 1;
    transform: scale(1);
}

/* Animations */
.rolling { animation: shake 0.1s infinite; }

/* The "Thud" effect when a die stops */
.die-reveal {
    animation: die-thud 0.2s ease-out;
    background-color: #ffffff !important;
}

@keyframes shake {
    0%, 100% { transform: translate(0, 0); }
    25% { transform: translate(-4px, 2px); }
    50% { transform: translate(4px, -2px); }
    75% { transform: translate(-2px, -4px); }
}

@keyframes die-thud {
    0% { transform: scale(1.4); }
    100% { transform: scale(1); }
}

/* ===== FEEDBACK & ERRORS ===== */
.success, .error {
    padding: 12px;
    border-radius: 5px;
    margin: 15px 0;
}

.success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }

.error {
    background: #f8d7da;
    color: #721c24;
    border: 3px solid #f5c6cb;
    font-weight: bold;
    box-shadow: 4px 4px 0 rgba(0,0,0,0.2);
}

.client-error { animation: shake 0.5s; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
    .form-row.three-columns { grid-template-columns: 1fr; gap: 15px; }
    .form-column { min-height: 120px; }
    .btn-roll-ready, .roll-preview { height: 80px; }
}

@media (max-width: 900px) {
    .header-top { flex-direction: column; gap: 15px; text-align: center; }
    .action-bar-content { flex-direction: column; align-items: stretch; }
    .form-row { flex-direction: column; align-items: stretch; }
}

@media (max-width: 850px) {
    .header-unified-bar { flex-direction: column; gap: 10px; }
    .header-section { width: 100%; justify-content: center !important; }
}