:root {
    --faint-grey: #cbd5e1;
}
.yinyang-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem;
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}

.yinyang-container h1 {
    margin-bottom: 1.5rem;
    text-align: center;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2rem;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 0.5rem;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.control-group label {
    font-weight: 600;
    color: var(--text-main);
}

.control-group input[type="number"] {
    width: 60px;
    padding: 0.25rem;
    border-radius: 0.25rem;
    border: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.3);
    color: var(--text-main);
    text-align: center;
}

.control-group input[type="checkbox"] {
    margin-right: 0.25rem;
}

.grid-wrapper {
    position: relative;
    display: inline-block;
    margin: 0 auto;
    /* Center the wrapper if it's smaller than container */
    left: 50%;
    transform: translateX(-50%);
    padding: 10px; /* Space for resize handles */
    border: 2px solid var(--glass-border);
    border-radius: 0.5rem;
    background: rgba(0, 0, 0, 0.3);
}

.yinyang-grid {
    display: grid;
    /* Grid template will be set dynamically via JS */
    gap: 2px;
    background: #475569; /* Grid line color */
    border: 2px solid #475569;
    user-select: none;
}

.cell {
    width: 40px;
    height: 40px;
    background: #f8fafc; /* Default clear background */
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    transition: background-color 0.2s;
}

.cell:hover {
    filter: brightness(0.9);
}

.cell-grey {
    background: #94a3b8;
    cursor: not-allowed;
}

.cell-black {
    background: #f8fafc;
}

/* Adjust cell backgrounds based on class */
.cell.cell-clear { background: #f8fafc; }
.cell.cell-black { background: #f8fafc; }
.cell.cell-white {
    background: #f8fafc;
}

.cell.cell-white .circle {
    background: #fff;
    border: 2px solid #000;
    /* Strong border for placed white */
}
.cell.cell-grey { background: #64748b; }

.circle {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: none; /* Hidden by default */
}

/* Specific circle styles */
.cell-black .circle {
    display: block;
    background: #000;
}

.cell-white .circle {
    display: block;
    background: #fff;
    border: 2px solid #000;
}

/* Predicted styles */
.circle.predicted {
    display: block;
    opacity: 0.4;
}

.circle.predicted-black {
    background: var(--faint-grey);
}

.circle.predicted-white {
    background: #fff;
    border: 2px solid var(--faint-grey);
        /* Fainter border */
        opacity: 0.6;
}

.circle.predicted-either {
    background: linear-gradient(135deg, var(--faint-grey) 50%, #fff 50%);
    border: 2px solid var(--faint-grey);
}

.circle.predicted-none {
    background: var(--danger);
    border: 1px solid #fff;
}

/* True state indicator */
.cell .true-state {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
    opacity: 0.4;
    /* Faded visuals */
}

.cell .true-state.small {
    width: 4px;
    height: 4px;
}

.cell .true-state.black {
    background: #000;
}

.cell .true-state.white {
    background: #fff;
    border: 2px solid #000;
        /* Outline for White */
}

.cell .true-state.none {
    background: var(--danger);
}

/* Resize Handles */
.resize-handle {
    position: absolute;
    background: var(--primary-color);
    width: 8px;
    height: 8px;
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.2s;
    cursor: pointer;
    z-index: 50;
}

.grid-wrapper:hover .resize-handle {
    opacity: 0.7;
}

.yinyang-grid:hover ~ .resize-handle {
    opacity: 0;
    pointer-events: none;
}

.resize-handle:hover {
    opacity: 1 !important;
    transform: scale(1.2);
}

.resize-handle-n { top: 0; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.resize-handle-s { bottom: 0; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.resize-handle-e { right: 0; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.resize-handle-w { left: 0; top: 50%; transform: translateY(-50%); cursor: ew-resize; }

.resize-handle-ne { top: 0; right: 0; cursor: nesw-resize; }
.resize-handle-nw { top: 0; left: 0; cursor: nwse-resize; }
.resize-handle-se { bottom: 0; right: 0; cursor: nwse-resize; }
.resize-handle-sw { bottom: 0; left: 0; cursor: nesw-resize; }

/* Visual Feedback for Computing */

.cell.computing::after {
    content: '';
    position: absolute;
    width: 24px;
    height: 24px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border: 3px solid var(--faint-grey);
    border-top-color: transparent;
    border-radius: 50%;
    animation: cell-spin 1s linear infinite;
    pointer-events: none;
    z-index: 10;
    opacity: 0.4;
}

@keyframes cell-spin {
    from {
        transform: translate(-50%, -50%) rotate(0deg);
    }

    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

#status-indicator.computing::after {
    content: '';
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--faint-grey);
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 1s linear infinite;
    margin-left: 5px;
    vertical-align: middle;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes pulse {
    0% {
        opacity: 0.4;
    }

    50% {
        opacity: 0.8;
    }

    100% {
        opacity: 0.4;
    }
}

/* Tooltips */
.cell-tooltip {
    display: none;
    position: absolute;
    bottom: 120%;
    /* Above the cell */
    left: 50%;
    transform: translateX(-50%);
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--glass-border);
    border-radius: 0.5rem;
    padding: 0.5rem;
    z-index: 1000;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    pointer-events: none;
    /* Don't interfere with clicks */
    white-space: nowrap;
}

.cell:hover .cell-tooltip {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
}

.tooltip-reason {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-main);
    text-align: center;
}

.mini-grid-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.mini-grid-title {
    font-size: 0.7rem;
    color: var(--text-dim);
}

.mini-grid {
    border-collapse: collapse;
    background: #475569;
    border: 1px solid #475569;
    table-layout: fixed;
    width: max-content;
}

.mini-cell {
    width: 12px;
    height: 12px;
    background: #f8fafc;
    border: 1px solid #475569;
}

.mini-cell.black {
    background: #000;
}

.mini-cell.white {
    background: #fff;
}

.mini-cell.clear {
    background: #d8dadc;
}

.mini-cell.conflict {
    background: var(--danger) !important;
}

.mini-cell.highlight {
    box-shadow: inset 0 0 0 2px var(--primary-color);
}

.mini-cell.highlight-1 {
    box-shadow: inset 0 0 0 2px var(--primary-color) !important;
}

.mini-cell.highlight-2 {
    box-shadow: inset 0 0 0 2px #ef4444 !important;
}

.mini-cell.black.inferred {
    background: #d8dadc;
}

.mini-cell.black.inferred::after {
    content: '';
    display: block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #000;
    margin: 2px auto;
}

.mini-cell.white.inferred {
    background: #d8dadc;
    border: 1px solid #475569;
}

.mini-cell.white.inferred::after {
    content: '';
    display: block;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid #000;
    margin: 2px auto;
}

.mini-cell.highlight-current {
    box-shadow: inset 0 0 0 2px #ffc107;
    z-index: 1;
}