*,
*::after,
*::before {
    box-sizing: border-box;
}

:root {
    font-size: 16px;
    --color-text: #000;
    --color-bg: #ddd;
    --color-link: #888;
    --color-link-hover: #000;
}

body {
    margin: 0;
    color: var(--color-text);
    background-color: var(--color-bg);
    font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
}

.game-title {
    position: absolute;
    top: 1rem;
    left: 1rem;
    font-size: 1.6rem;
    font-weight: bold;
    color: #000;
    z-index: 100;
}

.version-info {
    position: absolute;
    bottom: 10px;
    right: 10px;
    font-size: 0.7em;
    color: #666;
    opacity: 0.6;
    font-family: monospace;
    user-select: none;
    z-index: 100;
}

.dark-mode-toggle {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(0, 0, 0, 0.05);
    border: none;
    border-radius: 10px;
    padding: 0.6rem;
    cursor: pointer;
    z-index: 100;
    transition: background-color 0.3s ease, transform 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #000;
}

.dark-mode-toggle:hover {
    background: rgba(0, 0, 0, 0.1);
    transform: scale(1.05);
}

.dark-mode-toggle:active {
    transform: scale(0.95);
}

/* Dark mode styles */
body.dark-mode {
    --color-text: #e0e0e0;
    --color-bg: #1a1a1a;
}

body.dark-mode .game-title {
    color: #e0e0e0;
}

body.dark-mode .version-info {
    color: #999;
}

body.dark-mode .game-info,
body.dark-mode .score-rerolls {
    background: rgba(255, 255, 255, 0.05);
}

body.dark-mode .round::after,
body.dark-mode .target::after,
body.dark-mode .score::after {
    background: rgba(255, 255, 255, 0.2);
}

body.dark-mode .dark-mode-toggle {
    background: rgba(255, 255, 255, 0.1);
    color: #e0e0e0;
}

body.dark-mode .dark-mode-toggle:hover {
    background: rgba(255, 255, 255, 0.15);
}

body.dark-mode .earnings-details {
    background: rgba(46, 139, 87, 0.2);
    color: #e0e0e0;
}

body.dark-mode .store {
    background: rgba(39, 62, 154, 0.2);
    color: #e0e0e0;
}

body.dark-mode .earnings-title,
body.dark-mode .store-title {
    color: #e0e0e0;
}

body.dark-mode .store-table {
    color: #e0e0e0;
}

body.dark-mode .buy-btn:disabled {
    background-color: rgba(100, 100, 100, 0.5);
    color: #888;
}

main {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.content {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

canvas {
    position: absolute;
    top: 0;
    left: 0;
}

.ui-controls {
    position: relative;
    width: 100%;
    max-width: 700px;
    font-family: inherit;
    user-select: none;
    line-height: 1.5;
    padding: 10px;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.game-info {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0;
    width: 100%;
    margin-bottom: 1.5rem;
    max-width: 100%;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
    padding: 0.5rem 1rem;
}

.round, .target, .money {
    font-weight: bold;
    font-size: 1.2rem;
    padding: 0 1rem;
    position: relative;
}

.round::after, .target::after {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 1px;
    height: 1.5rem;
    background: rgba(0, 0, 0, 0.2);
}

.round span, .target span {
    color: #273e9a;
}

.money span {
    color: #2e8b57;
    font-weight: bold;
}

#round-number, #target-score, #money-amount {
    display: inline-block;
    min-width: 2.5rem;
    text-align: right;
}

.score-rerolls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0;
    width: 100%;
    margin-bottom: 1rem;
    max-width: 100%;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
    padding: 0.5rem 1rem;
}

.score {
    font-weight: bold;
    font-size: 1.6rem;
    padding: 0 1rem;
    position: relative;
}

.score::after {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 1px;
    height: 1.5rem;
    background: rgba(0, 0, 0, 0.2);
}

.rerolls {
    font-weight: bold;
    font-size: 1.6rem;
    padding: 0 1rem;
}

.rerolls span {
    font-weight: bold;
    color: #d45f2e;
}

.instructions {
    text-align: center;
    font-size: 1rem;
    color: #666;
    margin-bottom: 1.2rem;
    width: 100%;
    max-width: 100%;
}

.ui-controls #score-result {
    color: #d45f2e;
}

.ui-controls #roll-btn, .ui-controls #next-round-btn, .ui-controls #kick-table-btn {
    background-color: #273e9a;
    font-weight: bold;
    color: #ffffff;
    border: none;
    padding: 1em 1.5em;
    border-radius: 1.5em;
    text-decoration: none;
    display: block;
    cursor: pointer;
    margin: 0 auto 0.5rem;
    transition: background-color 0.2s, transform 0.1s;
    pointer-events: auto;
    font-size: 1.15rem;
}

.ui-controls #next-round-btn {
    background-color: #2e8b57;
}

.ui-controls #kick-table-btn {
    background-color: #d45f2e;
    animation: shake 0.5s infinite;
}

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

.ui-controls #roll-btn:active, .ui-controls #next-round-btn:active {
    transform: translateY(2px);
}

.ui-controls #roll-btn:hover {
    background-color: #3737af;
}

.ui-controls #next-round-btn:hover {
    background-color: #3da869;
}

.ui-controls #roll-btn:disabled {
    background-color: #999;
    cursor: not-allowed;
    opacity: 0.6;
}

.ui-controls #roll-btn:disabled:hover {
    background-color: #999;
}

.ui-controls #roll-btn.game-over {
    background-color: #d32f2f;
}

.ui-controls #roll-btn.game-over:hover {
    background-color: #f44336;
}


.round-summary {
    display: flex;
    gap: 1rem;
    margin: 0 0 1rem 0;
    align-items: stretch;
    width: 100%;
}

.earnings-details {
    flex: 1;
    background: rgba(46, 139, 87, 0.1);
    border: 2px solid #2e8b57;
    border-radius: 10px;
    padding: 1rem;
    font-size: 1rem;
    color: #333;
}

.earnings-title {
    font-size: 1.3rem;
    font-weight: bold;
    color: #2e8b57;
    margin-bottom: 0.3rem;
    text-align: center;
}

.earnings-content {
    line-height: 1.8;
}

.earnings-table {
    width: 100%;
    border-collapse: collapse;
}

.earnings-table td {
    padding: 0.3rem 0.5rem;
}

.earnings-table td:last-child {
    text-align: right;
    white-space: nowrap;
}

.earnings-table .total-row {
    border-top: 2px solid #2e8b57;
    margin-top: 0.5rem;
}

.earnings-table .total-row td {
    padding-top: 0.5rem;
}

.earning-positive {
    color: #2e8b57;
    font-weight: bold;
}

.earning-total {
    color: #2e8b57;
    font-size: 1.1rem;
    font-weight: bold;
}

.combo-bonus {
    color: #9c27b0;
    font-style: italic;
    font-weight: bold;
}

.combo-info {
    text-align: center;
    font-size: 1rem;
    color: #9c27b0;
    font-weight: bold;
    margin: 0 0 1rem 0;
    padding: 0.3rem;
    border-radius: 5px;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    background: transparent;
    transition: background-color 0.2s ease;
}

.combo-info:not(:empty) {
    background: rgba(156, 39, 176, 0.1);
}

.store {
    flex: 1;
    background: rgba(39, 62, 154, 0.1);
    border: 2px solid #273e9a;
    border-radius: 10px;
    padding: 1rem;
    font-size: 1rem;
}

.store-title {
    font-size: 1.3rem;
    font-weight: bold;
    color: #273e9a;
    margin-bottom: 0.3rem;
    text-align: center;
}

.store-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 0.5rem;
}

.store-table td {
    padding: 0.5rem;
}

.store-table td:first-child {
    font-weight: bold;
}

.store-table td:nth-child(2) {
    text-align: center;
    white-space: nowrap;
}

.store-table td:last-child {
    text-align: right;
}

.item-price {
    color: #2e8b57;
    font-weight: bold;
}

.buy-btn {
    background-color: #2e8b57;
    color: white;
    border: none;
    padding: 0.4rem 1rem;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.2s;
    pointer-events: auto;
}

.buy-btn:hover:not(:disabled) {
    background-color: #3da869;
}

.buy-btn:disabled {
    background-color: #999;
    cursor: not-allowed;
    opacity: 0.6;
}

@media (max-width: 768px) {
    .score {
        font-size: 1rem;
    }
    
    .ui-controls #roll-btn {
        font-size: 0.9rem;
        padding: 0.8em 1.2em;
    }
    
    .round-summary {
        flex-direction: column;
    }
    
    .earnings-details, .store {
        width: 100%;
    }
}