:root {
    --bg-color: #0f172a;
    --text-color: #f8fafc;
    
    --color-yellow: #facc15;
    --color-blue: #3b82f6;
    --color-green: #22c55e;
    --color-orange: #f97316;
    --color-purple: #a855f7;
    --color-white: #ffffff;
    
    --color-die-dot: #1e293b;
    --color-die-white-dot: #1e293b;
    
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
}

header {
    text-align: center;
    margin-bottom: 1rem;
}

h1 {
    font-size: 3rem;
    font-weight: 800;
    background: linear-gradient(to right, #facc15, #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 4px 15px rgba(250, 204, 21, 0.2);
    margin-bottom: 0.2rem;
}

.subtitle {
    color: #94a3b8;
    font-size: 1.2rem;
    letter-spacing: 2px;
    text-transform: uppercase;
}

main {
    width: 100%;
    max-width: 1000px;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

.screen {
    display: none;
    animation: fadeIn 0.5s ease;
}

.screen.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Setup */
#setupScreen {
    text-align: center;
}
select {
    padding: 0.75rem 1rem;
    font-size: 1.1rem;
    border-radius: 10px;
    border: 1px solid var(--glass-border);
    background: #1e293b;
    color: white;
    margin: 1rem 0;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    font-size: 1.1rem;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
}
.btn.primary {
    background: var(--color-blue);
    color: white;
}
.btn.primary:hover:not(:disabled) {
    background: #2563eb;
    transform: translateY(-2px);
}
.btn.secondary {
    background: #475569;
    color: white;
}
.btn.secondary:hover:not(:disabled) {
    background: #334155;
}
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Round Tracker */
.round-tracker {
    display: flex;
    gap: 0.5rem;
    margin: 0.5rem 0;
}
.round-item {
    background: rgba(255,255,255,0.1);
    border-radius: 6px;
    padding: 0.2rem 0.5rem;
    text-align: center;
    font-size: 0.8rem;
    color: #94a3b8;
    display: flex;
    flex-direction: column;
}
.round-item span {
    font-size: 1rem;
    margin-top: 2px;
}
.round-item.active {
    background: var(--color-blue);
    color: white;
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.5);
}

/* Info Bar */
.game-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--glass-border);
}
.phase-badge {
    display: inline-block;
    padding: 0.3rem 0.8rem;
    background: rgba(250, 204, 21, 0.2);
    color: var(--color-yellow);
    border-radius: 20px;
    font-weight: bold;
    font-size: 0.9rem;
    margin-top: 0.5rem;
}
.phase-badge.passive {
    background: rgba(168, 85, 247, 0.2);
    color: var(--color-purple);
}
.bonuses-available {
    display: flex;
    gap: 1rem;
}
.bonus-icon {
    font-size: 1.2rem;
    font-weight: bold;
    background: rgba(255,255,255,0.1);
    padding: 0.5rem 1rem;
    border-radius: 8px;
}

/* Dice */
.dice-section {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 2rem;
}
.dice-zone {
    flex: 1;
    background: rgba(0,0,0,0.2);
    border-radius: 12px;
    padding: 1rem;
    text-align: center;
}
.dice-zone h3 {
    font-size: 1rem;
    color: #cbd5e1;
    margin-bottom: 1rem;
}
.dice-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
    justify-content: center;
    min-height: 70px;
}
.dice-actions {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.die {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--color-die-dot);
    cursor: pointer;
    box-shadow: inset 0 -3px 0 rgba(0,0,0,0.2), 0 4px 6px rgba(0,0,0,0.3);
    transition: transform 0.2s;
    user-select: none;
}
.die.selectable:hover {
    transform: translateY(-5px);
    box-shadow: inset 0 -3px 0 rgba(0,0,0,0.2), 0 8px 12px rgba(0,0,0,0.4);
}
.die.grayed-out {
    opacity: 0.45;
    cursor: not-allowed;
    filter: grayscale(25%) saturate(70%);
}
.die.yellow { background: var(--color-yellow); }
.die.blue { background: var(--color-blue); color: white; }
.die.green { background: var(--color-green); color: white; }
.die.orange { background: var(--color-orange); color: white; }
.die.purple { background: var(--color-purple); color: white; }
.die.white { background: var(--color-white); color: var(--color-die-white-dot); }

/* Scorecard */
.scorecard-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.scorecard-top {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}
@media(min-width: 800px) {
    .scorecard-top {
        grid-template-columns: 1fr 1fr;
    }
}
.scorecard-bottom {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.score-area {
    background: rgba(15, 23, 42, 0.6);
    border-radius: 12px;
    padding: 1rem;
    border-top: 4px solid transparent;
}
.score-area.yellow-area { border-color: var(--color-yellow); }
.score-area.blue-area { border-color: var(--color-blue); }
.score-area.green-area { border-color: var(--color-green); }
.score-area.orange-area { border-color: var(--color-orange); }
.score-area.purple-area { border-color: var(--color-purple); }

.area-header {
    font-weight: bold;
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}
.yellow-area .area-header { color: var(--color-yellow); }
.blue-area .area-header { color: var(--color-blue); }
.green-area .area-header { color: var(--color-green); }
.orange-area .area-header { color: var(--color-orange); }
.purple-area .area-header { color: var(--color-purple); }

/* Field Grids */
.grid-4x4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
}
.track-row {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}
.blue-track {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
}
.diagonal-badge {
    border: 1px dashed var(--color-yellow) !important;
    background: rgba(250, 204, 21, 0.1) !important;
}
.field {
    background: rgba(255,255,255,0.1);
    border-radius: 6px;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    position: relative;
    user-select: none;
}
.field.valid {
    cursor: pointer;
    box-shadow: 0 0 8px rgba(255,255,255,0.5);
    animation: pulse 1.5s infinite;
}
.field.valid.yellow-field { background: rgba(250, 204, 21, 0.4); }
.field.valid.blue-field { background: rgba(59, 130, 246, 0.4); }
.field.valid.green-field { background: rgba(34, 197, 94, 0.4); }
.field.valid.orange-field { background: rgba(249, 115, 22, 0.4); }
.field.valid.purple-field { background: rgba(168, 85, 247, 0.4); }

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.field.marked::after {
    content: "X";
    position: absolute;
    color: white;
    font-size: 1.5rem;
    text-shadow: 0 0 5px black;
}
.field.filled {
    color: white;
    font-size: 1.2rem;
    background: rgba(255,255,255,0.2);
}
.field.disabled {
    opacity: 0.3;
}

/* New Scorecard Bonus & Point UI */
.area-content {
    display: flex;
    gap: 0.5rem;
}
.bonus-column {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.points-row, .bonus-row {
    display: flex;
    gap: 4px;
    margin-top: 0.5rem;
    padding-left: 2px;
}
.points-row span, .bonus-row span {
    width: 40px;
    text-align: center;
    display: inline-block;
}
.points-badge, .bonus-badge {
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.9rem;
    font-weight: bold;
    border-radius: 50%; /* Circle for bonuses */
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    color: #cbd5e1;
}
.points-badge {
    border-radius: 6px;
    color: var(--text-color);
    background: rgba(0,0,0,0.3);
}

/* Yellow Diagonal */
.yellow-field[data-r="0"][data-c="0"],
.yellow-field[data-r="1"][data-c="1"],
.yellow-field[data-r="2"][data-c="2"],
.yellow-field[data-r="3"][data-c="3"] {
    background: rgba(250, 204, 21, 0.15); /* light yellow tint */
    border: 1px dashed var(--color-yellow);
}

.bonus-badge.yellow { color: var(--color-yellow); border-color: var(--color-yellow); }
.bonus-badge.blue { color: var(--color-blue); border-color: var(--color-blue); }
.bonus-badge.green { color: var(--color-green); border-color: var(--color-green); }
.bonus-badge.orange { color: var(--color-orange); border-color: var(--color-orange); }
.bonus-badge.purple { color: var(--color-purple); border-color: var(--color-purple); }
.bonus-badge.fox { font-size: 1.2rem; border-color: #ef4444; }

.blue-points-scale {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--color-blue);
    margin-bottom: 0.5rem;
    background: rgba(0,0,0,0.2);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
}

/* Alignment fixes for specific areas */
.blue-content { gap: 1rem; }
.blue-col-bonuses { margin-left: 0; }
.blue-row-bonuses { margin-top: 4px; }
.green-points { margin-bottom: 0.2rem; margin-top: 0; font-size: 0.8rem; color: var(--color-green); }

/* Modals */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    align-items: center;
    justify-content: center;
}
.modal.show {
    display: flex;
}
.modal-content {
    background: #1e293b;
    padding: 2rem;
    border-radius: 16px;
    width: 90%;
    max-width: 500px;
    text-align: center;
    border: 1px solid var(--glass-border);
    position: relative;
    display: flex;
    flex-direction: column;
    max-height: 80vh;
}
.rules-content {
    max-width: 800px;
    height: 80vh;
}
.custom-instructions {
    text-align: left;
    padding-right: 1rem;
    overflow-y: auto;
    flex-grow: 1;
    margin-top: 1rem;
}
.custom-instructions section {
    margin-bottom: 2rem;
}
.custom-instructions h3 {
    color: var(--color-blue);
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
}
.custom-instructions p, .custom-instructions li {
    color: #cbd5e1;
    line-height: 1.6;
    margin-bottom: 0.5rem;
}
.custom-instructions a {
    color: var(--color-blue);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s;
}
.custom-instructions a:hover {
    color: #60a5fa;
    text-decoration: underline;
}
.custom-instructions ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}
.highlight {
    color: #facc15;
    font-weight: bold;
}
.instruction-illustration {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    background: rgba(0,0,0,0.2);
    padding: 1.5rem;
    border-radius: 12px;
    margin: 1.5rem 0;
}
.ill-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    color: #94a3b8;
    font-size: 0.9rem;
}
.ill-arrow {
    font-size: 2rem;
    color: #cbd5e1;
}
.color-rules {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.color-rule {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: rgba(255,255,255,0.05);
    padding: 1rem;
    border-radius: 8px;
}
.color-rule .die {
    flex-shrink: 0;
}
.color-rule div {
    color: #cbd5e1;
    font-size: 0.95rem;
    line-height: 1.4;
}
.close-btn {
    position: absolute;
    top: 10px;
    right: 20px;
    color: #94a3b8;
    font-size: 2rem;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s;
}
.close-btn:hover {
    color: white;
}
.rules-link {
    color: var(--color-blue);
    text-decoration: none;
    font-weight: 600;
    margin-top: 0.5rem;
    display: inline-block;
    transition: color 0.2s;
}
.rules-link:hover {
    color: #60a5fa;
    text-decoration: underline;
}
.analog-hint {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    opacity: 0.8;
}
.analog-hint a {
    color: var(--color-blue);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s;
}
.analog-hint a:hover {
    color: #60a5fa;
    text-decoration: underline;
}
.bonus-options {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.5rem;
}
.hidden {
    display: none !important;
}

/* Scores table styling */
.scores-table {
    width: 100%;
    max-width: 600px;
    margin: 2rem auto;
    border-collapse: collapse;
    background: rgba(15, 23, 42, 0.6);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}
.scores-table th, .scores-table td {
    padding: 1rem;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.scores-table th {
    background: rgba(0, 0, 0, 0.4);
    font-weight: bold;
    color: #f8fafc;
}
.scores-table tr:hover {
    background: rgba(255, 255, 255, 0.02);
}
.scores-table .total-row {
    background: rgba(59, 130, 246, 0.2);
    font-size: 1.1rem;
    border-top: 2px solid var(--color-blue);
}
.scores-table .total-row td {
    border-bottom: none;
}

#bonusModal {
    background-color: rgba(0, 0, 0, 0.2);
    backdrop-filter: none;
}
#bonusModal.show {
    display: block;
}
#bonusModal .modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
    border: 2px solid rgba(255, 255, 255, 0.15);
}

/* Scorecard Tabs */
.scorecard-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    border-bottom: 2px solid #334155;
    padding-bottom: 0.5rem;
}
.tab-btn {
    background: transparent;
    border: none;
    color: #94a3b8;
    padding: 0.5rem 1rem;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s ease;
}
.tab-btn:hover {
    color: #f1f5f9;
    background: #1e293b;
}
.tab-btn.active {
    color: #38bdf8;
    background: #0f172a;
    border: 1px solid #38bdf8;
}

button.die {
    border: none;
    font-family: inherit;
    outline: none;
    padding: 0;
}

/* Highlight for currently selected die in passive/plus-one scoring phases */
.die.selected {
    outline: 3px solid #f8fafc;
    outline-offset: 2px;
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.5);
    z-index: 10;
}

/* Multiplayer Lobby Styling */
.btn-back {
    display: inline-block;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: #94a3b8;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}
.btn-back:hover {
    color: white;
    background: rgba(255, 255, 255, 0.1);
}

.lobby-slot-card {
    background: rgba(30, 41, 59, 0.5);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 0.75rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    transition: all 0.3s ease;
}
.lobby-slot-card:hover {
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.lobby-slot-card.active-slot {
    border-left: 4px solid var(--color-blue);
}
.lobby-slot-card.remote-slot {
    border-left: 4px solid var(--color-purple);
}
.lobby-slot-card.ai-slot {
    border-left: 4px solid var(--color-green);
}
.lobby-slot-card.disabled-slot {
    border-left: 4px solid #475569;
    opacity: 0.5;
}

.slot-number {
    font-weight: 800;
    font-size: 1.1rem;
    color: #94a3b8;
    width: 24px;
}

.slot-main {
    flex-grow: 1;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.slot-name-input {
    background: transparent;
    border: none;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.3);
    color: white;
    font-size: 1rem;
    font-family: inherit;
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    width: 150px;
    transition: border-color 0.2s;
}
.slot-name-input:focus {
    border-bottom-color: var(--color-blue);
    outline: none;
}

.slot-type-select {
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
    border-radius: 8px;
    border: 1px solid var(--glass-border);
    background: #0f172a;
    color: white;
}

.ready-badge {
    padding: 0.25rem 0.75rem;
    font-size: 0.8rem;
    font-weight: bold;
    border-radius: 20px;
    text-transform: uppercase;
}
.ready-badge.ready {
    background: rgba(34, 197, 94, 0.2);
    color: var(--color-green);
    border: 1px solid rgba(34, 197, 94, 0.4);
}
.ready-badge.not-ready {
    background: rgba(249, 115, 22, 0.2);
    color: var(--color-orange);
    border: 1px solid rgba(249, 115, 22, 0.4);
}

/* Clipboard Copy Success Effect */
.copied-flash {
    animation: flashGreen 0.8s ease;
}
@keyframes flashGreen {
    0% { background-color: var(--color-green); color: white; }
    100% { }
}

/* In-game Multiplayer Status Banner */
.mp-status-banner {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 8px;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: #60a5fa;
    text-align: center;
    margin-bottom: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    animation: pulseBorder 2s infinite;
}
@keyframes pulseBorder {
    0% { border-color: rgba(59, 130, 246, 0.2); }
    50% { border-color: rgba(59, 130, 246, 0.6); }
    100% { border-color: rgba(59, 130, 246, 0.2); }
}

.spectator-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(1px);
    z-index: 50;
    pointer-events: none;
}


