:root {
    --bg-color: #0b1121;
    --card-bg: rgba(30, 41, 59, 0.6);
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --accent: #10b981;
    --accent-glow: rgba(16, 185, 129, 0.4);
    --text: #f8fafc;
    --text-muted: #94a3b8;
    --border: rgba(255, 255, 255, 0.08);
    --font-main: 'Outfit', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: radial-gradient(circle at top, #1e293b 0%, #0b1121 100%);
    color: var(--text);
    font-family: var(--font-main);
    display: flex;
    justify-content: center;
    min-height: 100vh;
}

.app-container {
    width: 100%;
    max-width: 1200px;
    padding: 30px 20px;
    display: flex;
    flex-direction: column;
    gap: 30px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

h1 {
    font-weight: 700;
    letter-spacing: -1px;
    font-size: 2.2rem;
    text-shadow: 0 0 20px rgba(59, 130, 246, 0.4);
}

h1 span {
    color: var(--primary);
}

main {
    display: grid;
    grid-template-columns: 1.3fr 1fr;
    gap: 40px;
}

/* Glassmorphism Classes */
.glass-panel {
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    padding: 24px;
}

/* Scoreboard */
.scoreboard-container {
    overflow-x: auto;
}

table {
    table-layout: fixed;
    width: max-content;
    margin: 0 auto;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.95rem;
}

th,
td {
    padding: 10px 8px;
    text-align: center;
    border-right: 1px solid rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    position: relative;
    overflow: hidden;
}

th:first-child,
td:first-child {
    width: 90px;
}

th:nth-child(2),
td:nth-child(2) {
    width: 50px;
}

th:nth-child(3),
td:nth-child(3) {
    width: 50px;
}

th:nth-child(4),
td:nth-child(4) {
    width: 50px;
}

th:nth-child(5),
td:nth-child(5) {
    width: 50px;
}

th:nth-child(6),
td:nth-child(6) {
    width: 60px;
}

th {
    color: var(--text-muted);
    font-weight: 600;
    padding-bottom: 15px;
    font-size: 1.4rem;
}

/* Matrix layout table styling */
td.row-header {
    font-weight: 600;
    color: var(--text-muted);
    background: transparent;
    text-align: right;
    padding-right: 15px;
}

td.playable-cell {
    background: rgba(255, 255, 255, 0.02);
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 4px;
}

td.playable-cell:not(.filled):hover {
    background: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

td.filled {
    color: #fff;
    font-weight: 700;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
}

td.announced-cell {
    background: rgba(16, 185, 129, 0.2) !important;
    box-shadow: inset 0 0 10px rgba(16, 185, 129, 0.5);
}

/* Table layout tweaks for clean view */
tr.section-end td {
    border-bottom: 2px solid rgba(255, 255, 255, 0.08);
}

.empty-header {
    background: transparent !important;
    border: none !important;
}

.row-bonus-cell {
    text-align: left;
    padding-left: 8px;
    color: var(--text-muted);
    font-size: 0.8rem;
    border-right: none;
}

/* Subtotals and totals */
.subtotal-row td:not(.empty-header) {
    background: rgba(0, 0, 0, 0.2) !important;
    font-weight: 700;
    color: var(--primary);
    padding-top: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(59, 130, 246, 0.3);
}

.subtotal-sum-cell {
    color: var(--accent) !important;
    font-size: 1.1rem;
    text-shadow: 0 0 10px var(--accent-glow);
}

.footer-row td {
    border: none !important;
    padding-top: 25px;
    padding-bottom: 25px;
}

.expected-est-cell {
    text-align: right !important;
    color: var(--text-muted) !important;
    font-size: 1.1rem !important;
    font-weight: 500 !important;
    vertical-align: middle !important;
    padding-right: 20px !important;
}

.expected-est-cell span {
    color: var(--accent);
    font-weight: 800;
    font-size: 1.3rem;
    margin-left: 10px;
    text-shadow: 0 0 10px var(--accent-glow);
}

.grand-total-final {
    display: inline-block;
    background: var(--primary) !important;
    color: white;
    font-size: 1.5rem;
    font-weight: 800;
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.5);
    padding: 12px 20px !important;
    min-width: 80px;
}

/* Controls */
.controls-container {
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.dice-area {
    text-align: center;
}

.dice-row {
    display: grid;
    grid-template-columns: repeat(3, max-content);
    justify-content: center;
    gap: 15px;
    margin-bottom: 25px;
}

/* Dice */
.die {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, #ffffff 0%, #e2e8f0 100%);
    color: #0f172a;
    border-radius: 14px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.8rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.3), inset 0 -4px 0 rgba(0, 0, 0, 0.1);
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    user-select: none;
}

.die:active {
    transform: translateY(2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3), inset 0 -2px 0 rgba(0, 0, 0, 0.1);
}

.die.kept {
    background: linear-gradient(135deg, var(--accent) 0%, #059669 100%);
    color: white;
    box-shadow: 0 0 20px var(--accent-glow), inset 0 -4px 0 rgba(0, 0, 0, 0.2);
    transform: translateY(8px);
}

.die.placeholder {
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.2);
    box-shadow: none;
    border: 2px dashed rgba(255, 255, 255, 0.1);
}

/* Dot Dice System */
.die[data-value] {
    font-size: 0;
    /* Hide text if dots are present */
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 4px;
    padding: 8px;
}

.die .dot {
    width: 12px;
    height: 12px;
    background: #0f172a;
    border-radius: 50%;
    align-self: center;
    justify-self: center;
}

.die.kept .dot {
    background: #fff;
}

/* Dice Dot Layouts using Grid Areas */
.die.val-1 .dot:nth-child(1) {
    grid-area: 2 / 2;
}

.die.val-2 .dot:nth-child(1) {
    grid-area: 1 / 1;
}

.die.val-2 .dot:nth-child(2) {
    grid-area: 3 / 3;
}

.die.val-3 .dot:nth-child(1) {
    grid-area: 1 / 1;
}

.die.val-3 .dot:nth-child(2) {
    grid-area: 2 / 2;
}

.die.val-3 .dot:nth-child(3) {
    grid-area: 3 / 3;
}

.die.val-4 .dot:nth-child(1) {
    grid-area: 1 / 1;
}

.die.val-4 .dot:nth-child(2) {
    grid-area: 1 / 3;
}

.die.val-4 .dot:nth-child(3) {
    grid-area: 3 / 1;
}

.die.val-4 .dot:nth-child(4) {
    grid-area: 3 / 3;
}

.die.val-5 .dot:nth-child(1) {
    grid-area: 1 / 1;
}

.die.val-5 .dot:nth-child(2) {
    grid-area: 1 / 3;
}

.die.val-5 .dot:nth-child(3) {
    grid-area: 2 / 2;
}

.die.val-5 .dot:nth-child(4) {
    grid-area: 3 / 1;
}

.die.val-5 .dot:nth-child(5) {
    grid-area: 3 / 3;
}

.die.val-6 .dot:nth-child(1) {
    grid-area: 1 / 1;
}

.die.val-6 .dot:nth-child(2) {
    grid-area: 2 / 1;
}

.die.val-6 .dot:nth-child(3) {
    grid-area: 3 / 1;
}

.die.val-6 .dot:nth-child(4) {
    grid-area: 1 / 3;
}

.die.val-6 .dot:nth-child(5) {
    grid-area: 2 / 3;
}

.die.val-6 .dot:nth-child(6) {
    grid-area: 3 / 3;
}

/* Roll Animation */
@keyframes rollAnim {
    0% {
        transform: scale(1) rotate(0deg);
    }

    30% {
        transform: scale(1.1) rotate(15deg);
    }

    70% {
        transform: scale(0.9) rotate(-15deg);
    }

    100% {
        transform: scale(1) rotate(0deg);
    }
}

.rolling {
    animation: rollAnim 0.3s ease-in-out;
}

.roll-info {
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 20px;
    font-size: 1.1rem;
}

.highlight-anim {
    animation: highlightFlash 0.5s ease-in-out;
}

@keyframes highlightFlash {
    0% {
        transform: scale(1);
        box-shadow: inset 0 0 0 rgba(59, 130, 246, 0);
        background-color: inherit;
        z-index: 10;
    }

    50% {
        transform: scale(1.05);
        box-shadow: inset 0 0 20px rgba(59, 130, 246, 0.8), 0 0 15px rgba(59, 130, 246, 0.4);
        background-color: rgba(59, 130, 246, 0.4) !important;
        z-index: 10;
        border-radius: 8px;
    }

    100% {
        transform: scale(1);
        box-shadow: inset 0 0 0 rgba(59, 130, 246, 0);
        background-color: inherit;
        z-index: 10;
    }
}

#rollsLeft {
    color: var(--primary);
    font-weight: 800;
}

/* Buttons */
.primary-btn,
.secondary-btn {
    padding: 14px 28px;
    border-radius: 12px;
    border: none;
    font-weight: 700;
    cursor: pointer;
    width: 100%;
    font-size: 1.1rem;
    transition: all 0.2s;
    letter-spacing: 0.5px;
    font-family: var(--font-main);
}

.primary-btn {
    background: linear-gradient(135deg, var(--primary) 0%, #2563eb 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(59, 130, 246, 0.6);
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Analysis */
.analysis-panel h3 {
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.analysis-panel.hidden {
    opacity: 0.3;
    pointer-events: none;
}

.suggestion-item {
    padding: 12px;
    margin-bottom: 8px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    position: relative;
    overflow: hidden;
    z-index: 1;
}

.suggestion-item:last-child {
    margin-bottom: 0;
}

.suggestion-item.clickable {
    cursor: pointer;
    transition: all 0.2s;
}

.suggestion-item.clickable:hover {
    transform: translateX(5px);
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.05);
}

.suggestion-item .content {
    display: flex;
    justify-content: space-between;
    position: relative;
    z-index: 2;
}

.suggestion-item .prob-bar {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: linear-gradient(90deg, rgba(16, 185, 129, 0.2) 0%, rgba(16, 185, 129, 0.05) 100%);
    z-index: 0;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.suggestion-item:first-child .prob-bar {
    background: linear-gradient(90deg, rgba(59, 130, 246, 0.3) 0%, rgba(59, 130, 246, 0.05) 100%);
}

.suggestion-item:first-child .prob {
    color: var(--primary);
}

.suggestion-item .prob {
    color: var(--accent);
    font-weight: 700;
}

/* Switch */
.engine-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--primary);
}

input:checked+.slider:before {
    transform: translateX(20px);
}

/* Edit Mode */
.dice-area.editing {
    border: 2px dashed var(--accent);
    animation: fadePulse 2s infinite;
}

@keyframes fadePulse {
    0% {
        border-color: rgba(16, 185, 129, 0.8);
    }

    50% {
        border-color: rgba(16, 185, 129, 0.3);
    }

    100% {
        border-color: rgba(16, 185, 129, 0.8);
    }
}

.header-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    font-weight: bold;
    display: grid;
    place-items: center;
}

.header-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.edit-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    padding-top: 10px;
    cursor: pointer;
    font-family: var(--font-main);
    text-decoration: underline;
    text-underline-offset: 4px;
}

.edit-btn:hover {
    color: var(--text);
}

/* Modals & Status */
.status-msg {
    margin-top: 15px;
    color: #ef4444;
    font-weight: 600;
    text-align: center;
    height: 20px;
}

.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.modal-content {
    background-color: var(--card-bg);
    margin: 5vh auto;
    padding: 30px;
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 90%;
    max-width: 700px;
    max-height: 90vh;
    overflow-y: auto;
}

.close-btn {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close-btn:hover {
    color: white;
}

@media (max-width: 900px) {
    main {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .die {
        width: 50px;
        height: 50px;
        font-size: 1.4rem;
    }

    .die .dot {
        width: 10px;
        height: 10px;
    }
}