:root {
    --primary-color: #2c3e50;
    --accent-color: #3498db;
    --bg-color: #f4f7f6;
    --card-bg: #ffffff;
    --text-color: #333;
    --border-color: #e0e0e0;
}

* {
    box-sizing: border-box;
}

body {
    font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
    font-size: 14px;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: var(--primary-color);
    color: white;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #1a252f;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 15px;
    background-color: #1a252f;
}

.sidebar-header h1 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: 1px;
}

.search-box {
    padding: 10px;
    background-color: #34495e;
}

.search-box input {
    width: 100%;
    padding: 8px;
    border-radius: 4px;
    border: none;
    background-color: #ecf0f1;
    color: #333;
    font-size: 0.9rem;
}

#category-nav {
    flex: 1;
    overflow-y: auto;
    padding: 5px 0;
}

/* Navigation Items */
.nav-item {
    padding: 10px 15px;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 0.9rem;
    border-left: 4px solid transparent;
    font-weight: bold;
}

.nav-item:hover {
    background-color: #34495e;
}

.nav-item.active {
    background-color: #2980b9;
    border-left-color: #3498db;
}

/* Category Header */
.nav-category-header {
    padding: 10px 15px;
    cursor: pointer;
    background-color: #2c3e50;
    font-weight: bold;
    border-bottom: 1px solid #34495e;
    color: #ecf0f1;
    transition: background 0.2s;
    font-size: 0.9rem;
}

.nav-category-header:hover {
    background-color: #34495e;
}

.nav-category-header.active {
    background-color: #34495e;
    color: #3498db;
}

/* Sub Items */
.nav-sub-item {
    padding: 6px 15px 6px 30px;
    cursor: pointer;
    font-size: 0.85rem;
    color: #ffffff;
    transition: all 0.2s;
    border-left: 4px solid transparent;
    opacity: 0.8;
}

.nav-sub-item:hover {
    background-color: #34495e;
    color: white;
    opacity: 1;
}

.nav-sub-item.active {
    background-color: #2980b9;
    border-left-color: #3498db;
    color: white;
    opacity: 1;
}

/* Main Content */
.content-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    scroll-behavior: smooth;
}

/* Formula Card */
.formula-card {
    background-color: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    margin-bottom: 20px;
    padding: 20px;
    border: 1px solid var(--border-color);
    transition: transform 0.2s, border-color 0.3s;
    scroll-margin-top: 10px;
}

.formula-card:hover {
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.formula-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    border-bottom: 2px solid var(--accent-color);
    padding-bottom: 8px;
}

.formula-title {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--primary-color);
    margin: 0;
}

.formula-category-tag {
    background-color: #eef2f7;
    color: #7f8c8d;
    padding: 3px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    background-color: #f8f9fa;
    border-left: 3px solid #95a5a6;
}

.variations-title {
    font-weight: bold;
    margin-bottom: 5px;
    font-size: 0.85rem;
    color: #555;
}

.variation-item {
    margin-bottom: 5px;
    font-size: 1rem;
}

.symbol-legend {
    margin-top: 15px;
}

.legend-title {
    font-weight: bold;
    margin-bottom: 8px;
    font-size: 0.9rem;
    border-bottom: 1px solid #eee;
    padding-bottom: 4px;
}

.symbol-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 5px;
}

.symbol-item {
    display: flex;
    align-items: baseline;
    font-size: 0.85rem;
}

.symbol-math {
    font-weight: bold;
    width: 50px;
    color: var(--primary-color);
}

.symbol-desc {
    color: #666;
    line-height: 1.5;
}

.symbol-reading {
    color: #7f8c8d;
    font-size: 0.75rem;
    margin-left: 4px;
    font-style: italic;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 15px;
    background-color: #1a252f;
    border-top: 1px solid #34495e;
    text-align: center;
    font-size: 0.8rem;
    margin-top: auto;
}

.legal-link {
    color: #ffffff;
    text-decoration: none;
    display: block;
    margin-bottom: 5px;
}

.legal-link:hover {
    color: #bdc3c7;
    text-decoration: underline;
}

.version-info {
    color: #7f8c8d;
    font-size: 0.7rem;
}

/* ========================================
   Mobile Header (hidden on desktop)
   ======================================== */
.mobile-header {
    display: none;
}

.menu-toggle {
    display: none;
}

.hamburger-line {
    display: none;
}

.sidebar-overlay {
    display: none;
}

/* ========================================
   Mobile Responsive Styles
   ======================================== */
@media screen and (max-width: 768px) {
    body {
        overflow: auto;
        height: auto;
    }

    .app-container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    /* Mobile Header */
    .mobile-header {
        display: flex;
        align-items: center;
        background-color: var(--primary-color);
        padding: 12px 15px;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    }

    .mobile-title {
        color: white;
        font-size: 1.1rem;
        margin: 0;
        font-weight: 700;
    }

    /* Hamburger Menu Button */
    .menu-toggle {
        display: flex;
        background: none;
        border: none;
        cursor: pointer;
        padding: 8px;
        margin-right: 12px;
        flex-direction: column;
        justify-content: space-between;
        height: 24px;
        width: 28px;
    }

    .hamburger-line {
        display: block;
        width: 100%;
        height: 3px;
        background-color: white;
        border-radius: 2px;
        transition: transform 0.3s, opacity 0.3s;
    }

    /* Hamburger to X animation */
    .menu-toggle.active .hamburger-line:nth-child(1) {
        transform: translateY(7.5px) rotate(45deg);
    }

    .menu-toggle.active .hamburger-line:nth-child(2) {
        opacity: 0;
    }

    .menu-toggle.active .hamburger-line:nth-child(3) {
        transform: translateY(-7.5px) rotate(-45deg);
    }

    /* Sidebar Overlay */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 1001;
    }

    .sidebar-overlay.active {
        display: block;
    }

    /* Sidebar as slide-in menu */
    .sidebar {
        position: fixed;
        top: 0;
        left: -300px;
        width: 280px;
        height: 100vh;
        z-index: 1002;
        transition: left 0.3s ease;
        overflow-y: auto;
    }

    .sidebar.open {
        left: 0;
    }

    /* Main Content */
    .content-area {
        margin-top: 56px;
        padding: 15px;
        overflow: visible;
    }

    /* Formula Card adjustments */
    .formula-card {
        padding: 15px;
        margin-bottom: 15px;
        scroll-margin-top: 70px;
    }

    .formula-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .formula-title {
        font-size: 1.1rem;
    }

    .formula-category-tag {
        align-self: flex-start;
    }

    /* Symbol grid single column on mobile */
    .symbol-grid {
        grid-template-columns: 1fr;
    }

    .symbol-item {
        flex-wrap: wrap;
    }

    .symbol-math {
        width: auto;
        margin-right: 5px;
    }

    /* MathJax overflow handling */
    .formula-main,
    .variation-item {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Navigation items touch-friendly */
    .nav-item,
    .nav-category-header,
    .nav-sub-item {
        padding: 12px 15px;
    }

    .nav-sub-item {
        padding-left: 30px;
    }
}