/* ===== Reset & Global ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-success: #16a34a;
    --color-danger: #dc2626;
    --color-warning: #f59e0b;
    --color-info: #0891b2;
    --color-bg: #f0f4f8;
    --color-surface: #ffffff;
    --color-text: #1e293b;
    --color-text-light: #64748b;
    --color-border: #e2e8f0;
    --color-income: #16a34a;
    --color-expense: #dc2626;
    --color-asset: #2563eb;
    --color-liability: #9333ea;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
    --transition: 0.2s ease;
}

/* ===== Dark Theme ===== */
[data-theme="dark"] {
    --color-primary: #3b82f6;
    --color-primary-dark: #2563eb;
    --color-success: #22c55e;
    --color-danger: #ef4444;
    --color-warning: #f59e0b;
    --color-info: #06b6d4;
    --color-bg: #0f172a;
    --color-surface: #1e293b;
    --color-text: #e2e8f0;
    --color-text-light: #94a3b8;
    --color-border: #334155;
    --color-income: #22c55e;
    --color-expense: #ef4444;
    --color-asset: #3b82f6;
    --color-liability: #a855f7;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
}

[data-theme="dark"] .modal-overlay {
    background: rgba(0,0,0,0.7);
}

[data-theme="dark"] .dice {
    background: #334155;
    border-color: #64748b;
    color: #e2e8f0;
}

[data-theme="dark"] .player-status-item.viewing {
    background: #1e3a5f;
}

[data-theme="dark"] .fs-row {
    border-bottom-color: #334155;
}

[data-theme="dark"] .fs-section-header.income-header {
    background: #14532d;
    color: #86efac;
}

[data-theme="dark"] .fs-section-header.expense-header {
    background: #450a0a;
    color: #fca5a5;
}

[data-theme="dark"] .fs-section-header.asset-header {
    background: #1e3a5f;
    color: #93c5fd;
}

[data-theme="dark"] .fs-section-header.liability-header {
    background: #3b0764;
    color: #c4b5fd;
}

[data-theme="dark"] .fs-summary {
    background: #0f172a;
}

[data-theme="dark"] .fs-asset-item {
    background: #0f172a;
}

[data-theme="dark"] .card-details,
[data-theme="dark"] .deal-analysis {
    background: #0f172a;
}

[data-theme="dark"] .deal-comparison-col.before {
    background: #1e293b;
}

[data-theme="dark"] .deal-comparison-col.after {
    background: #14532d;
    border-color: #22c55e;
}

[data-theme="dark"] .deal-warning {
    background: #450a0a;
    color: #fca5a5;
}

[data-theme="dark"] .escape-progress-container {
    background: #334155;
}

[data-theme="dark"] .profession-card {
    background: var(--color-surface);
}

[data-theme="dark"] .dream-card {
    background: linear-gradient(135deg, #422006, #78350f);
    border-color: #f59e0b;
    color: #fde68a;
}

[data-theme="dark"] .dream-card .dream-desc {
    color: #d4a574;
}

[data-theme="dark"] .notification.success { background: #15803d; }
[data-theme="dark"] .notification.error { background: #b91c1c; }
[data-theme="dark"] .notification.warning { background: #b45309; }
[data-theme="dark"] .notification.info { background: #0e7490; }

html {
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft JhengHei', sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    overflow: hidden;
}

/* ===== App Layout ===== */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-height: 100vh;
}

/* ===== Top Bar ===== */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
    z-index: 10;
}

.player-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.player-name {
    font-weight: 700;
    font-size: 1rem;
}

.player-profession {
    font-size: 0.85rem;
    color: var(--color-text-light);
}

.game-stats {
    display: flex;
    gap: 16px;
    font-size: 0.9rem;
}

.game-stats span {
    white-space: nowrap;
}

.cash-display strong {
    color: var(--color-success);
}

.cashflow-display strong {
    color: var(--color-primary);
}

.top-actions {
    display: flex;
    gap: 6px;
}

/* ===== Player Status Strip ===== */
.player-status-strip {
    display: flex;
    gap: 6px;
    padding: 4px 12px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    overflow-x: auto;
    flex-shrink: 0;
}

.player-status-item {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    flex-shrink: 0;
}

.player-status-item:hover {
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

.player-status-item.current-turn {
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.3);
    font-weight: 700;
}

.player-status-item.viewing {
    background: #f0f4ff;
}

.player-color-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.player-status-icon {
    font-size: 0.85rem;
}

.player-status-name {
    font-weight: 600;
}

.player-status-cash {
    color: var(--color-success);
    font-weight: 600;
}

.player-status-cf {
    color: var(--color-primary);
    font-size: 0.7rem;
}

/* ===== Main Content ===== */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

.board-section {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 8px;
}

.financial-panel {
    width: 340px;
    overflow-y: auto;
    border-left: 1px solid var(--color-border);
    background: var(--color-surface);
    flex-shrink: 0;
}

/* ===== Bottom Bar ===== */
.bottom-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 16px;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    flex-shrink: 0;
}

.dice-area {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.dice {
    width: 50px;
    height: 50px;
    background: white;
    border: 2px solid var(--color-text);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform var(--transition);
    user-select: none;
}

/* Legacy dice hidden */
.dice.rolling {
    animation: diceRoll 0.5s ease;
}

@keyframes diceRoll {
    0% { transform: rotate(0deg) scale(1); }
    25% { transform: rotate(90deg) scale(1.1); }
    50% { transform: rotate(180deg) scale(1); }
    75% { transform: rotate(270deg) scale(1.1); }
    100% { transform: rotate(360deg) scale(1); }
}

.dice-face {
    font-size: 1.5rem;
    font-weight: 700;
}

/* ===== 3D Dice ===== */
.dice-3d-wrapper {
    width: 50px;
    height: 50px;
    perspective: 300px;
    cursor: pointer;
    user-select: none;
}

.dice-3d {
    width: 50px;
    height: 50px;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.1s ease;
}

.dice-3d-face {
    position: absolute;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    background: var(--color-surface);
    border: 2px solid var(--color-text);
    border-radius: 6px;
    backface-visibility: hidden;
}

[data-theme="dark"] .dice-3d-face {
    background: #334155;
    border-color: #64748b;
}

.dice-front  { transform: rotateY(0deg) translateZ(25px); }
.dice-back   { transform: rotateY(180deg) translateZ(25px); }
.dice-right  { transform: rotateY(90deg) translateZ(25px); }
.dice-left   { transform: rotateY(-90deg) translateZ(25px); }
.dice-top    { transform: rotateX(90deg) translateZ(25px); }
.dice-bottom { transform: rotateX(-90deg) translateZ(25px); }

@keyframes diceRoll3d {
    0%   { transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg); }
    25%  { transform: rotateX(180deg) rotateY(90deg) rotateZ(45deg); }
    50%  { transform: rotateX(360deg) rotateY(180deg) rotateZ(90deg); }
    75%  { transform: rotateX(540deg) rotateY(270deg) rotateZ(135deg); }
    100% { transform: rotateX(720deg) rotateY(360deg) rotateZ(180deg); }
}

.dice-3d.rolling-3d {
    animation: diceRoll3d 0.6s ease-out;
}

.action-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.message-area {
    flex: 1;
    text-align: right;
    font-size: 0.9rem;
    color: var(--color-text-light);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 0.9rem;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn:hover {
    background: var(--color-bg);
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.btn-primary:hover {
    background: var(--color-primary-dark);
}

.btn-success {
    background: var(--color-success);
    color: white;
    border-color: var(--color-success);
}

.btn-danger {
    background: var(--color-danger);
    color: white;
    border-color: var(--color-danger);
}

.btn-warning {
    background: var(--color-warning);
    color: white;
    border-color: var(--color-warning);
}

.btn-small {
    padding: 4px 10px;
    font-size: 0.8rem;
}

.btn-large {
    padding: 12px 32px;
    font-size: 1.1rem;
}

.btn-block {
    display: flex;
    width: 100%;
    margin-bottom: 8px;
}

.btn-roll {
    font-size: 1rem;
    padding: 10px 20px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===== Mobile Tabs ===== */
.mobile-tabs {
    display: none;
    border-top: 1px solid var(--color-border);
    background: var(--color-surface);
    flex-shrink: 0;
}

.tab-btn {
    flex: 1;
    padding: 10px;
    border: none;
    background: none;
    font-size: 0.85rem;
    font-family: inherit;
    color: var(--color-text-light);
    cursor: pointer;
    transition: all var(--transition);
}

.tab-btn.active {
    color: var(--color-primary);
    border-bottom: 2px solid var(--color-primary);
    font-weight: 600;
}

.mobile-panel {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    background: var(--color-surface);
}

/* ===== Modal ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    max-width: 500px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.25s ease;
}

.modal-large {
    max-width: 700px;
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(20px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-title {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 8px;
    text-align: center;
}

.modal-subtitle {
    font-size: 0.9rem;
    color: var(--color-text-light);
    text-align: center;
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
    flex-wrap: wrap;
}

/* ===== Start Screen ===== */
.start-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin: 30px 0;
}

.start-info {
    text-align: center;
    color: var(--color-text-light);
    font-size: 0.85rem;
    line-height: 1.6;
}

/* ===== Menu ===== */
.menu-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* ===== History ===== */
.history-list {
    max-height: 400px;
    overflow-y: auto;
}

.history-item {
    display: flex;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.85rem;
}

.history-turn {
    font-weight: 600;
    color: var(--color-primary);
    min-width: 50px;
}

.history-text {
    flex: 1;
}

/* ===== Tutorial ===== */
.tutorial-content {
    min-height: 200px;
    line-height: 1.8;
    font-size: 0.95rem;
}

.tutorial-content h3 {
    margin-bottom: 10px;
    color: var(--color-primary);
}

.tutorial-content ul {
    margin-left: 20px;
    margin-bottom: 10px;
}

.tutorial-progress {
    font-size: 0.85rem;
    color: var(--color-text-light);
}

/* ===== Victory ===== */
.victory-title {
    font-size: 1.8rem;
    color: var(--color-warning);
}

.victory-content {
    text-align: center;
    line-height: 2;
}

/* ===== Utility ===== */
.text-income { color: var(--color-income); }
.text-expense { color: var(--color-expense); }
.text-asset { color: var(--color-asset); }
.text-liability { color: var(--color-liability); }
.text-bold { font-weight: 700; }
.text-center { text-align: center; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .top-bar {
        flex-wrap: wrap;
        gap: 6px;
        padding: 6px 10px;
    }

    .game-stats {
        gap: 8px;
        font-size: 0.8rem;
        order: 3;
        width: 100%;
        justify-content: space-around;
    }

    .financial-panel {
        display: none;
    }

    .player-status-strip {
        padding: 3px 8px;
        gap: 4px;
    }

    .player-status-item {
        padding: 3px 6px;
        font-size: 0.7rem;
    }

    .player-status-cash,
    .player-status-cf {
        display: none;
    }

    .mobile-tabs {
        display: flex;
    }

    .bottom-bar {
        flex-wrap: wrap;
        gap: 8px;
        padding: 6px 10px;
    }

    .message-area {
        width: 100%;
        order: 3;
        text-align: center;
    }

    .board-section {
        padding: 4px;
    }

    .modal {
        padding: 16px;
        max-height: 90vh;
    }

    .modal-large {
        max-width: 100%;
    }

    .dice {
        width: 42px;
        height: 42px;
    }

    .btn-roll {
        font-size: 0.9rem;
        padding: 8px 14px;
    }
}

@media (max-width: 480px) {
    html {
        font-size: 14px;
    }

    .top-actions .btn-small {
        padding: 4px 6px;
        font-size: 0.75rem;
    }

    .player-profession {
        display: none;
    }
}
