.ql-keyscale-card {
    display: block;
    position: relative;
    margin: 1.5rem auto;
    padding: 0; 
    /* Theme-aware borders and backgrounds */
    border: 1px solid var(--sandbox-card-border);
    border-radius: 8px;
    background-color: var(--sandbox-card-bg);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    
    width: 100%; 
    max-width: 800px;
    /* Height is now a suggestion; the controller should manage the aspect ratio */
    min-height: 400px;
    text-align: center;
    overflow: hidden; 
}

/* Container for the specific viewer logic */
.keyscale-viewer-component .btn-group {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 20;
    /* Uses the theme's surface color with transparency for the backdrop */
    background: var(--sandbox-ruler-bg);
    backdrop-filter: blur(8px);
    border: 1px solid var(--sandbox-border);
    border-radius: 6px;
    overflow: hidden;
    opacity: 0.6;
    transition: opacity 0.3s ease, background 0.3s ease;
}

.keyscale-viewer-component:hover .btn-group { 
    opacity: 1; 
}

.keyscale-viewer-component .btn-group .btn {
    font-size: 11px;
    padding: 4px 12px;
    border: none;
    background: transparent;
    color: var(--sandbox-text);
    cursor: pointer;
}

/* Active state matches the theme's primary/accent color */
.keyscale-viewer-component .btn-group .btn.active {
    background-color: var(--sandbox-accent) !important;
    color: #ffffff !important; /* White text for contrast on accent color */
    font-weight: bold;
}

/* Canvas ensures it fills the container logic managed by JS */
.keyscale-viewer-component canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
    background-color: var(--sandbox-canvas-bg);
}

.keyscale-header {
    padding: 3.25rem 1rem 0.5rem;
}

.keyscale-title {
    display: block;
    color: var(--sandbox-text);
    font-size: 1rem;
    font-weight: 700;
}

.keyscale-visual-container {
    position: relative;
    width: 100%;
    height: 320px;
    min-height: 320px;
}

.keyscale-visual-container canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* Focus state when the blot is selected in Quill */
.ql-keyscale-card.ql-selected {
    outline: 2px solid var(--sandbox-accent);
    box-shadow: 0 0 10px rgba(var(--bs-primary-rgb), 0.4);
}


/* The floating container for the view switchers */
.keyscale-toolbar {
    display: flex;
    gap: 2px;
    padding: 4px;
    background-color: var(--sandbox-ruler-bg);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--sandbox-card-border);
    /* If you want it floating over the canvas like the previous design */
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 10;
    border-radius: 6px;
    border: 1px solid var(--sandbox-border);
    transition: opacity 0.2s ease-in-out;
}

/* Individual buttons within the toolbar */
.keyscale-btn {
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--sandbox-text);
    font-size: 10px;
    font-weight: 600;
    padding: 4px 10px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: all 0.2s ease;
}

.keyscale-btn:hover {
    background-color: rgba(var(--bs-primary-rgb), 0.15);
}

/* Active state linked to your theme's accent color */
.keyscale-btn.active {
    background-color: var(--sandbox-accent) !important;
    color: #ffffff !important; /* Force white text for readability on accent colors */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Optional: Hide the toolbar when not hovering over the card for a cleaner look */
.ql-keyscale-card:not(:hover) .keyscale-toolbar {
    opacity: 0.4;
}
