/* Decomposition Layout System
 * Replaces the old 3x3 grid with operator-based layouts
 */

/* View toggle controls */
.decomposition-view-toggle {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 20px;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #dee2e6;
}

.view-toggle-button {
    padding: 8px 16px;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: #495057;
    transition: all 0.2s ease;
}

.view-toggle-button:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

.view-toggle-button.active {
    background: #3498db;
    color: white;
    border-color: #3498db;
}

/* Base layout container */
.decomposition-layout {
    position: relative;
    width: 300px;
    height: 300px;
    margin: 0 auto;
    background: #f8f9fa;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    overflow: hidden;
}

/* Component containers */
.component-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Component visual styling */
.component-visual {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    cursor: pointer;
    transition: all 0.3s ease;
    border-radius: 4px;
    background: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.component-visual:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    z-index: 10;
}

/* Component content */
.component-content {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Text styling */
.component-text {
    font-size: 2.5rem;
    font-weight: bold;
    color: #2c3e50;
    text-align: center;
    z-index: 2;
}

.component-text-large {
    font-size: 3rem;
    font-weight: bold;
    color: #2c3e50;
    text-align: center;
}

/* Image styling */
.component-image-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

.component-image {
    max-width: 80%;
    max-height: 80%;
    object-fit: contain;
    border-radius: 4px;
    opacity: 0.7;
}

.component-image-full {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    border-radius: 4px;
}

.component-text-overlay {
    position: absolute;
    bottom: 5px;
    left: 0;
    width: 100%;
    text-align: center;
    font-size: 0.875rem;
    color: #6c757d;
    background: rgba(255, 255, 255, 0.8);
    padding: 2px 0;
    z-index: 3;
}

/* Badges */
.component-position-badge {
    position: absolute;
    top: 5px;
    left: 5px;
    font-size: 0.75rem;
    color: #6c757d;
    background: rgba(255, 255, 255, 0.9);
    padding: 2px 6px;
    border-radius: 10px;
    z-index: 3;
}

.component-type-badge {
    position: absolute;
    bottom: 5px;
    right: 5px;
    font-size: 0.75rem;
    color: white;
    padding: 2px 6px;
    border-radius: 10px;
    z-index: 3;
}

/* Type-specific badge colors */
.component-type-badge[data-component-type="radical"] {
    background: #e74c3c;
}

.component-type-badge[data-component-type="phonetic"] {
    background: #3498db;
}

.component-type-badge[data-component-type="semantic"] {
    background: #2ecc71;
}

.component-type-badge[data-component-type="other"] {
    background: #9b59b6;
}

/* Full character overlay */
.full-character-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
    font-weight: bold;
    color: rgba(44, 62, 80, 0.1);
    pointer-events: none;
    z-index: 0;
}

/* Warning message */
.extra-components-warning {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(231, 76, 60, 0.1);
    color: #c0392b;
    font-size: 0.75rem;
    padding: 4px 8px;
    text-align: center;
    z-index: 20;
}

/* ============================================
   LAYOUT SPECIFIC STYLES
   ============================================ */

/* Horizontal Split (⿰) */
.horizontal-split {
    display: flex;
    gap: 8px;
    padding: 8px;
}

.horizontal-split .left-component {
    flex: 1;
    border-right: 2px dashed #3498db;
}

.horizontal-split .right-component {
    flex: 1;
}

/* Vertical Split (⿱) - Top-Bottom Layout */
.vertical-split {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px;
}

.vertical-split .top-component {
    flex: 1;
    border-bottom: 3px solid #3498db;
    background: rgba(52, 152, 219, 0.1); /* Light blue background for top */
    border-radius: 8px 8px 0 0; /* Rounded top corners */
    z-index: 1;
    position: relative;
    overflow: hidden;
}

.vertical-split .top-component::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 10%;
    right: 10%;
    height: 2px;
    background: linear-gradient(90deg, transparent, #3498db, transparent);
}

.vertical-split .bottom-component {
    flex: 1;
    background: rgba(46, 204, 113, 0.1); /* Light green background for bottom */
    border-radius: 0 0 8px 8px; /* Rounded bottom corners */
    margin-top: -2px; /* Overlap the border */
    position: relative;
    z-index: 0;
}

/* Three Part Horizontal (⿲) */
.three-part-horizontal {
    display: flex;
    gap: 4px;
    padding: 8px;
}

.three-part-horizontal .left-component,
.three-part-horizontal .middle-component,
.three-part-horizontal .right-component {
    flex: 1;
}

.three-part-horizontal .left-component {
    border-right: 1px dashed #3498db;
}

.three-part-horizontal .right-component {
    border-left: 1px dashed #3498db;
}

/* Three Part Vertical (⿳) */
.three-part-vertical {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px;
}

.three-part-vertical .top-component,
.three-part-vertical .middle-component,
.three-part-vertical .bottom-component {
    flex: 1;
}

.three-part-vertical .top-component {
    border-bottom: 1px dashed #3498db;
}

.three-part-vertical .bottom-component {
    border-top: 1px dashed #3498db;
}

/* Full Enclosure (⿴) - Outer/Inner overlay style */
.full-enclosure {
    padding: 15px;
    position: relative;
}

.full-enclosure .enclosing-component {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80%;
    height: 80%;
    background: rgba(52, 152, 219, 0.1); /* Light blue transparent background */
    border-radius: 50%; /* Circular shape */
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: "Noto Sans", "SimHei", "Microsoft YaHei", sans-serif;
    font-size: 120px; /* Large font for outer character */
    color: #3498db; /* Blue color for outer character */
    z-index: 1;
}

.full-enclosure .enclosed-component {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40%; /* 40% of container as requested */
    height: 40%;
    background: rgba(231, 76, 60, 0.2); /* Light red transparent background */
    border-radius: 50%; /* Circular shape */
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: "Noto Sans", "SimHei", "Microsoft YaHei", sans-serif;
    font-size: 48px; /* Scaled font for inner character */
    color: #e74c3c; /* Red color for inner character */
    z-index: 2;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}

/* Adjust component visual styles for full enclosure */
.full-enclosure .component-visual {
    background: transparent;
    box-shadow: none;
    border-radius: 50%;
}

.full-enclosure .component-visual:hover {
    transform: none; /* Disable hover effect for overlay style */
    box-shadow: none;
}

.full-enclosure .component-text {
    font-size: inherit; /* Use font-size from parent */
    color: inherit; /* Use color from parent */
}

.full-enclosure .component-position-badge {
    display: none; /* Hide position badges for cleaner overlay look */
}

/* Top Enclosure (⿵) */
.top-enclosure {
    padding: 15px;
}

.top-enclosure .top-enclosure-component {
    position: absolute;
    top: 10px;
    left: 10px;
    width: calc(100% - 20px);
    height: 30%;
    border: 3px solid #3498db;
    border-bottom: none;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
}

.top-enclosure .enclosed-component {
    position: absolute;
    top: 40%;
    left: 20%;
    width: 60%;
    height: 50%;
}

/* Bottom Enclosure (⿶) */
.bottom-enclosure {
    padding: 15px;
}

.bottom-enclosure .bottom-enclosure-component {
    position: absolute;
    bottom: 10px;
    left: 10px;
    width: calc(100% - 20px);
    height: 30%;
    border: 3px solid #3498db;
    border-top: none;
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
}

.bottom-enclosure .enclosed-component {
    position: absolute;
    top: 15%;
    left: 20%;
    width: 60%;
    height: 50%;
}

/* Left Enclosure (⿷) */
.left-enclosure {
    padding: 15px;
}

.left-enclosure .left-enclosure-component {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 30%;
    height: calc(100% - 20px);
    border: 3px solid #3498db;
    border-right: none;
    border-top-left-radius: 8px;
    border-bottom-left-radius: 8px;
}

.left-enclosure .enclosed-component {
    position: absolute;
    top: 20%;
    left: 35%;
    width: 60%;
    height: 60%;
}

/* Top-Left Enclosure (⿸) */
.top-left-enclosure {
    padding: 15px;
}

.top-left-enclosure .top-left-enclosure-component {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 40%;
    height: 40%;
    border: 3px solid #3498db;
    border-bottom: none;
    border-right: none;
    border-top-left-radius: 8px;
}

.top-left-enclosure .enclosed-component {
    position: absolute;
    top: 25%;
    left: 25%;
    width: 70%;
    height: 70%;
}

/* Top-Right Enclosure (⿹) */
.top-right-enclosure {
    padding: 15px;
}

.top-right-enclosure .top-right-enclosure-component {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 40%;
    height: 40%;
    border: 3px solid #3498db;
    border-bottom: none;
    border-left: none;
    border-top-right-radius: 8px;
}

.top-right-enclosure .enclosed-component {
    position: absolute;
    top: 25%;
    left: 5%;
    width: 70%;
    height: 70%;
}

/* Bottom-Left Enclosure (⿺) */
.bottom-left-enclosure {
    padding: 15px;
}

.bottom-left-enclosure .bottom-left-enclosure-component {
    position: absolute;
    bottom: 10px;
    left: 10px;
    width: 40%;
    height: 40%;
    border: 3px solid #3498db;
    border-top: none;
    border-right: none;
    border-bottom-left-radius: 8px;
}

.bottom-left-enclosure .enclosed-component {
    position: absolute;
    top: 5%;
    left: 25%;
    width: 70%;
    height: 70%;
}

/* Overlay (⿻) */
.overlay {
    padding: 15px;
}

.overlay .overlay-component-1 {
    position: absolute;
    top: 15px;
    left: 15px;
    width: calc(100% - 30px);
    height: calc(100% - 30px);
    z-index: 1;
    animation: pulse-overlay-1 3s ease-in-out infinite;
}

.overlay .overlay-component-2 {
    position: absolute;
    top: 30px;
    left: 30px;
    width: calc(100% - 60px);
    height: calc(100% - 60px);
    z-index: 2;
    opacity: 0.8;
    animation: pulse-overlay-2 3s ease-in-out infinite;
}

@keyframes pulse-overlay-1 {
    0%, 100% {
        transform: translate(0, 0);
        box-shadow: 0 0 0 rgba(52, 152, 219, 0);
    }
    50% {
        transform: translate(-2px, -2px);
        box-shadow: 0 0 10px rgba(52, 152, 219, 0.3);
    }
}

@keyframes pulse-overlay-2 {
    0%, 100% {
        transform: translate(0, 0);
        box-shadow: 0 0 0 rgba(231, 76, 60, 0);
    }
    50% {
        transform: translate(2px, 2px);
        box-shadow: 0 0 10px rgba(231, 76, 60, 0.3);
    }
}

/* Single Component (？) */
.single-component {
    padding: 20px;
}

.single-component .main-component {
    width: 100%;
    height: 100%;
}

/* ============================================
   VIEW MODES
   ============================================ */

/* Text-only view */
.text-only .component-image-container {
    display: none;
}

.text-only .component-text {
    font-size: 3rem;
}

/* Image-only view */
.image-only .component-text {
    display: none;
}

.image-only .component-image {
    opacity: 1;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

@media (max-width: 768px) {
    .decomposition-layout {
        width: 250px;
        height: 250px;
    }
    
    .component-text {
        font-size: 2rem;
    }
    
    .component-text-large {
        font-size: 2.5rem;
    }
    
    .full-character-overlay {
        font-size: 3rem;
    }
    
    /* Adjust full enclosure for smaller screens */
    .full-enclosure .enclosing-component {
        font-size: 90px;
    }
    
    .full-enclosure .enclosed-component {
        font-size: 36px;
    }
}

@media (max-width: 480px) {
    .decomposition-layout {
        width: 200px;
        height: 200px;
    }
    
    .component-text {
        font-size: 1.5rem;
    }
    
    .component-text-large {
        font-size: 2rem;
    }
    
    .full-character-overlay {
        font-size: 2.5rem;
    }
    
    /* Adjust full enclosure for mobile screens */
    .full-enclosure .enclosing-component {
        font-size: 70px;
    }
    
    .full-enclosure .enclosed-component {
        font-size: 28px;
    }
}

/* ============================================
   ANIMATIONS
   ============================================ */

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

.component-visual.highlighted {
    animation: component-pulse 1s ease-in-out;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.5);
}

/* ============================================
   RELATIONSHIP VISUALIZATION
   ============================================ */

.relationship-line {
    stroke-width: 2;
    stroke-linecap: round;
    fill: none;
    opacity: 0.7;
    transition: all 0.3s ease;
}

.relationship-line:hover {
    stroke-width: 3;
    opacity: 1;
}

.relationship-contains {
    stroke: #3498db;
    stroke-dasharray: 10, 5;
}

.relationship-overlaps {
    stroke: #e74c3c;
    stroke-dasharray: 5, 5;
}

.relationship-adjacent {
    stroke: #2ecc71;
}

.relationship-encloses {
    stroke: #9b59b6;
    stroke-dasharray: 15, 5;
}

/* Circular Enclosure Layout (口 内 玉 style) */
.circular-enclosure {
    position: relative;
    width: 300px;
    height: 300px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #f0f0f0;
    border-radius: 8px;
}

.circular-outer {
    width: 80%;
    height: 80%;
    background: rgba(0, 120, 215, 0.2); /* light blue transparent */
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: "Noto Sans", "SimHei", "Microsoft YaHei", sans-serif;
    font-size: 120px; /* adjust as needed */
    color: #0078d7;
    position: relative;
}

.circular-inner {
    position: absolute;
    width: 30%;
    height: 30%;
    background: rgba(255, 100, 100, 0.5); /* 50% opacity red */
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: "Noto Sans", "SimHei", "Microsoft YaHei", sans-serif;
    font-size: 48px; /* scaled to fit inner circle */
    color: #a00;
    z-index: 2;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}

.circular-outer-character,
.circular-inner-character {
    font-weight: bold;
}

.circular-outer-image,
.circular-inner-image {
    width: 80%;
    height: 80%;
    object-fit: contain;
    border-radius: 50%;
}

.circular-full-character {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 140px;
    font-weight: bold;
    color: rgba(0, 0, 0, 0.3);
    z-index: 3;
    pointer-events: none;
}

.circular-warning {
    position: absolute;
    bottom: 10px;
    left: 10px;
    right: 10px;
    background: rgba(255, 204, 0, 0.9);
    padding: 8px;
    border-radius: 4px;
    font-size: 12px;
    text-align: center;
    z-index: 10;
}

/* Responsive adjustments for circular enclosure */
@media (max-width: 768px) {
    .circular-enclosure {
        width: 250px;
        height: 250px;
    }
    
    .circular-outer {
        font-size: 100px;
    }
    
    .circular-inner {
        font-size: 40px;
    }
    
    .circular-full-character {
        font-size: 120px;
    }
}

@media (max-width: 480px) {
    .circular-enclosure {
        width: 200px;
        height: 200px;
    }
    
    .circular-outer {
        font-size: 80px;
    }
    
    .circular-inner {
        font-size: 32px;
    }
    
    .circular-full-character {
        font-size: 100px;
    }
}