/* ═══════════════════════════════════════════════════
   Basics Tutorial — Base Styles
   Used by index.html and all chapter pages.
   ═══════════════════════════════════════════════════ */

/* ── Design Tokens ───────────────── */
:root,
[data-theme="light"] {
    --bg: #fafafa;
    --surface: #ffffff;
    --border: #e5e7eb;
    --text: #1a1a2e;
    --text-secondary: #6b7280;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-light: #eff6ff;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.06);
    --radius: 12px;
}

/* ── Dark Theme ─────────────────── */
[data-theme="dark"] {
    --bg: #1a1a2e;
    --surface: #16213e;
    --border: #2d3748;
    --text: #e2e8f0;
    --text-secondary: #94a3b8;
    --accent: #60a5fa;
    --accent-hover: #93c5fd;
    --accent-light: #1e3a5f;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.4), 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* ── Sepia Theme ────────────────── */
[data-theme="sepia"] {
    --bg: #f4ecd8;
    --surface: #faf3e3;
    --border: #d4c5a9;
    --text: #3e2f1c;
    --text-secondary: #7a6a52;
    --accent: #8b5e3c;
    --accent-hover: #6b4530;
    --accent-light: #f0e2c8;
    --shadow: 0 1px 3px rgba(60, 40, 20, 0.08), 0 1px 2px rgba(60, 40, 20, 0.04);
    --shadow-hover: 0 4px 16px rgba(60, 40, 20, 0.12), 0 2px 4px rgba(60, 40, 20, 0.06);
}

/* ── Forest Theme ───────────────── */
[data-theme="forest"] {
    --bg: #f0f5f0;
    --surface: #ffffff;
    --border: #c8d6c0;
    --text: #1e2d1e;
    --text-secondary: #5a7a5a;
    --accent: #2d7a3a;
    --accent-hover: #1f5c28;
    --accent-light: #e8f5e9;
    --shadow: 0 1px 3px rgba(30, 50, 30, 0.06), 0 1px 2px rgba(30, 50, 30, 0.04);
    --shadow-hover: 0 4px 16px rgba(30, 50, 30, 0.1), 0 2px 4px rgba(30, 50, 30, 0.06);
}

/* ── Ocean Theme ────────────────── */
[data-theme="ocean"] {
    --bg: #f0f6fa;
    --surface: #ffffff;
    --border: #c8dae8;
    --text: #0f2d44;
    --text-secondary: #4a7a9e;
    --accent: #0d6ea8;
    --accent-hover: #095180;
    --accent-light: #e3f0f8;
    --shadow: 0 1px 3px rgba(15, 45, 68, 0.06), 0 1px 2px rgba(15, 45, 68, 0.04);
    --shadow-hover: 0 4px 16px rgba(15, 45, 68, 0.1), 0 2px 4px rgba(15, 45, 68, 0.06);
}

/* ── Sunset Theme ───────────────── */
[data-theme="sunset"] {
    --bg: #fef9f5;
    --surface: #ffffff;
    --border: #f0d5c8;
    --text: #3d1e0a;
    --text-secondary: #9e6a52;
    --accent: #d4683a;
    --accent-hover: #b84e28;
    --accent-light: #fff0e8;
    --shadow: 0 1px 3px rgba(80, 30, 10, 0.06), 0 1px 2px rgba(80, 30, 10, 0.04);
    --shadow-hover: 0 4px 16px rgba(80, 30, 10, 0.1), 0 2px 4px rgba(80, 30, 10, 0.06);
}

/* ── Theme Picker & Search Button ── */
.theme-picker {
    position: fixed;
    top: 0.75rem;
    right: 0.75rem;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 0;
}

.theme-btn {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, border-color 0.15s ease;
    line-height: 1;
}

.theme-btn:hover {
    border-color: var(--accent);
}

.theme-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.35rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.15);
    min-width: 180px;
    overflow: hidden;
    z-index: 101;
}

.theme-menu.open {
    display: block;
}

.theme-menu-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.6rem 0.9rem;
    border: none;
    border-bottom: 1px solid var(--border);
    background: none;
    font-family: inherit;
    font-size: 0.85rem;
    color: var(--text);
    cursor: pointer;
    text-align: left;
    transition: filter 0.1s ease;
}

.theme-menu-item:last-child {
    border-bottom: none;
}

.theme-menu-item:hover {
    filter: brightness(0.95);
}

.theme-menu-item.active {
    font-weight: 600;
}

.theme-menu-item .dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1px solid rgba(0, 0, 0, 0.15);
}

.search-toggle {
    position: fixed;
    top: 0.75rem;
    right: 3.25rem;
    z-index: 100;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, border-color 0.15s ease;
    line-height: 1;
}

.search-toggle:hover {
    border-color: var(--accent);
}

/* ── Search Overlay ─────────────── */
.search-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    justify-content: center;
    padding-top: 12vh;
}

.search-overlay.visible {
    display: flex;
}

.search-box {
    width: 560px;
    max-width: 92vw;
    max-height: 70vh;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border);
}

.search-input-wrap {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    gap: 0.6rem;
}

.search-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.search-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 1rem;
    font-family: inherit;
    background: transparent;
    color: var(--text);
}

.search-input::placeholder {
    color: var(--text-secondary);
}

.search-close {
    background: none;
    border: none;
    font-size: 1rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    flex-shrink: 0;
}

.search-close:hover {
    background: var(--accent-light);
    color: var(--text);
}

.search-results {
    overflow-y: auto;
    padding: 0.4rem;
}

.search-result {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.65rem 0.75rem;
    text-decoration: none;
    color: var(--text);
    border-radius: 8px;
    transition: background 0.1s ease;
    cursor: pointer;
}

.search-result:hover,
.search-result.active {
    background: var(--accent-light);
}

.search-badge {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    height: 24px;
    padding: 0 0.5rem;
    border-radius: 6px;
    background: var(--accent-light);
    color: var(--accent);
    font-size: 0.72rem;
    font-weight: 700;
    margin-top: 0.1rem;
}

.search-result-text {
    min-width: 0;
}

.search-result-title {
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.4;
}

.search-result-sub {
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-top: 0.1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.search-empty {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* ── Reset ───────────────────────── */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ── Body ────────────────────────── */
body {
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ── Footer ──────────────────────── */
.footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
}

/* Documentation portal treatment, aligned with TypeScript-100. */
:root {
    --bg: #f6f8fb;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1f2937;
    --text-secondary: #64748b;
    --accent: #3451b2;
    --accent-hover: #263f91;
    --accent-light: #e8edff;
    --radius: 10px;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
        "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

.search-toggle,
.sidebar-toggle,
.theme-btn {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--accent);
}

.search-icon { color: var(--accent); }
.search-overlay { background: rgba(15, 23, 42, 0.42); }
.search-box { border-color: var(--border); box-shadow: 0 20px 60px rgba(15, 23, 42, .18); }
.search-input-wrap { background: var(--surface); }

/* Quiet, reusable icon controls. */
.ui-icon {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.search-toggle,
.sidebar-toggle,
.theme-btn {
    width: 44px;
    height: 44px;
    border: 1px solid #dbe3ee;
    border-radius: 10px;
    background: rgba(255, 255, 255, .94);
    box-shadow: 0 8px 24px rgba(15, 23, 42, .08);
    transition: border-color .18s ease, color .18s ease, box-shadow .18s ease, transform .18s ease;
}

.search-toggle:hover,
.sidebar-toggle:hover,
.theme-btn:hover {
    border-color: #93c5fd;
    color: #1d4ed8;
    box-shadow: 0 10px 28px rgba(37, 99, 235, .14);
    transform: translateY(-1px);
}

.theme-picker { top: 20px; right: 20px; }
.search-toggle { top: 20px; right: 76px; }
.sidebar-toggle { top: 20px; left: 20px; }
.theme-menu { min-width: 190px; margin-top: 10px; border-radius: 10px; }
.theme-menu-item { gap: .7rem; padding: .72rem .9rem; }
.theme-menu-item .dot { width: 10px; height: 10px; }
