:root {
    --primary-color: #4CAF50;
    --secondary-color: #2196F3;
    --accent-color: #FF9800;
    --background-color: #f5f5f5;
    --card-background: #ffffff;
    --text-color: #333333;
    --text-muted: #666666;
    --border-color: #ddd;
    --error-color: #f44336;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
    padding-top: 0; /* Will be adjusted when sticky header is shown */
}

/* Sticky Header */
.sticky-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 10px 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    transition: transform 0.3s ease;
}

.sticky-header.hidden {
    transform: translateY(-100%);
}

.sticky-header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
}

.sticky-player-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sticky-player-name {
    font-size: 1.2em;
    font-weight: bold;
}

.sticky-rolls-remaining {
    font-size: 0.9em;
    opacity: 0.9;
}

.sticky-dice-mini {
    display: flex;
    gap: 4px;
}

.mini-die {
    width: 24px;
    height: 24px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.mini-die.frozen {
    background: rgba(255, 255, 255, 0.4);
    border-color: rgba(255, 255, 255, 0.6);
}

/* Adjust body padding when sticky header is visible */
body.sticky-header-visible {
    padding-top: 70px;
}

/* Mobile responsiveness for sticky header */
@media (max-width: 768px) {
    .sticky-header {
        padding: 8px 15px;
    }
    
    .sticky-header-content {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }
    
    .sticky-player-info {
        flex-direction: row;
        gap: 15px;
        align-items: center;
    }
    
    .sticky-player-name {
        font-size: 1.1em;
    }
    
    .sticky-rolls-remaining {
        font-size: 0.85em;
    }
    
    .mini-die {
        width: 20px;
        height: 20px;
        font-size: 11px;
    }
    
    body.sticky-header-visible {
        padding-top: 90px;
    }
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 30px;
    padding: 20px;
    background: var(--card-background);
    border-radius: 10px;
    box-shadow: var(--shadow);
}

header h1 {
    color: var(--primary-color);
    font-size: 2.5em;
    margin-bottom: 10px;
}

header p {
    color: #666;
    font-size: 1.2em;
}

main {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 20px;
}

.game-setup {
    background: var(--card-background);
    padding: 20px;
    border-radius: 10px;
    box-shadow: var(--shadow);
}

.game-setup h2 {
    text-align: center;
    margin-bottom: 20px;
    color: var(--primary-color);
}

.setup-description {
    text-align: center;
    margin-bottom: 20px;
    color: var(--text-muted);
    font-size: 16px;
}

.player-setup {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.player-inputs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 15px;
    width: 100%;
    max-width: 800px;
}

.player-input-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.player-input-group label {
    font-weight: 600;
    color: var(--text-color);
    font-size: 14px;
}

.player-inputs input {
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: 5px;
    font-size: 16px;
    transition: border-color 0.3s ease;
}

.player-inputs input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.player-inputs input:invalid {
    border-color: var(--error-color);
}

.input-help {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.input-help:contains("Required"),
input[required] + .input-help {
    color: var(--primary-color);
    font-weight: 500;
}

.game-play {
    background: var(--card-background);
    padding: 20px;
    border-radius: 10px;
    box-shadow: var(--shadow);
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

.dev-mode-toggle {
    text-align: center;
    margin-bottom: 15px;
    padding: 10px;
    background: #f0f8ff;
    border: 1px solid #b3d9ff;
    border-radius: 5px;
}

.dev-mode-toggle label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 500;
}

.dev-mode-toggle input[type="checkbox"] {
    transform: scale(1.2);
}

.dev-mode-section {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 5px;
    padding: 15px;
    margin-bottom: 15px;
}

.dev-mode-section h3,
.dev-mode-section h4 {
    color: var(--secondary-color);
    margin-bottom: 10px;
    font-size: 1.1em;
}

.dev-buttons,
.test-dice-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.test-dice-btn {
    font-size: 12px;
    padding: 6px 12px;
}

.game-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.current-player {
    display: flex;
    align-items: center;
    gap: 10px;
}

.current-player select {
    padding: 8px;
    border: 2px solid var(--border-color);
    border-radius: 5px;
    font-size: 16px;
}

.game-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.left-panel,
.right-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.dice-input {
    background: #f9f9f9;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.dice-input h3 {
    text-align: center;
    margin-bottom: 15px;
    color: var(--secondary-color);
}

.dice-container {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 10px;
}

.dice-help {
    text-align: center;
    margin-bottom: 15px;
    color: #666;
    font-style: italic;
}

.dice-container input {
    width: 60px;
    height: 60px;
    font-size: 24px;
    text-align: center;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    background: white;
    transition: all 0.3s ease;
    
    /* Mobile optimizations */
    -webkit-appearance: none;
    -moz-appearance: textfield;
    font-weight: bold;
    user-select: none;
    
    /* Touch target size for mobile */
    min-height: 44px;
    min-width: 44px;
}

/* Hide number input arrows on WebKit browsers */
.dice-container input::-webkit-outer-spin-button,
.dice-container input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Hide number input arrows on Firefox */
.dice-container input[type=number] {
    -moz-appearance: textfield;
}

.dice-container input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 10px rgba(76, 175, 80, 0.3);
    transform: scale(1.05);
}

/* Visible focus indicator for keyboard navigation */
.dice-container input:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}

/* Selection styling */
.dice-container input::selection {
    background-color: var(--primary-color);
    color: white;
}

.dice-container input:hover {
    border-color: var(--primary-color);
    transform: scale(1.02);
}

/* Invalid input styling */
.dice-container input:invalid {
    border-color: #f44336;
    background-color: #ffebee;
}

/* Active state for better mobile feedback */
.dice-container input:active {
    transform: scale(0.98);
    border-color: var(--accent-color);
}

/* Better selection styling for dice inputs */
.dice-container input::selection {
    background-color: var(--primary-color);
    color: white;
}

.dice-container input::-moz-selection {
    background-color: var(--primary-color);
    color: white;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 5px;
}

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

.btn-primary:hover {
    background-color: #45a049;
    transform: translateY(-2px);
}

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

.btn-secondary:hover {
    background-color: #1976D2;
    transform: translateY(-2px);
}

.btn-tertiary {
    background-color: #9E9E9E;
    color: white;
}

.btn-tertiary:hover {
    background-color: #757575;
    transform: translateY(-2px);
}

.scores-section {
    background: #f9f9f9;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.scores-section h3 {
    text-align: center;
    margin-bottom: 15px;
    color: var(--secondary-color);
}

.scores-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.score-category {
    background: white;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.score-category h4 {
    text-align: center;
    margin-bottom: 15px;
    color: var(--secondary-color);
    font-size: 1.2em;
}

.score-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #eee;
}

.score-item:last-child {
    border-bottom: none;
}

.category-name {
    font-weight: 500;
    flex: 1;
}

/* Score display functional states */
.score {
    font-weight: bold;
    font-size: 1.2em;
    padding: 8px 12px;
    margin: 4px 0;
    border-radius: 8px;
    text-align: center;
    min-width: 60px;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    background: #f5f5f5;
    color: #666;
}

/* Available category with points */
.score.available {
    background: #e8f5e8;
    color: #2e7d32;
    border-color: #4caf50;
    box-shadow: 0 2px 4px rgba(76, 175, 80, 0.2);
}

/* Available category but would score zero */
.score.zero-option {
    background: linear-gradient(135deg, #fff3e0, #ffe0b2);
    color: #e65100;
    border: 2px dashed #ff9800;
    font-style: italic;
    position: relative;
}

.score.zero-option::after {
    content: "0";
    position: absolute;
    top: -8px;
    right: -8px;
    background: #ff9800;
    color: white;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-style: normal;
}

/* Used score - category already scored */
.score.used {
    background: linear-gradient(135deg, #e3f2fd, #f5f5f5);
    color: #1565c0;
    border: 2px solid #2196f3;
    opacity: 1;
    font-weight: bold;
    position: relative;
    box-shadow: inset 0 1px 3px rgba(33, 150, 243, 0.2);
}

.score.used::before {
    content: "✓";
    position: absolute;
    top: -8px;
    right: -8px;
    background: #2196f3;
    color: white;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.scorecard-item.used {
    background: linear-gradient(135deg, #e3f2fd, #f5f5f5);
    border-left: 6px solid #2196f3;
    opacity: 1;
    position: relative;
    box-shadow: 0 1px 3px rgba(33, 150, 243, 0.15);
}

.scorecard-item.used::before {
    content: "✓";
    position: absolute;
    top: 8px;
    right: 8px;
    background: #2196f3;
    color: white;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.scorecard-item.used span:last-of-type {
    color: #1565c0;
    font-weight: bold;
}

.use-score-btn {
    padding: 6px 12px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex; /* Show buttons, but they'll be disabled until dice are entered */
    align-items: center;
    gap: 4px;
    min-width: 70px;
    justify-content: center;
    border: 2px solid transparent;
    margin-left: 12px;
}

.use-score-btn:hover {
    background: #f57c00;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.use-score-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    opacity: 0.7;
}

/* Button color scheme: Score (green), Take 0 (red), Used (grey) */
.use-score-btn.available-score {
    background: var(--primary-color); /* Green for "Score" */
    border-color: #2e7d32;
}

.use-score-btn.available-score:hover {
    background: #45a049;
    transform: translateY(-1px);
    box-shadow: 0 3px 6px rgba(76, 175, 80, 0.3);
}

.use-score-btn.zero-score {
    background: var(--error-color); /* Red for "Take 0" */
    border-color: #d32f2f;
}

.use-score-btn.zero-score:hover {
    background: #d32f2f;
    transform: translateY(-1px);
    box-shadow: 0 3px 6px rgba(244, 67, 54, 0.3);
}

.use-score-btn.bonus-available {
    background: #ffc107;
    color: #000;
    border-color: #ff8f00;
    font-weight: bold;
    animation: bonus-pulse 1.5s ease-in-out infinite;
}

.use-score-btn.used {
    background: #9e9e9e; /* Grey for "Used" */
    color: white;
    border: 2px solid #757575;
    opacity: 1;
    position: relative;
    cursor: default;
    box-shadow: 0 2px 4px rgba(158, 158, 158, 0.3);
}

.use-score-btn.used::before {
    content: "✓";
    margin-right: 4px;
    font-weight: bold;
}

.use-score-btn.used:hover {
    background: #9e9e9e;
    transform: none;
    cursor: default;
}

/* Animations for enhanced visual feedback */
@keyframes bonus-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.dice-display {
    background: #f9f9f9;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.dice-display h3 {
    text-align: center;
    margin-bottom: 15px;
    color: var(--secondary-color);
}

.dice-visual {
    display: flex;
    justify-content: center;
    gap: 15px;
}

.die {
    width: 64px;
    height: 64px;
    font-size: 2.5em;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 4px;
    background: var(--primary-color);
    color: #fff;
    border: none;
    cursor: pointer;
    transition: background 0.2s;
}

.large-die {
    width: 64px;
    height: 64px;
    font-size: 2.5em;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 4px auto;
    background: var(--primary-color);
    color: #fff;
    border: none;
}

.die:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

/* Virtual dice - frozen state */
.die {
    cursor: pointer;
}

.die.frozen {
    background-color: #e3f2fd;
    border-color: #2196f3;
    box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.3);
}

.die.frozen:after {
    content: "🔒";
    position: absolute;
    top: -8px;
    right: -8px;
    background: #2196f3;
    color: white;
    font-size: 12px;
    padding: 2px 4px;
    border-radius: 10px;
    z-index: 1;
}

.player-scorecards {
    background: var(--card-background);
    padding: 20px;
    border-radius: 10px;
    box-shadow: var(--shadow);
}

.player-scorecards h2 {
    text-align: center;
    margin-bottom: 20px;
    color: var(--primary-color);
}

.scorecard {
    background: #f9f9f9;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
}

.scorecard h3 {
    color: var(--secondary-color);
    margin-bottom: 10px;
}

.scorecard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
}

.scorecard-item {
    display: flex;
    justify-content: space-between;
    padding: 5px;
    background: white;
    border-radius: 3px;
    border: 1px solid #eee;
}

.scorecard-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.scorecard-item:hover .scorecard-actions {
    opacity: 1;
}

.edit-score-btn,
.clear-score-btn,
.add-score-btn {
    background: none;
    border: none;
    font-size: 12px;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
    transition: all 0.2s ease;
    min-width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.edit-score-btn:hover {
    background-color: #e3f2fd;
    transform: scale(1.1);
}

.clear-score-btn:hover {
    background-color: #ffebee;
    transform: scale(1.1);
}

.add-score-btn:hover {
    background-color: #e8f5e8;
    transform: scale(1.1);
}

.edit-score-btn:active,
.clear-score-btn:active,
.add-score-btn:active {
    transform: scale(0.95);
}

.bonus-tracker {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 8px;
    padding: 15px;
    margin-top: 15px;
    position: relative;
}

.bonus-tracker h4 {
    color: #856404;
    margin: 0 0 10px 0;
    font-size: 1.1em;
    text-align: center;
    font-weight: 600;
}

.bonus-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.bonus-info div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: white;
    border-radius: 4px;
    border: 1px solid #e6cc7a;
    font-size: 0.9em;
    color: #856404;
    font-weight: 500;
}

.bonus-info div:first-child {
    background: #f8f9fa;
    border-color: #dee2e6;
    color: #495057;
    font-weight: 600;
}

.bonus-info div:nth-child(2) {
    background: #ffeaa7;
    border-color: #fdcb6e;
    color: #2d3436;
}

.bonus-info div:nth-child(3) {
    background: #55a3ff;
    border-color: #74b9ff;
    color: white;
}

.final-score {
    background: var(--primary-color);
    color: white;
    padding: 10px;
    border-radius: 5px;
    text-align: center;
    font-weight: bold;
    margin-top: 10px;
}

.leaderboard {
    background: var(--card-background);
    padding: 20px;
    border-radius: 10px;
    box-shadow: var(--shadow);
}

.leaderboard h2 {
    text-align: center;
    margin-bottom: 20px;
    color: var(--primary-color);
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

.leaderboard-table th,
.leaderboard-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

.leaderboard-table th {
    background: var(--primary-color);
    color: white;
}

.leaderboard-table tr:nth-child(even) {
    background: #f9f9f9;
}

.leaderboard-table tr:hover {
    background: #f5f5f5;
}

.rank-1 {
    background: #ffd700 !important;
    font-weight: bold;
}

.rank-2 {
    background: #c0c0c0 !important;
}

.rank-3 {
    background: #cd7f32 !important;
}

footer {
    text-align: center;
    padding: 20px;
    background: var(--card-background);
    border-radius: 10px;
    box-shadow: var(--shadow);
    margin-top: 20px;
}

footer p {
    color: #666;
    font-style: italic;
}

/* Bonus Yahtzee styling */
.bonus-yahtzee-item {
    background-color: #f0f8ff !important;
    border-left: 4px solid #4CAF50 !important;
}

.bonus-yahtzee-item .category-name {
    font-weight: bold;
}

.bonus-yahtzee-item .score-info {
    font-size: 12px;
    color: #666;
    font-style: italic;
}

.bonus-notification {
    font-size: 12px;
    color: #856404;
    font-weight: bold;
    margin-top: 5px;
    padding: 5px;
    background-color: #fff3cd;
    border-radius: 3px;
    border: 1px solid #ffeaa7;
}

/* Player Tabs */
.player-tabs {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 10px;
}

.player-tab {
    padding: 10px 20px;
    background: #f8f9fa;
    border: 2px solid #dee2e6;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
    font-size: 16px;
    color: #495057;
    min-width: 100px;
    text-align: center;
}

.player-tab:hover {
    background: #e9ecef;
    border-color: #adb5bd;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.player-tab.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
    font-weight: bold;
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
}

.player-tab.active:hover {
    background: #45a049;
    border-color: #45a049;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(76, 175, 80, 0.4);
}

/* Enhanced Dice Actions */
.dice-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 16px;
    flex-wrap: wrap;
}

.dice-actions .btn {
    min-width: 140px;
}

/* Quick Entry Section */
.quick-entry-section {
    margin-top: 24px;
    padding: 20px;
    background: var(--card-background);
    border-radius: 12px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

.quick-entry-section h4 {
    color: var(--primary-color);
    margin-bottom: 16px;
    font-size: 1.1em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.fast-entry {
    margin-bottom: 20px;
}

.fast-entry label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-color);
}

.fast-input-group {
    display: flex;
    gap: 8px;
    margin-bottom: 4px;
}

.fast-input-group input {
    flex: 1;
    padding: 10px 12px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-size: 16px;
    text-align: center;
    font-weight: bold;
    letter-spacing: 2px;
    transition: all 0.2s ease;
}

.fast-input-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
}

.fast-input-group input::placeholder {
    letter-spacing: normal;
    font-weight: normal;
    color: var(--text-muted);
}

/* Responsive design for quick entry */
@media (max-width: 768px) {
    .fast-input-group {
        flex-direction: column;
    }
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
    padding: 20px;
    box-sizing: border-box;
}

/* Modal layering - ensure proper stacking order */
#scorecards-modal {
    z-index: 1000; /* Base layer for scorecard modal */
}

#add-score-modal,
#die-edit-modal {
    z-index: 1100; /* Higher layer for secondary modals */
}

#score-confirmation-modal {
    z-index: 1200; /* Highest layer for confirmation dialogs */
}

.modal-content {
    background: var(--card-background);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

.modal-header {
    padding: 24px 24px 16px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    color: var(--text-color);
    font-size: 1.25em;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.2em;
    cursor: pointer;
    color: var(--text-muted);
    padding: 8px;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: var(--border-color);
    color: var(--text-color);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 16px 24px 24px 24px;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    border-top: 1px solid var(--border-color);
}

/* Add Score Modal Specific Styles */
.add-score-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.score-info {
    background: var(--background-color);
    padding: 16px;
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
}

.player-category {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}

.player-category:last-child {
    margin-bottom: 0;
}

.player-category .label {
    font-weight: 600;
    color: var(--text-muted);
}

/* Dice display in add score modal */
.current-dice-display {
    text-align: center;
}

.current-dice-display h4 {
    margin-bottom: 12px;
    color: var(--text-color);
    font-size: 1em;
}

.add-score-dice,
.confirmation-dice {
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
}

#confirmation-dice {
    margin-bottom: 10px;
}

/* Style dice in both add score modal containers */
.add-score-dice .confirmation-die,
.confirmation-dice .confirmation-die {
    width: 70px;
    height: 70px;
    background: white;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    color: var(--text-color);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    transition: all 0.2s ease;
}

.add-score-dice .confirmation-die.frozen,
.confirmation-dice .confirmation-die.frozen {
    background-color: #e3f2fd;
    border-color: #2196f3;
    position: relative;
}

.add-score-dice .confirmation-die.frozen:after,
.confirmation-dice .confirmation-die.frozen:after {
    content: "🔒";
    position: absolute;
    top: -6px;
    right: -6px;
    background: #2196f3;
    color: white;
    font-size: 10px;
    padding: 1px 3px;
    border-radius: 8px;
}

.score-input-section .input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.score-input-section label {
    font-weight: 500;
    color: var(--text-color);
}

.score-input-section input {
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-size: 16px;
    transition: all 0.2s ease;
}

.score-input-section input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
}

.fixed-score {
    background: var(--background-color);
    padding: 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.fixed-score-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.fixed-score-info .label {
    font-weight: 600;
    color: var(--text-muted);
}

.fixed-score-info span:last-child {
    font-size: 1.5em;
    font-weight: bold;
    color: var(--primary-color);
}

.fixed-score-description {
    color: var(--text-muted);
    font-size: 0.9em;
}

/* Responsive modal */
@media (max-width: 768px) {
    .modal-overlay {
        padding: 10px;
    }
    
    .modal-content {
        max-width: 100%;
    }
    
    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 16px;
    }
    
    .modal-footer {
        flex-direction: column;
    }
}

/* Scorecard Modal Styles */
.scorecard-tabs {
    margin-bottom: 20px;
}

.scorecard-tab-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--border-color);
}

.scorecard-tab-btn {
    padding: 8px 16px;
    background: var(--card-background);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
    color: var(--text-color);
}

.scorecard-tab-btn:hover {
    background: var(--background-color);
    border-color: var(--primary-color);
}

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

.scorecard-display {
    max-height: 60vh;
    overflow-y: auto;
}

.large-modal .modal-content {
    max-width: 800px;
    width: 90vw;
}

/* Enhanced scorecard styling in modal */
.scorecard-display .scorecard {
    border: none;
    box-shadow: none;
    margin: 0;
    padding: 0;
}

.scorecard-display .scorecard h3 {
    font-size: 1.4em;
    color: var(--primary-color);
    margin-bottom: 20px;
    text-align: center;
    padding: 10px;
    background: var(--background-color);
    border-radius: 8px;
}
