:root {
    --bg: #f7f7f8;
    --text: #111114;
    --muted: #707078;
    --line: rgba(145, 145, 153, 0.38);
    --glass: rgba(255, 255, 255, 0.74);
    --shadow: 0 22px 70px rgba(0, 0, 0, 0.10);
    --radius: 24px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    background:
        radial-gradient(circle at 12% 8%, rgba(235, 235, 238, 0.92), transparent 28%),
        radial-gradient(circle at 80% 4%, rgba(228, 228, 232, 0.72), transparent 28%),
        #ffffff;
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, Arial, sans-serif;
    overflow: hidden;
}

button, input, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.glass {
    background: linear-gradient(145deg, rgba(255,255,255,0.86), rgba(233,233,236,0.72));
    border: 1px solid var(--line);
    box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,0.72);
    backdrop-filter: blur(18px);
}

.app-shell {
    height: 100vh;
    display: grid;
    grid-template-rows: 74px 1fr;
    padding: 14px;
    gap: 14px;
}

.topbar {
    display: grid;
    grid-template-columns: 220px minmax(260px, 1fr) auto;
    align-items: center;
    gap: 16px;
    border-radius: var(--radius);
    padding: 12px 14px 12px 20px;
}

.brand {
    font-size: 25px;
    font-weight: 720;
    letter-spacing: -0.055em;
    white-space: nowrap;
}

.search-wrap {
    position: relative;
    min-width: 0;
}

.search {
    width: 100%;
    height: 44px;
    border: 1px solid rgba(145,145,153,0.42);
    border-radius: 17px;
    background: rgba(255,255,255,0.72);
    padding: 0 16px;
    outline: none;
    letter-spacing: -0.015em;
}

.search:focus { border-color: rgba(55,55,60,0.52); }

.search-results {
    position: absolute;
    top: 52px;
    left: 0;
    right: 0;
    z-index: 30;
    display: none;
    max-height: 420px;
    overflow: auto;
    border-radius: 18px;
    padding: 8px;
}

.search-results.open { display: block; }

.search-result {
    padding: 10px 12px;
    border-radius: 13px;
    cursor: pointer;
}

.search-result:hover { background: rgba(255,255,255,0.74); }

.result-title { font-weight: 650; letter-spacing: -0.025em; }
.result-snippet { margin-top: 3px; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.top-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.button, .icon-button {
    border: 1px solid rgba(130,130,138,0.48);
    border-radius: 15px;
    cursor: pointer;
    transition: transform 110ms ease, background 110ms ease;
}

.button:hover, .icon-button:hover { transform: translateY(-1px); }
.button { height: 44px; padding: 0 15px; }
.button.soft { background: rgba(255,255,255,0.62); color: #151518; }
.button.dark { background: #070709; color: white; border-color: #070709; }
.icon-button {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    background: rgba(255,255,255,0.62);
}

.workspace {
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(260px, 0.24fr) minmax(420px, 1fr) minmax(260px, 0.26fr);
    gap: 14px;
}

.pane {
    min-height: 0;
    border-radius: var(--radius);
    overflow: hidden;
}

.files-pane, .links-pane {
    padding: 16px;
    overflow-y: auto;
}

.editor-pane {
    position: relative;
    padding: 0;
}

.pane-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.pane-title {
    font-size: 18px;
    font-weight: 720;
    letter-spacing: -0.04em;
}

.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

.tree { padding-bottom: 80px; }

.folder-block { margin: 3px 0; }

.tree-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 7px;
    min-height: 36px;
    padding: 4px 4px 4px 8px;
    border-radius: 13px;
    cursor: pointer;
}

.tree-row:hover, .tree-row.selected { background: rgba(255,255,255,0.68); }
.tree-row.root { font-weight: 700; }

.tree-title {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    letter-spacing: -0.015em;
}

.tree-actions {
    display: none;
    gap: 3px;
}

.tree-row:hover .tree-actions, .tree-row.selected .tree-actions { display: flex; }

.mini-btn {
    min-width: 25px;
    height: 25px;
    padding: 0 6px;
    border: 1px solid rgba(150,150,158,0.38);
    background: rgba(255,255,255,0.58);
    border-radius: 9px;
    cursor: pointer;
    font-size: 12px;
}

.children { margin-left: 16px; }
.note-row .tree-title::before { content: "◇ "; color: #7a7a82; }
.folder-row .tree-title::before { content: "▾ "; color: #7a7a82; }

.empty-state {
    height: 100%;
    display: grid;
    place-content: center;
    text-align: center;
    padding: 40px;
}

.empty-title {
    font-size: 32px;
    font-weight: 760;
    letter-spacing: -0.06em;
    margin-bottom: 8px;
}

.note-editor {
    height: 100%;
    display: grid;
    grid-template-rows: auto auto 1fr;
}

.note-toolbar {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 14px;
    padding: 16px;
    border-bottom: 1px solid rgba(145,145,153,0.27);
}

.note-title-input {
    min-width: 0;
    border: 0;
    background: transparent;
    outline: none;
    font-size: 31px;
    font-weight: 730;
    letter-spacing: -0.065em;
}

.segmented {
    align-self: center;
    display: flex;
    padding: 4px;
    border: 1px solid rgba(145,145,153,0.34);
    border-radius: 15px;
    background: rgba(255,255,255,0.52);
}

.segment {
    border: 0;
    background: transparent;
    border-radius: 11px;
    padding: 8px 12px;
    cursor: pointer;
    color: #55555d;
}
.segment.active { background: #08080a; color: white; }

.save-status {
    height: 26px;
    padding: 4px 18px;
    color: var(--muted);
    font-size: 12px;
}

.note-body, .preview {
    width: 100%;
    height: 100%;
    min-height: 0;
    border: 0;
    resize: none;
    outline: none;
    background: transparent;
    padding: 18px 28px 110px;
    overflow: auto;
}

.note-body {
    font-size: 17px;
    line-height: 1.62;
    font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

.preview {
    font-size: 18px;
    line-height: 1.72;
    letter-spacing: -0.012em;
}

.preview h1, .preview h2, .preview h3 {
    letter-spacing: -0.055em;
    line-height: 1.16;
}

.preview a.wikilink {
    color: #111114;
    text-decoration: none;
    border-bottom: 1px solid rgba(20,20,22,0.42);
    cursor: pointer;
}

.preview a.wikilink.missing { color: #8b4d00; border-bottom-style: dashed; }

.preview pre {
    overflow-x: auto;
    padding: 16px;
    border-radius: 17px;
    background: rgba(255,255,255,0.60);
    border: 1px solid rgba(160,160,168,0.42);
}

.preview code { font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; }
.preview table { border-collapse: collapse; width: 100%; overflow: auto; }
.preview th, .preview td { border: 1px solid rgba(145,145,153,0.36); padding: 8px 10px; }

.link-section { margin-bottom: 22px; }
.link-section h3 {
    margin: 0 0 10px;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.055em;
    color: #5d5d65;
}

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
    padding: 7px 10px;
    border-radius: 999px;
    background: rgba(255,255,255,0.66);
    border: 1px solid rgba(150,150,158,0.35);
    color: #16161a;
    cursor: pointer;
    font-size: 13px;
}

.link-list { display: flex; flex-direction: column; gap: 7px; }
.side-link {
    padding: 9px 11px;
    border-radius: 13px;
    background: rgba(255,255,255,0.50);
    border: 1px solid rgba(150,150,158,0.25);
    cursor: pointer;
}
.side-link.missing { color: #8b4d00; border-style: dashed; }

.graph-dialog {
    width: min(1100px, calc(100vw - 28px));
    height: min(760px, calc(100vh - 28px));
    border-radius: 28px;
    padding: 16px;
    color: var(--text);
}

.graph-dialog::backdrop { background: rgba(255,255,255,0.55); backdrop-filter: blur(10px); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.graph-svg { width: 100%; height: calc(100% - 64px); border-radius: 21px; background: rgba(255,255,255,0.46); border: 1px solid rgba(145,145,153,0.32); }
.graph-node { cursor: pointer; }
.graph-label { pointer-events: none; font-size: 13px; fill: #151518; }
.graph-edge { stroke: rgba(50,50,55,0.34); stroke-width: 1.4; }

.mobile-nav { display: none; }

@media (max-width: 980px) {
    body { overflow: hidden; }

    .app-shell {
        height: 100dvh;
        grid-template-rows: auto 1fr auto;
        padding: 8px;
        gap: 8px;
    }

    .topbar {
        grid-template-columns: 1fr;
        gap: 9px;
        padding: 12px;
        border-radius: 20px;
    }

    .brand { font-size: 22px; }
    .top-actions { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 7px; }
    .button { height: 42px; padding: 0 8px; font-size: 13px; }

    .workspace { display: block; min-height: 0; }
    .mobile-panel { display: none; height: 100%; border-radius: 20px; }
    .mobile-panel.active { display: block; }
    .files-pane, .links-pane { height: 100%; }

    .note-toolbar { grid-template-columns: 1fr; gap: 9px; padding: 12px; }
    .note-title-input { font-size: 25px; }
    .segmented { width: 100%; }
    .segment { flex: 1; }
    .note-body, .preview { padding: 14px 16px 120px; font-size: 16px; }

    .tree-actions { display: flex; }
    .tree-row { min-height: 42px; }
    .mini-btn { min-width: 31px; height: 31px; }

    .mobile-nav {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 6px;
        border-radius: 20px;
        padding: 8px 8px calc(8px + var(--safe-bottom));
    }

    .mobile-tab {
        height: 42px;
        border: 1px solid rgba(145,145,153,0.35);
        background: rgba(255,255,255,0.55);
        border-radius: 15px;
        color: #55555d;
    }

    .mobile-tab.active { background: #08080a; color: white; }

    .graph-dialog {
        width: calc(100vw - 12px);
        height: calc(100dvh - 12px);
        border-radius: 22px;
        padding: 12px;
    }
}

.nav-link { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
