:root {
    --bg: #f8f4ee;
    --surface: #fffdf9;
    --surface-strong: #ffffff;
    --text: #2d2926;
    --muted: #847a72;
    --border: #e7ddd3;
    --accent: #8b2f4b;
    --accent-soft: #f3e4e8;
    --shadow: 0 8px 24px rgba(64, 43, 34, 0.08);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: "Noto Sans TC", "Outfit", sans-serif;
}

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

body { min-height: 100dvh; }

.app-shell {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: calc(14px + env(safe-area-inset-top, 0px)) 16px 12px;
    background: rgba(248, 244, 238, 0.94);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
    backdrop-filter: blur(18px);
}

.eyebrow {
    margin: 0 0 3px;
    color: var(--accent);
    font-family: "Outfit", sans-serif;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.12em;
}

h1 {
    margin: 0;
    max-width: 210px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 20px;
    font-weight: 600;
}

.header-actions { display: flex; align-items: center; gap: 8px; }
.save-status { color: var(--muted); font-size: 12px; white-space: nowrap; }

.icon-btn {
    width: 42px;
    height: 42px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    color: var(--text);
    display: inline-grid;
    place-items: center;
    text-decoration: none;
    font-size: 20px;
}
.icon-btn:disabled { opacity: 0.38; }
.icon-btn:active { transform: scale(0.97); }

.view-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    margin: 12px 16px 8px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: #eee7df;
}

.tab-btn {
    min-height: 44px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--muted);
    font-weight: 600;
}
.tab-btn.active { background: var(--surface-strong); color: var(--accent); box-shadow: 0 2px 8px rgba(64, 43, 34, 0.08); }

.main-content { flex: 1; min-height: 0; }
.view-panel { min-height: 100%; }
.outline-list { padding: 8px 16px calc(28px + var(--safe-bottom)); }

.outline-card {
    --depth: 0;
    margin: 0 0 10px min(calc(var(--depth) * 18px), 72px);
    min-height: 58px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-left: 4px solid var(--node-color, var(--accent));
    border-radius: 16px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.outline-card.root-card {
    background: linear-gradient(135deg, #8b2f4b, #a94d68);
    border-color: transparent;
    color: white;
}

.node-index {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    background: var(--accent-soft);
    color: var(--accent);
    font-family: "Outfit", sans-serif;
    font-size: 12px;
    font-weight: 600;
}
.root-card .node-index { background: rgba(255,255,255,0.18); color: white; }
.node-topic { min-width: 0; flex: 1; font-size: 16px; font-weight: 500; overflow-wrap: anywhere; }
.node-level { color: var(--muted); font-size: 12px; }
.root-card .node-level { color: rgba(255,255,255,0.72); }

.map-toolbar {
    display: grid;
    grid-template-columns: 46px 66px 46px 1fr;
    gap: 7px;
    padding: 8px 12px 0;
}
.map-toolbar button {
    min-height: 42px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: var(--surface);
    color: var(--text);
    font-weight: 600;
}
.map-toolbar button:last-child { background: var(--accent-soft); color: var(--accent); border-color: #e6cbd3; }

.mobile-map {
    height: calc(100dvh - 202px - env(safe-area-inset-top, 0px));
    min-height: 420px;
    margin: 8px 12px calc(12px + var(--safe-bottom));
    overflow: hidden;
    touch-action: none;
    overscroll-behavior: contain;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
}

.mobile-map jmnode.map-dragging {
    z-index: 50 !important;
    opacity: 0.86;
    box-shadow: 0 12px 28px rgba(90, 37, 55, 0.28) !important;
    transition: none !important;
}
.mobile-map jmnode.map-drop-target {
    outline: 4px solid rgba(139, 47, 75, 0.42) !important;
    outline-offset: 5px;
}

.outline-card.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(139, 47, 75, 0.13), var(--shadow);
}

.action-dock {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(10px + var(--safe-bottom));
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 3px;
    padding: 7px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: rgba(255, 253, 249, 0.96);
    box-shadow: 0 14px 38px rgba(50, 32, 25, 0.18);
    backdrop-filter: blur(20px);
}

.action-dock button {
    min-width: 0;
    min-height: 50px;
    padding: 4px 1px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--muted);
    font-size: 10px;
}
.action-dock button span { display: block; color: var(--accent); font-size: 19px; line-height: 22px; }
.action-dock button:active { background: var(--accent-soft); }

.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; width: 100%; border: 0; background: rgba(36, 27, 23, 0.42); }
.sheet-panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 10px 18px calc(18px + var(--safe-bottom));
    border-radius: 24px 24px 0 0;
    background: var(--surface-strong);
    box-shadow: 0 -18px 50px rgba(40, 25, 20, 0.2);
}
.sheet-handle { width: 42px; height: 5px; margin: 0 auto 16px; border-radius: 999px; background: #d8cec5; }
.sheet h2 { margin: 0 0 16px; font-size: 20px; }
.file-subtitle {
    margin: 0 0 16px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
}
.sheet label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 13px; }
.sheet textarea {
    width: 100%;
    min-height: 104px;
    resize: none;
    padding: 13px;
    border: 1px solid var(--border);
    border-radius: 14px;
    outline: none;
    background: #fffdfa;
    color: var(--text);
    font-size: 17px;
}
.sheet textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(139, 47, 75, 0.12); }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.sheet-actions button { min-height: 48px; border-radius: 14px; font-weight: 600; }
.btn-secondary { border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.btn-primary { border: 1px solid var(--accent); background: var(--accent); color: white; }

.compact-sheet { padding-bottom: calc(24px + var(--safe-bottom)); }
.more-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.more-grid button {
    min-height: 82px;
    padding: 10px 5px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
}
.more-grid button span { display: block; margin-bottom: 5px; color: var(--accent); font-size: 24px; }
.more-grid .danger-action { color: #a12828; border-color: #efcaca; background: #fff7f7; }
.more-grid .danger-action span { color: #b42323; }

.collapse-toggle {
    flex: 0 0 auto;
    min-width: 36px;
    padding: 4px 8px;
    border-radius: 10px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 12px;
    font-weight: 600;
    text-align: center;
    user-select: none;
}
.root-card .collapse-toggle { background: rgba(255,255,255,0.2); color: white; }

.move-target-list {
    max-height: 60vh;
    overflow-y: auto;
    padding-bottom: calc(20px + var(--safe-bottom));
}
.move-target-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 52px;
    padding: 10px 14px;
    margin-bottom: 6px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    color: var(--text);
    font-size: 15px;
    text-align: left;
}
.move-target-item:active { background: var(--accent-soft); }
.move-target-item.disabled { opacity: 0.38; }
.move-target-item .move-depth { color: var(--muted); font-size: 11px; white-space: nowrap; }

body.has-selection .outline-list { padding-bottom: calc(100px + var(--safe-bottom)); }
body.has-selection .mobile-map { height: calc(100dvh - 300px - env(safe-area-inset-top, 0px)); }

.file-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.file-grid button {
    min-height: 72px;
    padding: 10px 8px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
}
.file-grid button span { display: block; margin-bottom: 4px; color: var(--accent); font-size: 22px; }
.file-grid .btn-secondary { grid-column: 1 / -1; min-height: 48px; }

.import-warning { color: #a12828; font-weight: 600; margin-top: 12px; }
.storage-notice-text { color: var(--text); font-size: 15px; line-height: 1.6; margin-bottom: 16px; }

[hidden] { display: none !important; }
