:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --radius: 12px;
}

[data-theme="dark"] {
    --bg-main: #020617;
    --bg-card: #0f172a;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: #1e293b;
    --primary: #3b82f6;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    transition: background-color 0.3s, color 0.3s;
}

header {
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 1.5rem 2rem;
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    transition: transform 0.3s ease-in-out;
}

.header-hidden {
    transform: translateY(-100%);
}

.logo {
    font-weight: 800;
    font-size: 2rem;
    color: var(--primary);
    text-decoration: none;
    display: flex;
    align-items: center;
}

.logo img {
    height: 60px;
    width: auto;
    display: block;
}

.search-container {
    flex: 1;
    max-width: 600px;
    position: relative;
}

.search-input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 3rem;
    border: 1px solid var(--border);
    border-radius: 99px;
    background-color: var(--bg-main);
    color: var(--text-main);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.search-input:focus {
    border-color: var(--primary);
}

.main-container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1rem;
}

.hero {
    text-align: center;
    margin-bottom: 3rem;
}

.hero h1 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
}

.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.5rem;
}

.category-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    padding: 1.5rem;
    border-radius: var(--radius);
    text-decoration: none;
    color: inherit;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.75rem;
}

.category-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow);
    border-color: var(--primary);
}

.category-card-icon {
    font-size: 2rem;
}

.category-card-name {
    font-weight: 600;
    font-size: 1.1rem;
}

.footer {
    border-top: 1px solid var(--border);
    padding: 3rem 1rem;
    margin-top: 4rem;
    text-align: center;
    color: var(--text-muted);
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.footer-links a {
    color: var(--text-muted);
    text-decoration: none;
}

.footer-links a:hover {
    color: var(--primary);
}

/* Modal / Results */
.conversion-result-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    margin-bottom: 2rem;
    margin-top: 1.5rem;
    text-align: center;
}

.result-value {
    font-size: 3rem;
    font-weight: 800;
    color: var(--primary);
}

/* Segmented Radial Menu - SVG */
.radial-menu-wrapper {
    position: relative;
    width: 100%;
    display: flex;
    justify-content: center;
    margin: 0;
    overflow: visible;
    min-height: 95vh;
    /* Maximize vertical space */
    align-items: center;
}

#radial-menu-mount {
    width: 95vh;
    height: 95vh;
    max-width: 95vw;
    /* Ensure it fits horizontally */
    max-height: 95vw;
    position: relative;
    transition: width 0.3s, height 0.3s;
}

.radial-svg {
    width: 100%;
    height: 100%;
    overflow: visible;
}

.slice-path {
    fill: var(--bg-card);
    stroke: var(--bg-main);
    stroke-width: 2px;
    cursor: pointer;
    transition: fill 0.3s, transform 0.2s;
    transform-origin: center;
}

.slice-path:hover {
    fill: var(--primary);
    transform: scale(1.02);
    z-index: 10;
}

/* Text and Icons on top of SVG */
.slice-content {
    pointer-events: none;
    /* Let clicks pass to the path */
    text-anchor: middle;
    fill: var(--text-main);
    /* font-size removed */
    font-family: var(--font-main);
    /* Ensure consistent font */
    font-weight: 600;
    transition: fill 0.3s;
}

.slice-path:hover+.slice-content,
.slice-group:hover .slice-content {
    fill: white;
}

.center-dial {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 25%;
    /* Slightly larger to let logo breathe */
    height: 25%;
    background: transparent;
    /* No background */
    border-radius: 50%;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
    /* No shadow */
    border: none;
    /* No border */
    pointer-events: none;
}

.center-logo {
    width: 100%;
    /* Fill the container */
    height: 100%;
    object-fit: contain;
    pointer-events: none;
    background: transparent;
}

/* Center text removed */

/* Submenu SVG styles */
.submenu-path {
    fill: var(--bg-card);
    stroke: var(--bg-main);
    stroke-width: 1px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.3s, fill 0.2s;
}

.submenu-text {
    fill: var(--text-main);
    /* font-size removed to let SVG attribute control it */
    pointer-events: none;
    text-anchor: middle;
    opacity: 0;
    transition: opacity 0.3s;
}

.slice-group:hover .submenu-path,
.slice-group:hover .submenu-text {
    opacity: 1;
}

.submenu-path:hover {
    fill: var(--primary);
}

.submenu-path:hover+.submenu-text {
    fill: white;
}

@media (max-width: 768px) {
    .radial-menu-wrapper {
        min-height: auto;
        height: auto;
        margin: 2rem 0;
    }

    #radial-menu-mount {
        width: 95vw;
        height: 95vw;
        max-width: 500px;
        max-height: 500px;
    }

    .center-dial {
        border-width: 6px;
    }

    .center-text {
        font-size: 1.2rem;
    }

    .slice-content {
        font-size: 0.8rem;
    }
}

/* Inner Submenu Ring */
.submenu-ring {
    position: fixed;
    /* Fixed helps z-index, but absolute to menu is better */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    /* Centered */
    width: 700px;
    /* Outer radius */
    height: 700px;
    pointer-events: none;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.3s;
}

.radial-segment:hover .submenu-ring {
    opacity: 1;
    pointer-events: auto;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .radial-menu {
        width: 340px;
        height: 340px;
    }

    .center-dial {
        width: 80px;
        height: 80px;
        font-size: 0.9rem;
    }

    .radial-segment {
        width: 170px;
        height: 170px;
    }

    .radial-icon {
        font-size: 1.2rem;
    }

    .radial-text {
        font-size: 0.6rem;
    }
}

.submenu-fan {
    opacity: 0;
    transform: translate(-10px, -50%) !important;
    transition: all 0.3s ease;
    pointer-events: none;
}

.radial-link:hover .submenu-fan {
    opacity: 1;
    transform: translate(0, -50%) !important;
    pointer-events: auto;
}

/* Fan/Nested Radial Menu Styles */
.radial-menu-container {
    position: relative;
    width: 600px;
    height: 600px;
    margin: 4rem auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.radial-item-wrapper {
    position: absolute;
    width: 120px;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.category-card.radial-item {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    z-index: 5;
    background: var(--bg-card);
    display: flex;
    flex-direction: column;
    padding: 0;
    font-size: 0.8rem;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: transform 0.3s, border-color 0.2s, box-shadow 0.3s;
}

.radial-item-wrapper:hover .category-card.radial-item {
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(37, 99, 235, 0.3);
}

.submenu-container {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.radial-item-wrapper:hover .submenu-container {
    opacity: 1;
    pointer-events: auto;
}

.submenu-item {
    position: absolute;
    width: 60px;
    height: 60px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
    text-decoration: none;
    color: var(--text-main);
    box-shadow: var(--shadow);
    transition: transform 0.4s ease, background 0.2s;
}

.submenu-item:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

@media (max-width: 768px) {
    .radial-menu-container {
        width: 350px;
        height: 350px;
    }

    .radial-item-wrapper {
        width: 80px;
        height: 80px;
    }

    .category-card.radial-item {
        width: 70px;
        height: 70px;
    }

    .submenu-item {
        width: 45px;
        height: 45px;
        font-size: 0.6rem;
    }
}



.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
    text-decoration: none;
    margin-bottom: 1.5rem;
    font-weight: 500;
    transition: color 0.2s;
}

.back-link:hover {
    color: var(--primary);
}

.converter-title {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.converter-row {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1.5rem;
}

.converter-row input,
.converter-row select {
    flex: 1;
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    font-size: 1.25rem;
    background: var(--bg-main);
    color: var(--text-main);
    outline: none;
    transition: border-color 0.2s;
}

.converter-row input:focus,
.converter-row select:focus {
    border-color: var(--primary);
}

.swap-btn-container {
    display: flex;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.swap-btn {
    background: var(--primary);
    color: white;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    transition: background-color 0.2s, transform 0.2s;
}

.swap-btn:hover {
    background: var(--primary-hover);
    transform: scale(1.1);
}

/* Mobile Optimizations */
@media (max-width: 768px) {

    /* Header */
    header {
        padding: 1rem;
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .logo {
        justify-content: center;
        font-size: 1.75rem;
    }

    .search-container {
        max-width: 100%;
    }

    /* Main Content */
    .main-container {
        margin: 1.5rem auto;
        padding: 0 1rem;
    }

    .hero h1 {
        font-size: 2rem;
    }

    /* Converters */
    .converter-title {
        font-size: 1.75rem;
        justify-content: center;
        text-align: center;
    }

    .converter-row {
        flex-direction: column;
        gap: 0.75rem;
    }

    .swap-btn-container {
        margin: 0.5rem 0;
    }

    .swap-btn {
        transform: rotate(90deg);
        /* Rotate for vertical flow */
    }

    .swap-btn:hover {
        transform: rotate(90deg) scale(1.1);
    }

    .conversion-result-card {
        padding: 1.5rem;
    }

    .result-value {
        font-size: 2.25rem;
    }

    /* Footer */
    .footer {
        padding: 2rem 1rem;
        margin-top: 2rem;
    }

    .footer-links {
        flex-direction: column;
        gap: 1rem;
    }
}

/* PWA Install Prompt */
.install-prompt {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 -4px 6px -1px rgb(0 0 0 / 0.1);
    z-index: 1000;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

.install-content {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.install-icon {
    font-size: 2rem;
}

.install-text {
    display: flex;
    flex-direction: column;
    font-size: 0.9rem;
}

.install-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 99px;
    font-weight: 600;
    cursor: pointer;
    margin-right: 0.5rem;
}

.close-install {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 0.5rem;
}