/* ---- App Logo Overlay ---- */
#app-logo-overlay {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1000;
    pointer-events: none;
    display: none;
}

body.radial-ui-active #app-logo-overlay {
    display: block;
}

#app-logo-overlay img {
    height: 40px;
    width: auto;
}

/* Mobile Layout for App Logo */
@media (max-width: 768px) {
    #app-logo-overlay {
        left: 50%;
        transform: translateX(-50%) scale(1.3);
        transform-origin: top center;
        top: 15px;
    }
}

/* ================================
   RADIAL MENU
================================ */

/* Hide sidebar/topbar when radial is active - High Specificity */
body.radial-ui-active aside.sidebar,
body.radial-ui-active .sidebar {
    display: none !important;
}

body.radial-ui-active header.topbar,
body.radial-ui-active .topbar {
    display: none !important;
}

/* Force Logo to FILL and OVERFLOW the button circle */
.rm-hub-btn img {
    width: 150% !important;
    height: 150% !important;
    max-width: 150% !important;
    max-height: 150% !important;
    border-radius: 50%;
    object-fit: cover;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

/* MENU label below hub button */
.rm-hub-label {
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    color: #00A8FF;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 2px;
    pointer-events: none;
    text-shadow: 0 0 8px rgba(0, 168, 255, 0.4);
    white-space: nowrap;
}


body.radial-ui-active .app {
    height: 100vh;
}

/* ---- Container ---- */
#radial-menu-container {
    position: fixed;
    /* Initial Position defaults (overridden by JS) */
    left: 50%;
    top: 85%;
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: width 0.3s, height 0.3s;
    /* Only animate size, pos is driven by drag */
    pointer-events: none;
    /* Hub/SVG inside will have pointer-events: auto */
}

/* ---- Closed: Hub button ---- */
.rm-hub-btn {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    border: 2px solid rgba(0, 168, 255, 0.5);
    background: radial-gradient(circle, #2a2a2a 0%, #1a1a1a 100%);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 0 15px rgba(0, 168, 255, 0.3);
    transition: transform 0.2s, box-shadow 0.2s;
    pointer-events: auto;

    /* Centering content */
    display: flex;
    align-items: center;
    justify-content: center;
    /* Pulse Animation */
    animation: bluePulse 2s infinite;
}

.rm-hub-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 25px rgba(0, 168, 255, 0.6);
    border-color: rgba(0, 168, 255, 0.5);
}

.rm-hub-btn:active {
    transform: scale(0.95);
}



#radial-menu-container {
    /* Default state: visible (Hub Button) */
    position: fixed;
    /* Initial Position defaults (overridden by JS) */
    left: 50%;
    top: 85%;
    z-index: 100000;
    /* Ensure it is ALWAYS on top of drop zones/overlays */
    display: flex;
    justify-content: center;
    align-items: center;
    transition: width 0.2s ease, height 0.2s ease;
    pointer-events: none;
    /* Let background 3D canvas receive touches */
}

#radial-menu-container.open {
    /* JS Handles positioning now via top/left */
    /* Just ensure size is correct */
    width: 500px;
    height: 500px;
}

/* Container transition handled by JS positioning/sizing */

#radial-menu-container {
    /* ... existing positioning ... */
    /* Remove transition on width/height to avoid layout jank if we rely on JS positioning */
    transition: none;
}

/* Animate the SVG contents on entry */
.rm-svg {
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
    /* Revert to default interactivity */

    /* Animation defaults */
    transform-origin: 250px 250px;
}

.rm-svg.animate-open {
    animation: menu-pop 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes menu-pop {
    0% {
        transform: scale(0.2);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Hub pulsing - keep existing */


/* ---- Slice interactions ---- */
.rm-slice {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    pointer-events: auto;
}


.rm-slice path {
    transition: all 0.2s ease;
    transform-origin: 250px 250px;
}

/* Hover: Lift effect */
.rm-slice:hover path {
    filter: brightness(1.05);
    transform: scale(1.02);
}

/* Active: No scale effect for individual slices (flat feel) */


/* ---- Hub Hover Effects (Close Button) ---- */
.rm-hub {
    pointer-events: auto;
}

.rm-hub:hover .hub-close-icon {
    opacity: 1;
    transition: opacity 0.2s;
}

/* ---- Mobile Scaling ---- */
@media (max-width: 768px) {

    /* Since we use JS positioning, we just scale the whole container */

    /* Mobile Quality Card - Simplified (Square like screenshot) */
    .rm-qp-card {
        padding: 4px;
        /* Tight padding */
        gap: 2px;
        flex-direction: column;
        justify-content: center;
        text-align: center;
        width: 100%;
        /* Fill parent */
        box-sizing: border-box;
        /* Include padding in width */
        background: rgba(30, 30, 30, 0.8);
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 8px;
    }

    .rm-qp-card:hover {
        transform: none;
    }

    .rm-qp-card img {
        width: 45px;
        /* Larger relative to card */
        height: 45px;
        margin: 0 auto;
    }

    .rm-qp-info {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0;
    }

    .rm-qp-info strong {
        font-size: 13px;
        color: #eee;
        display: block;
        /* Ensure it shows */
    }

    .rm-qp-info span {
        display: none;
        /* Hide 'Medium', 'Low' label */
    }

    /* Panel Sizing */
    .rm-side-panel {
        padding: 8px;
        font-size: 13px;
        background: rgba(20, 20, 20, 0.95);
    }

    .rm-side-panel.material {
        min-width: 160px;
        /* Restore width for text */
        width: auto;
    }

    .rm-side-panel.quality {
        /* Handled by mobile override at bottom of file */
        width: auto;
    }

    .rm-sp-item {
        padding: 8px;
    }
}

/* Smart Positioning Zones (Mobile) - Center Relative (Radius 110px + Gap) */
/* Right Middle */
.rm-side-panel.pos-right-mid {
    left: 50%;
    margin-left: 125px;
    top: 50%;
    transform: translateY(-50%);
}

/* Left Middle */
.rm-side-panel.pos-left-mid {
    left: auto;
    right: 50%;
    margin-right: 125px;
    top: 50%;
    transform: translateY(-50%);
}

/* Top Middle */
.rm-side-panel.pos-top-mid {
    top: auto;
    bottom: 50%;
    margin-bottom: 125px;
    left: 50%;
    transform: translateX(-50%);
}

/* Bottom Middle */
.rm-side-panel.pos-btm-mid {
    top: 50%;
    margin-top: 125px;
    left: 50%;
    transform: translateX(-50%);
}

/* Corners (Offset ~90px => Distance ~127px) */
.rm-side-panel.pos-left-top {
    left: auto;
    right: 50%;
    margin-right: 90px;
    top: auto;
    bottom: 50%;
    margin-bottom: 90px;
    transform: none;
}

.rm-side-panel.pos-left-btm {
    left: auto;
    right: 50%;
    margin-right: 90px;
    top: 50%;
    margin-top: 90px;
    transform: none;
}

.rm-side-panel.pos-right-top {
    left: 50%;
    margin-left: 90px;
    top: auto;
    bottom: 50%;
    margin-bottom: 90px;
    transform: none;
}

.rm-side-panel.pos-right-btm {
    left: 50%;
    margin-left: 90px;
    top: 50%;
    margin-top: 90px;
    transform: none;
}


/* ---- L1 Ring Animation (Spin and Expand) ---- */
@keyframes rm-ring-l1-in {
    0% {
        opacity: 0;
        transform: scale(0.5) rotate(-30deg);
        filter: blur(5px);
    }

    60% {
        transform: scale(1.05) rotate(5deg);
        opacity: 1;
        filter: blur(0);
    }

    100% {
        transform: scale(1) rotate(0deg);
    }
}

.level-1 {
    transform-origin: 250px 250px;
    /* animation: rm-ring-l1-in 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) both; */
    /* Stagger animations based on index */
    /* animation-delay: calc(var(--i) * 0.05s); */
}

/* ---- L2 Ring "Fan Out" Animation ---- */
@keyframes fan-out {
    from {
        opacity: 0;
        transform: scale(0.8);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.rm-ring-l2 {
    transform-origin: 250px 250px;
    /* animation: fan-out 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) both; */
}

/* Hub Pulse for Active State */
@keyframes bluePulse {
    0% {
        box-shadow: 0 0 0 0 rgba(0, 168, 255, 0.7);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(0, 168, 255, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(0, 168, 255, 0);
    }
}

/* ---- Guided Highlight Pulse ---- */
@keyframes guidedPulse {
    0% {
        stroke: #00A8FF;
        stroke-width: 2px;
        filter: drop-shadow(0 0 0 rgba(0, 168, 255, 0));
    }

    50% {
        stroke: #00A8FF;
        stroke-width: 4px;
        filter: drop-shadow(0 0 8px rgba(0, 168, 255, 0.8));
    }

    100% {
        stroke: #00A8FF;
        stroke-width: 2px;
        filter: drop-shadow(0 0 0 rgba(0, 168, 255, 0));
    }
}

.guided-pulse path {
    animation: guidedPulse 1.5s infinite ease-in-out;
    stroke: #00A8FF !important;
    /* Force override */
    stroke-opacity: 1 !important;
}

/* ================================
   SIDE PANELS (Material/Quality)
================================ */
.rm-side-panel {
    position: absolute;
    /* Center (250) + L1 (110) + Gap = ~380px. */
    left: 380px;
    top: 50%;
    transform: translateY(-50%);
    width: 260px;
    background: rgba(30, 30, 30, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
    padding: 16px;
    z-index: 100;
    /* Above SVG */
    animation: panel-in 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    pointer-events: auto;
    /* Essential since container is none */
    display: flex;
    flex-direction: column;
    gap: 12px;
}

body.light-mode .rm-side-panel {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(0, 0, 0, 0.1);
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}

/* Panel Header */
.rm-sp-header {
    font-size: 14px;
    font-weight: 700;
    color: #ccc;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 8px;
    display: none;
    margin-bottom: 4px;
}

body.light-mode .rm-sp-header {
    color: #555;
    border-bottom-color: rgba(0, 0, 0, 0.1);
}

/* Scrollable List (Material) */
.rm-sp-list {
    max-height: 320px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-right: 4px;
    /* Space for scrollbar */
}

/* List Item */
.rm-sp-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

body.light-mode .rm-sp-item {
    background: rgba(0, 0, 0, 0.03);
}

body.light-mode .rm-sp-item:hover {
    background: rgba(24, 144, 255, 0.1);
    border-color: #1890ff;
}

.rm-sp-item:hover {
    background: rgba(0, 168, 255, 0.15);
    border-color: rgba(0, 168, 255, 0.3);
    transform: translateX(4px);
}

.rm-sp-label {
    font-size: 14px;
    color: #fff;
    font-weight: 500;
}

body.light-mode .rm-sp-label {
    color: #333;
}

.rm-sp-price {
    font-size: 12px;
    color: #888;
}

/* Quality Panel Container (Grid/Flex) */
.rm-qp-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Quality Card */
.rm-qp-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: all 0.2s;
}

body.light-mode .rm-qp-card {
    background: rgba(0, 0, 0, 0.03);
    border-color: rgba(0, 0, 0, 0.1);
}

body.light-mode .rm-qp-card:hover {
    background: rgba(0, 0, 0, 0.08);
}

.rm-qp-card.selected {
    background: rgba(0, 168, 255, 0.15);
    border-color: #00A8FF;
    box-shadow: 0 0 15px rgba(0, 168, 255, 0.1);
}

.rm-qp-card:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.02);
}

.rm-qp-card img {
    width: 48px;
    height: 48px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.rm-qp-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.rm-qp-info strong {
    font-size: 18px;
    color: #fff;
    font-weight: 700;
}

body.light-mode .rm-qp-info strong {
    color: #333;
}

.rm-qp-info span {
    font-size: 13px;
    color: #aaa;
}

@keyframes panel-in {
    from {
        opacity: 0;
        transform: translateY(-50%) translateX(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(-50%) translateX(0);
    }
}

/* Scrollbar styling for list */
.rm-sp-list::-webkit-scrollbar {
    width: 6px;
}

.rm-sp-list::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.rm-sp-list::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 3px;
}

.rm-sp-list::-webkit-scrollbar-thumb:hover {
    background: #777;
}

/* ---- Mobile Fixes & Smart Positioning Override ---- */
@media (max-width: 768px) {

    /* Force Panel Sizing & Background Reset */
    .rm-side-panel {
        /* Reset background to theme defaults if possible, or force dark/light */
        background-color: #ffffff !important;
        color: #333333 !important;
    }

    /* Dark Mode Override for Panel */
    body:not(.light-mode) .rm-side-panel {
        background-color: rgba(20, 20, 20, 0.95) !important;
        color: #eee !important;
    }

    .rm-side-panel.material {
        min-width: 160px !important;
        width: auto !important;
    }

    .rm-side-panel.quality {
        width: 80px !important;
        /* Force exact width */
        min-width: 0 !important;
        padding: 4px !important;
        box-sizing: border-box;
        /* Include padding */
        display: flex;
        flex-direction: column;
        align-items: stretch;
        /* Stretch children to fill 80px */
    }

    /* Hide Header in Quality Panel on Mobile */
    .rm-side-panel.quality .rm-sp-header {
        display: none !important;
    }

    /* Force Positioning logic with !important */
    /* Right Middle */
    .rm-side-panel.pos-right-mid {
        left: 50% !important;
        margin-left: 125px !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
    }

    /* Left Middle */
    .rm-side-panel.pos-left-mid {
        left: auto !important;
        right: 50% !important;
        margin-right: 125px !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
    }

    /* Top Middle */
    .rm-side-panel.pos-top-mid {
        top: auto !important;
        bottom: 50% !important;
        margin-bottom: 125px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
    }

    /* Bottom Middle */
    .rm-side-panel.pos-btm-mid {
        top: 50% !important;
        margin-top: 125px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
    }

    /* Corners */
    .rm-side-panel.pos-left-top {
        left: auto !important;
        right: 50% !important;
        margin-right: 90px !important;
        top: auto !important;
        bottom: 50% !important;
        margin-bottom: 90px !important;
        transform: none !important;
    }

    .rm-side-panel.pos-left-btm {
        left: auto !important;
        right: 50% !important;
        margin-right: 90px !important;
        top: 50% !important;
        margin-top: 90px !important;
        transform: none !important;
    }

    .rm-side-panel.pos-right-top {
        left: 50% !important;
        margin-left: 90px !important;
        top: auto !important;
        bottom: 50% !important;
        margin-bottom: 90px !important;
        transform: none !important;
    }

    .rm-side-panel.pos-right-btm {
        left: 50% !important;
        margin-left: 90px !important;
        top: 50% !important;
        margin-top: 90px !important;
        transform: none !important;
    }
}