/* ===== CSS Variables — Light Minimal Theme ===== */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f7f7f8;
    --bg-tertiary: #ececf1;
    --bg-card: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #444654;
    --text-muted: #8e8ea0;
    --border: #e5e5e5;
    --border-light: #f0f0f0;
    --accent: #10a37f;
    --accent-hover: #0d8a6a;
    --easy: #10a37f;
    --medium: #c97a2d;
    --hard: #e5534b;
    --sidebar-width: 280px;
    --radius: 8px;
    --radius-lg: 12px;
    --transition: all 0.2s ease;
}

/* ===== Reset & Base ===== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.7;
    overflow: hidden;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: var(--transition);
}

a:hover {
    color: var(--accent-hover);
}

/* ===== App Layout ===== */
.app {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100vh;
    z-index: 100;
}

.sidebar-header {
    padding: 16px 16px 10px;
    border-bottom: 1px solid var(--border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--accent);
    border-radius: var(--radius);
    color: #fff;
}

.logo h1 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.logo-sub {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 1px;
}

/* ===== Search ===== */
.search-box {
    padding: 10px 14px;
    position: relative;
}

.search-icon {
    position: absolute;
    left: 26px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 13px;
    opacity: 0.5;
}

.search-box input {
    width: 100%;
    padding: 8px 10px 8px 34px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: var(--transition);
}

.search-box input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.12);
}

.search-box input::placeholder {
    color: var(--text-muted);
}

/* ===== View Tabs ===== */
.view-tabs {
    display: flex;
    padding: 0 14px 10px;
    gap: 4px;
}

.tab {
    flex: 1;
    padding: 6px 4px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.tab:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.tab.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 500;
}

/* ===== Sidebar Content ===== */
.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 6px 10px;
}

.sidebar-content::-webkit-scrollbar {
    width: 4px;
}

.sidebar-content::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

/* Nav Items */
.nav-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 13px;
    transition: var(--transition);
    cursor: pointer;
    text-decoration: none;
    position: relative;
}

.nav-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.nav-item.active {
    background: rgba(16, 163, 127, 0.08);
    color: var(--accent);
    font-weight: 500;
}

.nav-item.completed::after {
    content: '✓';
    position: absolute;
    right: 8px;
    font-size: 11px;
    color: var(--easy);
    font-weight: 700;
}

.nav-id {
    min-width: 26px;
    font-size: 11px;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
}

.nav-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-title-en {
    display: block;
    font-size: 10px;
    color: var(--text-muted);
    font-weight: 400;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-diff {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 500;
    flex-shrink: 0;
}

.diff-easy {
    background: rgba(16, 163, 127, 0.1);
    color: var(--easy);
}

.diff-medium {
    background: rgba(201, 122, 45, 0.1);
    color: var(--medium);
}

.diff-hard {
    background: rgba(229, 83, 75, 0.1);
    color: var(--hard);
}

/* Nav Groups */
.nav-group {
    margin-bottom: 2px;
}

.nav-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
}

.nav-group-header:hover {
    background: var(--bg-tertiary);
}

.nav-group-header .nav-count {
    font-size: 11px;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    padding: 1px 7px;
    border-radius: 10px;
}

.nav-group-items {
    display: none;
    padding-left: 6px;
}

.nav-group.open>.nav-group-items {
    display: block;
}

.nav-group-header::before {
    content: '▸';
    margin-right: 6px;
    font-size: 10px;
    transition: transform 0.2s;
}

.nav-group.open>.nav-group-header::before {
    transform: rotate(90deg);
}

/* ===== Sidebar Footer ===== */
.sidebar-footer {
    padding: 10px 14px 14px;
    border-top: 1px solid var(--border);
}

.progress-bar {
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 5px;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.5s ease;
    width: 0%;
}

.progress-text {
    font-size: 11px;
    color: var(--text-muted);
}

/* ===== Mobile Toggle ===== */
.mobile-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    width: 36px;
    height: 36px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px;
}

.mobile-toggle span {
    display: block;
    width: 16px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 1px;
    transition: var(--transition);
}

/* ===== Main Content ===== */
.content {
    flex: 1;
    overflow-y: auto;
    padding: 32px 48px;
    background: var(--bg-primary);
}

.content::-webkit-scrollbar {
    width: 5px;
}

.content::-webkit-scrollbar-track {
    background: transparent;
}

.content::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

/* ===== Home Page ===== */
.home {
    max-width: 720px;
    margin: 0 auto;
}

.hero {
    text-align: center;
    padding: 48px 0 32px;
}

.hero-title {
    font-size: 36px;
    font-weight: 700;
    margin-bottom: 10px;
    line-height: 1.25;
    color: var(--text-primary);
}

.gradient-text {
    color: var(--accent);
}

.hero-subtitle {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.hero-desc {
    font-size: 14px;
    color: var(--text-muted);
    max-width: 420px;
    margin: 0 auto;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 40px;
}

.stat-card {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 14px;
    text-align: center;
    transition: var(--transition);
}

.stat-card:hover {
    border-color: var(--accent);
}

.stat-number {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent);
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.quick-start h2,
.how-to h2 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.start-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 40px;
}

.start-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 14px;
    transition: var(--transition);
}

.start-card:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.start-icon {
    font-size: 20px;
}

.instructions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 32px;
}

.instruction {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 14px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
}

.inst-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.instruction p {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.instruction strong {
    color: var(--text-primary);
}

/* ===== Question Detail ===== */
.question-detail {
    max-width: 760px;
    margin: 0 auto;
}

.question-header {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.question-number {
    font-size: 12px;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.question-main-title {
    font-size: 24px;
    font-weight: 600;
    line-height: 1.3;
    margin-bottom: 2px;
}

.question-en-title {
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 400;
    margin-bottom: 12px;
}

.question-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.diff-badge {
    display: inline-flex;
    padding: 3px 10px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
}

.diff-badge.easy {
    background: rgba(16, 163, 127, 0.1);
    color: var(--easy);
}

.diff-badge.medium {
    background: rgba(201, 122, 45, 0.1);
    color: var(--medium);
}

.diff-badge.hard {
    background: rgba(229, 83, 75, 0.1);
    color: var(--hard);
}

.tag {
    display: inline-flex;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}

.tag.algo-tag {
    background: rgba(16, 163, 127, 0.08);
    color: var(--accent);
    border: 1px solid rgba(16, 163, 127, 0.15);
}

.tag.ds-tag {
    background: rgba(111, 96, 232, 0.08);
    color: #6f60e8;
    border: 1px solid rgba(111, 96, 232, 0.15);
}

/* Completion checkbox */
.completion-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    margin-left: auto;
}

.completion-toggle:hover {
    border-color: var(--easy);
    color: var(--easy);
}

.completion-toggle.done {
    background: rgba(16, 163, 127, 0.08);
    border-color: rgba(16, 163, 127, 0.25);
    color: var(--easy);
}

/* Sections */
.section {
    margin-bottom: 28px;
}

.section-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-primary);
}

.section p,
.section li {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.8;
    margin-bottom: 8px;
}

.section ul,
.section ol {
    padding-left: 18px;
}

.section strong {
    color: var(--text-primary);
    font-weight: 600;
}

.section code:not([class*="language-"]) {
    background: var(--bg-tertiary);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    color: var(--accent);
}

/* Code Blocks */
.code-block-wrapper {
    position: relative;
    margin: 10px 0;
}

.code-block-wrapper pre {
    background: #1e1e1e !important;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px !important;
    margin: 0 !important;
    overflow-x: auto;
    font-size: 13px !important;
    line-height: 1.6 !important;
}

.code-block-wrapper pre code {
    font-family: 'JetBrains Mono', monospace !important;
    font-size: 13px !important;
}

.copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 10px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 11px;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
    z-index: 2;
}

.copy-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

/* Complexity */
.complexity-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.complexity-item {
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
}

.complexity-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 3px;
}

.complexity-value {
    font-size: 15px;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    color: var(--accent);
}

/* Tips */
.tip-box {
    padding: 10px 14px;
    background: rgba(16, 163, 127, 0.04);
    border: 1px solid rgba(16, 163, 127, 0.1);
    border-radius: var(--radius);
    border-left: 3px solid var(--accent);
    margin-bottom: 6px;
}

.tip-box p {
    font-size: 13px;
    margin: 0;
    color: var(--text-secondary);
}

/* ===== Visualization Styles ===== */
.vis-container {
    padding: 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 10px 0;
}

.vis-array {
    display: flex;
    align-items: center;
    gap: 4px;
    justify-content: center;
    flex-wrap: wrap;
    margin: 8px 0;
}

.vis-cell {
    min-width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    position: relative;
    transition: var(--transition);
}

.vis-cell.highlight {
    background: rgba(16, 163, 127, 0.1);
    border-color: var(--accent);
    color: var(--accent);
}

.vis-cell.highlight2 {
    background: rgba(111, 96, 232, 0.1);
    border-color: #6f60e8;
    color: #6f60e8;
}

.vis-cell.success {
    background: rgba(16, 163, 127, 0.12);
    border-color: var(--easy);
    color: var(--easy);
}

.vis-index {
    position: absolute;
    bottom: -16px;
    font-size: 10px;
    color: var(--text-muted);
}

.vis-linkedlist {
    display: flex;
    align-items: center;
    gap: 2px;
    justify-content: center;
    flex-wrap: wrap;
    margin: 8px 0;
}

.vis-node {
    min-width: 40px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    border: 1.5px solid var(--accent);
    border-radius: 18px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    font-weight: 500;
    color: var(--accent);
}

.vis-node.highlight {
    background: rgba(16, 163, 127, 0.1);
}

.vis-arrow {
    color: var(--text-muted);
    font-size: 16px;
    padding: 0 2px;
}

.vis-null {
    color: var(--text-muted);
    font-size: 12px;
    font-style: italic;
    padding: 0 4px;
}

.vis-tree {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    margin: 8px 0;
}

.vis-tree-row {
    display: flex;
    gap: 14px;
    justify-content: center;
}

.vis-tnode {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    border: 1.5px solid #6f60e8;
    border-radius: 50%;
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    font-weight: 500;
    color: #6f60e8;
}

.vis-tnode.highlight {
    background: rgba(111, 96, 232, 0.1);
}

.vis-tnode.empty {
    border: 1px dashed var(--border);
    color: transparent;
}

.vis-matrix {
    display: inline-flex;
    flex-direction: column;
    gap: 2px;
    margin: 8px 0;
}

.vis-matrix-row {
    display: flex;
    gap: 2px;
}

.vis-steps {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 8px 0;
}

.vis-step {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.step-num {
    min-width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    border-radius: 50%;
    font-size: 12px;
    font-weight: 600;
    color: #fff;
    flex-shrink: 0;
}

.step-content {
    flex: 1;
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
    padding-top: 2px;
}

.vis-caption {
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
    font-style: italic;
}

.vis-label {
    font-size: 12px;
    color: var(--accent);
    text-align: center;
    margin-bottom: 6px;
    font-weight: 500;
}

.vis-pointer {
    text-align: center;
    font-size: 12px;
    color: var(--accent);
    margin-top: -2px;
}

/* ===== Navigation Buttons ===== */
.question-nav {
    display: flex;
    justify-content: space-between;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    margin-top: 28px;
}

.nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.nav-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.nav-btn:disabled,
.nav-btn.disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

/* ===== Topic Page ===== */
.topic-page {
    max-width: 760px;
    margin: 0 auto;
}

.topic-header {
    margin-bottom: 24px;
}

.topic-title {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 6px;
}

.topic-desc {
    font-size: 13px;
    color: var(--text-muted);
}

.topic-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.topic-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    transition: var(--transition);
    text-decoration: none;
}

.topic-card:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.topic-card .tc-id {
    font-size: 12px;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-muted);
    min-width: 30px;
}

.topic-card .tc-title {
    flex: 1;
    font-size: 14px;
}

.topic-card .tc-diff {
    font-size: 10px;
    padding: 1px 7px;
    border-radius: 4px;
    font-weight: 500;
}

/* ===== No Results ===== */
.no-results {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-muted);
}

.no-results-icon {
    font-size: 40px;
    margin-bottom: 10px;
}

/* ===== Responsive Design ===== */
@media (max-width: 768px) {
    .mobile-toggle {
        display: flex;
    }

    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        height: 100vh;
        transition: left 0.3s ease;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.08);
    }

    .sidebar.open {
        left: 0;
    }

    .content {
        padding: 52px 16px 32px;
    }

    .hero-title {
        font-size: 26px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .start-cards {
        grid-template-columns: 1fr;
    }

    .complexity-grid {
        grid-template-columns: 1fr;
    }

    .question-main-title {
        font-size: 20px;
    }
}

@media (max-width: 480px) {
    .content {
        padding: 48px 12px 24px;
    }

    .hero {
        padding: 24px 0 16px;
    }

    .hero-title {
        font-size: 22px;
    }

    .stats-grid {
        gap: 6px;
    }

    .stat-card {
        padding: 14px 10px;
    }

    .stat-number {
        font-size: 22px;
    }
}

/* ===== Animations ===== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.question-detail,
.home,
.topic-page {
    animation: fadeIn 0.25s ease;
}

/* ===== Print Styles ===== */
@media print {

    .sidebar,
    .mobile-toggle,
    .question-nav,
    .completion-toggle,
    .copy-btn {
        display: none !important;
    }

    .content {
        padding: 16px;
    }

    body {
        color: #000;
        background: #fff;
    }

    .section p,
    .section li {
        color: #333;
    }
}