/* ===== Design Tokens ===== */
:root {
    /* Dark theme (default) */
    --bg-primary: #0B0E14;
    --bg-secondary: #121722;
    --bg-card: #161B27;
    --bg-card-hover: #1C2333;
    --bg-elevated: #1E2536;
    --bg-terminal: #0A0D12;
    --text-primary: #E6EDF3;
    --text-secondary: #8B949E;
    --text-muted: #5A6370;
    --accent: #7C6AFF;
    --accent-glow: rgba(124, 106, 255, 0.15);
    --accent-soft: rgba(124, 106, 255, 0.08);
    --green: #3FB950;
    --green-soft: rgba(63, 185, 80, 0.1);
    --orange: #F0883E;
    --orange-soft: rgba(240, 136, 62, 0.1);
    --red: #F85149;
    --red-soft: rgba(248, 81, 73, 0.1);
    --blue: #58A6FF;
    --border: rgba(139, 148, 158, 0.12);
    --border-focus: rgba(124, 106, 255, 0.5);
    --shadow: 0 2px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
    --glass: rgba(22, 27, 39, 0.8);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --sidebar-w: 260px;
    --terminal-w: 340px;
}

[data-theme="light"] {
    --bg-primary: #F6F8FA;
    --bg-secondary: #FFFFFF;
    --bg-card: #FFFFFF;
    --bg-card-hover: #F0F2F5;
    --bg-elevated: #FFFFFF;
    --bg-terminal: #1E2536;
    --text-primary: #1F2328;
    --text-secondary: #656D76;
    --text-muted: #8B949E;
    --border: rgba(31, 35, 40, 0.1);
    --glass: rgba(255, 255, 255, 0.85);
    --shadow: 0 2px 16px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.12);
}

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

html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== Header ===== */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--glass);
    backdrop-filter: blur(20px) saturate(1.8);
    -webkit-backdrop-filter: blur(20px) saturate(1.8);
    border-bottom: 1px solid var(--border);
}

.header-inner {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    border-radius: var(--radius-sm);
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
}

.logo h1 {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    justify-content: flex-end;
}

/* ===== Search ===== */
.search-wrapper {
    position: relative;
    flex: 1;
    max-width: 480px;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 0.6rem 3.5rem 0.6rem 2.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.9rem;
    outline: none;
    transition: var(--transition);
}

.search-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

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

.search-kbd {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    padding: 2px 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: var(--font);
    font-size: 0.7rem;
    color: var(--text-muted);
    pointer-events: none;
}

/* ===== Buttons ===== */
.btn-icon {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border-color: var(--accent);
}

.bookmark-count {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: var(--accent);
    border-radius: 10px;
    font-size: 0.65rem;
    font-weight: 600;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0);
    transition: var(--transition);
}

.bookmark-count.visible {
    opacity: 1;
    transform: scale(1);
}

/* ===== Layout ===== */
.main {
    display: flex;
    flex: 1;
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    padding: 1.25rem;
    border-right: 1px solid var(--border);
    height: calc(100vh - 60px);
    position: sticky;
    top: 60px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

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

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

.sidebar-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.sidebar-subtitle {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.sidebar-section {
    margin-top: 1.5rem;
}

.category-list {
    list-style: none;
}

.category-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-xs);
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
}

.category-item:hover {
    background: var(--accent-soft);
    color: var(--text-primary);
}

.category-item.active {
    background: var(--accent-glow);
    color: var(--accent);
    font-weight: 500;
}

.category-item .cat-emoji {
    margin-right: 0.5rem;
}

.category-item .cat-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--bg-elevated);
    padding: 1px 7px;
    border-radius: 10px;
}

/* ===== Difficulty Filters ===== */
.difficulty-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.diff-btn {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.65rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-family: var(--font);
    font-size: 0.75rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.diff-btn:hover {
    border-color: var(--text-muted);
}

.diff-btn.active {
    background: var(--accent-glow);
    border-color: var(--accent);
    color: var(--accent);
}

.diff-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.diff-dot.beginner {
    background: var(--green);
}

.diff-dot.intermediate {
    background: var(--orange);
}

.diff-dot.advanced {
    background: var(--red);
}

/* ===== Recipe List ===== */
.recipe-list {
    list-style: none;
}

.recipe-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.75rem;
    border-radius: var(--radius-xs);
    font-size: 0.82rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.recipe-item:hover {
    background: var(--accent-soft);
    color: var(--text-primary);
}

.recipe-item .recipe-emoji {
    font-size: 1rem;
}

.sidebar-stats {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.8;
}

/* ===== Content ===== */
.content {
    flex: 1;
    min-width: 0;
    padding: 1.25rem;
    overflow-y: auto;
}

/* ===== Filters Bar ===== */
.filters-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.filter-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.active-filters {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.filter-tag {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.6rem;
    background: var(--accent-glow);
    border: 1px solid var(--accent);
    border-radius: 20px;
    font-size: 0.75rem;
    color: var(--accent);
}

.clear-filters {
    margin-left: auto;
    background: none;
    border: none;
    font-family: var(--font);
    font-size: 0.78rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
}

.clear-filters:hover {
    color: var(--red);
}

/* ===== Commands Grid ===== */
.commands-grid {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

/* ===== Command Card ===== */
.cmd-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    transition: var(--transition);
    cursor: pointer;
    position: relative;
    outline: none;
}

.cmd-card:hover,
.cmd-card:focus-visible {
    background: var(--bg-card-hover);
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
    transform: translateY(-1px);
}

.cmd-card.bookmarked {
    border-left: 3px solid var(--accent);
}

.cmd-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.cmd-title-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.cmd-name {
    font-family: var(--mono);
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--accent);
}

.cmd-diff {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 2px 8px;
    border-radius: 10px;
}

.cmd-diff.beginner {
    background: var(--green-soft);
    color: var(--green);
}

.cmd-diff.intermediate {
    background: var(--orange-soft);
    color: var(--orange);
}

.cmd-diff.advanced {
    background: var(--red-soft);
    color: var(--red);
}

.cmd-actions {
    display: flex;
    gap: 0.25rem;
    flex-shrink: 0;
}

.cmd-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-xs);
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
}

.cmd-action-btn:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.cmd-action-btn.bookmarked {
    color: var(--accent);
}

.cmd-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.65rem;
}

.cmd-syntax {
    font-family: var(--mono);
    font-size: 0.82rem;
    background: var(--bg-terminal);
    padding: 0.6rem 0.9rem;
    border-radius: var(--radius-xs);
    color: var(--green);
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.cmd-example {
    margin-top: 0.6rem;
}

.cmd-example-toggle {
    background: none;
    border: none;
    font-family: var(--font);
    font-size: 0.78rem;
    color: var(--blue);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0;
}

.cmd-example-toggle:hover {
    text-decoration: underline;
}

.cmd-example-content {
    margin-top: 0.5rem;
    padding: 0.6rem 0.9rem;
    background: var(--bg-terminal);
    border-radius: var(--radius-xs);
    font-family: var(--mono);
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.7;
    display: none;
}

.cmd-example-content.show {
    display: block;
}

.cmd-example-content .ex-comment {
    color: var(--text-muted);
}

.cmd-example-content .ex-cmd {
    color: var(--green);
}

.cmd-example-content .ex-output {
    color: var(--text-secondary);
}

/* ===== Terminal Panel ===== */
.terminal-panel {
    width: var(--terminal-w);
    flex-shrink: 0;
    border-left: 1px solid var(--border);
    background: var(--bg-terminal);
    height: calc(100vh - 60px);
    position: sticky;
    top: 60px;
    display: flex;
    flex-direction: column;
}

.terminal-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.terminal-dots {
    display: flex;
    gap: 6px;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.dot.red {
    background: #FF5F56;
}

.dot.yellow {
    background: #FFBD2E;
}

.dot.green {
    background: #27C93F;
}

.terminal-title {
    font-size: 0.75rem;
    color: var(--text-muted);
    flex: 1;
}

.terminal-clear {
    background: none;
    border: none;
    font-family: var(--font);
    font-size: 0.72rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
}

.terminal-clear:hover {
    color: var(--text-primary);
}

.terminal-body {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    font-family: var(--mono);
    font-size: 0.8rem;
    line-height: 1.7;
}

.terminal-body::-webkit-scrollbar {
    width: 4px;
}

.terminal-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.term-comment {
    color: var(--text-muted);
    display: block;
}

.term-line {
    display: block;
    margin: 2px 0;
}

.term-prompt-line {
    color: var(--green);
    display: block;
}

.term-output-line {
    color: var(--text-secondary);
    display: block;
    padding-left: 0.75rem;
}

.terminal-input-row {
    display: flex;
    align-items: center;
    padding: 0.6rem 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.term-prompt {
    color: var(--green);
    font-family: var(--mono);
    font-size: 0.85rem;
    margin-right: 0.5rem;
    font-weight: 600;
}

.terminal-input {
    flex: 1;
    background: none;
    border: none;
    font-family: var(--mono);
    font-size: 0.82rem;
    color: var(--text-primary);
    outline: none;
}

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

/* ===== No Results ===== */
.no-results {
    text-align: center;
    padding: 4rem 2rem;
}

.no-results-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.no-results h3 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.no-results p {
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* ===== Recipe Modal ===== */
.recipe-modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.recipe-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
}

.recipe-modal-content {
    position: relative;
    max-width: 640px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow-lg);
}

.recipe-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-muted);
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-xs);
    transition: var(--transition);
}

.recipe-close:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.recipe-heading {
    font-size: 1.35rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.recipe-desc {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.recipe-step {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.recipe-step-num {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-glow);
    border: 1px solid var(--accent);
    border-radius: 50%;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent);
}

.recipe-step-body {
    flex: 1;
    min-width: 0;
}

.recipe-step-title {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
}

.recipe-step-cmd {
    font-family: var(--mono);
    font-size: 0.82rem;
    background: var(--bg-terminal);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-xs);
    color: var(--green);
    display: block;
}

/* ===== Keyboard Help ===== */
.kbd-help {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.kbd-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(6px);
}

.kbd-content {
    position: relative;
    max-width: 420px;
    width: 100%;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow-lg);
}

.kbd-content h2 {
    font-size: 1.2rem;
    margin-bottom: 1.25rem;
}

.kbd-grid {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.kbd-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.85rem;
}

.kbd-row kbd {
    padding: 3px 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: var(--mono);
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.kbd-row span {
    color: var(--text-secondary);
}

.kbd-close {
    margin-top: 1.5rem;
    width: 100%;
    padding: 0.6rem;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 600;
    color: #fff;
    cursor: pointer;
    transition: var(--transition);
}

.kbd-close:hover {
    opacity: 0.9;
}

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 500;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    padding: 0.6rem 1rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    color: var(--text-primary);
    box-shadow: var(--shadow);
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2s forwards;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.95);
    }

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

@keyframes toastOut {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }

    to {
        opacity: 0;
        transform: translateY(-10px) scale(0.95);
    }
}

/* ===== Responsive ===== */
@media (max-width: 1200px) {
    .terminal-panel {
        display: none;
    }
}

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        left: -300px;
        top: 60px;
        width: 280px;
        height: calc(100vh - 60px);
        z-index: 50;
        background: var(--bg-secondary);
        transition: left 0.3s ease;
    }

    .sidebar.open {
        left: 0;
        box-shadow: var(--shadow-lg);
    }

    .main {
        flex-direction: column;
    }
}

@media (max-width: 640px) {
    .header-inner {
        padding: 0.6rem 1rem;
        gap: 0.75rem;
    }

    .logo h1 {
        display: none;
    }

    .search-kbd {
        display: none;
    }

    .content {
        padding: 0.75rem;
    }

    .cmd-card {
        padding: 0.75rem;
    }

    .recipe-modal-content,
    .kbd-content {
        padding: 1.25rem;
        margin: 1rem;
    }
}

/* ===== Highlight match ===== */
mark {
    background: var(--accent-glow);
    color: var(--accent);
    border-radius: 2px;
    padding: 0 2px;
}

/* scrollbar for content */
.content::-webkit-scrollbar {
    width: 6px;
}

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