/* ===== RESET & BASE ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #333;
    background: #f5f5f5;
}

.level-1 { margin-left: 0; }
.level-2 { margin-left: 1rem; }
.level-3 { margin-left: 2rem; }
.level-4 { margin-left: 3rem; }
.level-5 { margin-left: 4rem; }

/* ===== HEADER WITH INTEGRATED NAVIGATION ===== */
.header {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    color: white;
    padding: 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1001;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

.header h1 {
    font-size: 1.8rem;
    margin-bottom: 1rem;
    text-align: center;
    cursor: pointer;
}

/* ===== SEARCH ===== */
.search-container {
    max-width: 600px;
    margin: 0 auto 1rem;
    position: relative;
}

#searchBox {
    width: 100%;
    padding: 0.8rem 3rem 0.8rem 1rem;
    font-size: 1rem;
    border: none;
    border-radius: 25px;
    outline: none;
}

.clear-search {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #999;
    cursor: pointer;
    padding: 0 10px;
}

.clear-search:hover {
    color: #333;
}

/* ===== MATCH NAVIGATION ===== */
.match-navigation {
    max-width: 600px;
    margin: 0.5rem auto;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
}

.match-btn {
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.match-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.match-counter {
    color: white;
    font-size: 0.9rem;
    min-width: 60px;
    text-align: center;
}

.highlight.current-match {
    background-color: #ff9800;
    font-weight: bold;
    padding: 2px 4px;
    border-radius: 3px;
}

/* ===== VISIBILITY OPTIONS ===== */
.visibility-options {
    max-width: 600px;
    margin: 0.5rem auto 0.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.checkbox-option {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    cursor: pointer;
}

.checkbox-option input[type="checkbox"] {
    cursor: pointer;
}

.checkbox-option span {
    user-select: none;
    color: white;
    font-size: 0.9rem;
}

/* ===== INTEGRATED NAVIGATION ===== */
.nav-container {
    margin-top: 0.5rem;
    max-width: 1080px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 1rem;
    padding-right: 1rem;
}

.nav-menu {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-in-out, opacity 0.3s ease-in-out, padding 0.3s ease-in-out, border 0.3s ease-in-out;
    opacity: 0;
    padding: 0;
    border-top: none;
}

.nav-menu.collapsed {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    padding: 0;
    border-top: none;
}

.nav-menu:not(.collapsed) {
    max-height: 500px;
    opacity: 1;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
    border-top: 1px solid rgba(255,255,255,0.3);
}

.nav-menu a {
    padding: 0.4rem 0.8rem;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    text-decoration: none;
    border-radius: 20px;
    font-size: 0.85rem;
    transition: all 0.3s;
    border: 1px solid rgba(255, 255, 255, 0.2);
    white-space: nowrap;
}

.nav-menu a:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.nav-menu a.quick-ref {
    background: #e67e22;
    border-color: #d35400;
}

.nav-menu a.quick-ref:hover {
    background: #d35400;
}

/* ===== RESPONSIVE NAVIGATION ===== */
@media (max-width: 768px) {
    .header {
        padding: 1rem;
    }
    
    .header h1 {
        font-size: 1.5rem;
        margin-bottom: 0.8rem;
    }
    
    .search-container {
        margin-bottom: 0.8rem;
    }
    
    .nav-menu a {
        font-size: 0.8rem;
        padding: 0.35rem 0.6rem;
    }
}

@media (max-width: 480px) {
    .visibility-options {
        gap: 0.5rem;
    }
    
    .nav-menu a {
        font-size: 0.75rem;
        padding: 0.3rem 0.5rem;
    }
}

/* ===== CONTAINER & LAYOUT ===== */
.container {
    max-width: 1080px;
    margin: 0 auto;
    padding: 2rem;
    background: white;
    min-height: calc(100vh - 120px);
}

/* ===== SECTIONS ===== */
.section {
    margin-bottom: 2rem;
    padding: 1.5rem;
    border-left: 4px solid #3498db;
    background: #f8f9fa;
    border-radius: 4px;
    scroll-margin-top: 150px;
}

.section.hidden {
    display: none !important;
}

.subsection {
    margin-left: 1.5rem;
    margin-top: 0.5rem;
}

/* ===== TYPOGRAPHY ===== */
.section h2 {
    color: #2c3e50;
    margin-bottom: 1rem;
    font-size: 1.5rem;
}

.section h3 {
    color: #34495e;
    margin: 1.5rem 0 0.5rem 0;
    font-size: 1.2rem;
}

.section h4,
.subsection h4 {
    color: #333;
    margin: 1rem 0 0.5rem 0;
    font-size: 1.1rem;
    font-weight: 600;
}

.section h5,
.subsection h5 {
    color: #333;
    margin: 1rem 0 0.5rem 0;
    font-size: 1rem;
    font-weight: 600;
}

.section p {
    margin: 0.5rem 0;
}

.rule-number {
    color: #7f8c8d;
    font-weight: bold;
    margin-right: 0.5rem;
}

ul, ol {
    margin-left: 2rem;
    margin-top: 0.5rem;
}

li {
    margin: 0.3rem 0;
}

/* ===== COLLAPSIBLE HEADERS ===== */
.section h2,
.section h3,
.section h4,
.section h5 {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-left: 1.5rem;
}

.section h2::before {
    content: "▼";
    position: absolute;
    left: 0;
    top: 4px;
    font-size: 0.8em;
    transition: transform 0.2s;
    color: #7f8c8d;
}

.section h3::before,
.section h4::before,
.section h5::before {
    content: "▼";
    position: absolute;
    left: 0;
    top: 2px;
    font-size: 0.8em;
    transition: transform 0.2s;
    color: #7f8c8d;
}

.section h2.collapsed::before,
.section h3.collapsed::before,
.section h4.collapsed::before,
.section h5.collapsed::before {
    transform: rotate(-90deg);
}

.section h2:hover,
.section h3:hover,
.section h4:hover,
.section h5:hover {
    color: #3498db;
}

.rule-content {
    overflow: hidden;
    transition: max-height 0.3s ease-out, opacity 0.3s ease-out;
    max-height: 50000px; /* Very large value to accommodate all content */
}

.rule-content.collapsed {
    max-height: 0 !important;
    opacity: 0;
}

/* ===== COMPONENTS ===== */
.icon {
    display: inline-block;
    height: 1.2em;
    width: 1.2em;
    vertical-align: middle;
    margin: 0 2px;
}

.table-wrapper {
    overflow-x: auto;
    margin: 1rem 0;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    table-layout: auto;
}

th, td {
    border: 1px solid #ddd;
    padding: 0.8rem;
    text-align: center;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

th {
    background: #34495e;
    color: white;
    font-weight: bold;
    white-space: normal;
    line-height: 1.3;
    min-width: 60px;
}

tr:nth-child(even) {
    background: #f9f9f9;
}

/* Mobile table improvements */
@media (max-width: 768px) {
    th, td {
        padding: 0.5rem 0.25rem;
        font-size: 0.85rem;
    }
    
    th {
        font-size: 0.75rem;
        padding: 0.5rem 0.2rem;
        line-height: 1.2;
    }
}

@media (max-width: 480px) {
    th, td {
        padding: 0.4rem 0.15rem;
        font-size: 0.8rem;
    }
    
    th {
        font-size: 0.7rem;
        padding: 0.4rem 0.1rem;
    }
}

.note {
    background: #fff3cd;
    border-left: 4px solid #ffc107;
    padding: 1rem;
    margin: 1rem 0;
}

.no-results {
    text-align: center;
    padding: 3rem;
    color: #7f8c8d;
    font-size: 1.2rem;
    display: none;
}

.no-results.show {
    display: block;
}

/* ===== ICON GRID ===== */
.icon-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
    margin: 1.5rem 0;
}

.icon-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.7rem;
    background: #f8f9fa;
    border-radius: 6px;
    font-size: 0.9rem;
}

.icon-item .icon {
    flex-shrink: 0;
}

/* ===== QUICK REFERENCE SPACING ===== */
.note h4 {
    margin-top: 1.5rem;
    margin-bottom: 0.8rem;
}

.note h4:first-child {
    margin-top: 0;
}

.note ol {
    margin-bottom: 1.2rem;
}

.note p {
    margin-bottom: 1.2rem;
}

/* ===== CLARIFICATION BOXES ===== */
.clarification {
    background: linear-gradient(135deg, #e3f2fd 0%, #f8f9ff 100%);
    border-left: 4px solid #2196f3;
    margin: 1rem 0;
    padding: 1rem;
    border-radius: 0 8px 8px 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: relative;
}

.clarification .box-header {
    font-size: 0.8rem;
    font-weight: bold;
    color: #1976d2;
    display: block;
    margin-bottom: 0.5rem;
    font-style: normal;
}

.clarification strong {
    display: block;
    font-style: normal;
    font-size: 1.05em;
    margin-bottom: 0.5rem;
    color: #1565c0;
}

.clarification > span {
    font-style: normal;
}

.clarification p {
    font-style: normal;
}

.clarification ul,
.clarification ol {
    margin-left: 2.5rem;
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
    font-style: normal;
}

.clarification li {
    margin: 0.4rem 0;
    font-style: normal;
}

.clarification .source-info {
    margin-top: 0.8rem;
    padding-top: 0.8rem;
    border-top: 1px solid rgba(33, 150, 243, 0.2);
    font-size: 0.85em;
    font-style: normal;
    opacity: 0.8;
}

.clarification .source-info a {
    color: inherit;
    text-decoration: none;
    display: inline-block;
    transition: opacity 0.2s;
}

.clarification .source-info a:hover {
    opacity: 1;
}

.strategy-tip {
    background: linear-gradient(135deg, #f3e5f5 0%, #faf8ff 100%);
    border-left: 4px solid #9c27b0;
    margin: 1rem 0;
    padding: 1rem;
    border-radius: 0 8px 8px 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    font-style: italic;
}

.strategy-tip::before {
    content: "🎯 Strategy Tip";
    font-size: 0.8rem;
    font-weight: bold;
    color: #7b1fa2;
    display: block;
    margin-bottom: 0.5rem;
    font-style: normal;
}

.timing-note {
    background: linear-gradient(135deg, #fff3e0 0%, #fffef7 100%);
    border-left: 4px solid #ff9800;
    margin: 1rem 0;
    padding: 1rem;
    border-radius: 0 8px 8px 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    font-style: italic;
}

.timing-note .box-header {
    font-size: 0.8rem;
    font-weight: bold;
    color: #f57c00;
    display: block;
    margin-bottom: 0.5rem;
    font-style: normal;
}

/* ===== VISIBILITY TOGGLES ===== */
body.hide-clarifications .clarification {
    display: none !important;
}

body.hide-strategy-tips .strategy-tip {
    display: none !important;
}

/* ===== UTILITY CLASSES ===== */
.highlight {
    background-color: yellow;
    font-weight: bold;
    padding: 2px 0;
}

.hidden {
    display: none !important;
}

a.rule-ref {
    color: #0066cc;
    text-decoration: underline;
    cursor: pointer;
}

a.rule-ref:hover {
    text-decoration: none;
}