:root {
    color-scheme: light;
    --ink: #17302a;
    --muted: #65746f;
    --paper: #f7f2e8;
    --paper-strong: #fffdf8;
    --forest: #123a32;
    --forest-light: #1f594d;
    --line: #dcd5c8;
    --accent: #ed7958;
    --accent-light: #ffb45f;
    --danger: #ac443d;
    --shadow: 0 18px 60px rgb(28 50 43 / 10%);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--paper); }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
.skip-link { position: fixed; top: -5rem; left: 1rem; z-index: 100; padding: .75rem 1rem; color: white; background: var(--forest); border-radius: .4rem; }
.skip-link:focus { top: 1rem; }
.eyebrow { display: inline-block; color: var(--accent); font-size: .7rem; font-weight: 800; letter-spacing: .19em; text-transform: uppercase; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

.site-header { position: sticky; top: 0; z-index: 20; min-height: 68px; display: grid; grid-template-columns: 260px 1fr auto; align-items: center; gap: 1.5rem; padding: .65rem 1.25rem; color: #f9f2e7; background: rgb(15 43 36 / 97%); border-bottom: 1px solid rgb(255 255 255 / 9%); backdrop-filter: blur(14px); }
.brand { display: flex; align-items: center; gap: .7rem; color: inherit; text-decoration: none; }
.brand img { filter: drop-shadow(0 5px 12px rgb(0 0 0 / 18%)); }
.brand span { display: grid; }
.brand strong { font-family: Georgia, serif; font-size: 1.2rem; letter-spacing: .11em; }
.brand small { color: #b9c9c3; font-size: .67rem; letter-spacing: .08em; }
.header-center { min-width: 0; display: flex; align-items: center; gap: .65rem; }
.header-search { width: min(310px, 38vw); flex: 0 1 310px; display: flex; align-items: center; color: #e8f0ed; background: rgb(255 255 255 / 9%); border: 1px solid rgb(255 255 255 / 12%); border-radius: .5rem; }
.header-search input { min-width: 0; padding: .5rem .15rem .5rem .7rem; color: inherit; background: transparent; border: 0; box-shadow: none; }
.header-search input::placeholder { color: #9db0a9; }
.header-search button { width: 36px; align-self: stretch; color: #f4c695; background: transparent; border: 0; cursor: pointer; font-size: 1.25rem; }
.chip-nav { min-width: 0; display: flex; gap: .35rem; overflow-x: auto; scrollbar-width: none; }
.chip-nav a { flex: 0 0 auto; padding: .48rem .7rem; color: #d4dfdb; border-radius: 999px; font-size: .82rem; text-decoration: none; }
.chip-nav a:hover { color: white; background: rgb(255 255 255 / 8%); }
.header-actions, .inline-actions, .form-actions { display: flex; align-items: center; gap: .65rem; }
.button, .icon-button, .text-button, .tab, .management-card { border: 0; cursor: pointer; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 38px; padding: .62rem 1rem; border-radius: .5rem; font-weight: 700; text-decoration: none; transition: transform .16s ease, background .16s ease, opacity .16s ease; }
.button:hover { transform: translateY(-1px); }
.button.primary { color: #172b25; background: linear-gradient(135deg, var(--accent-light), var(--accent)); box-shadow: 0 7px 20px rgb(237 121 88 / 22%); }
.button.subtle { color: var(--ink); background: #ebe5d9; }
.site-header .button.subtle { color: #f7f2e8; background: rgb(255 255 255 / 10%); }
.button.danger { color: white; background: var(--danger); }
.button.danger-text { color: var(--danger); background: #f5e5e0; }
.button.large { min-height: 50px; padding-inline: 1.4rem; }
.button:disabled { cursor: wait; opacity: .5; }
.icon-button { min-width: 38px; min-height: 38px; display: grid; place-items: center; padding: .35rem; color: inherit; background: transparent; border-radius: .4rem; font-size: 1.15rem; }
.icon-button:hover { background: rgb(128 128 128 / 12%); }
.mobile-only { display: none; }

.workspace { min-height: calc(100vh - 68px); display: grid; grid-template-columns: 280px minmax(0, 1fr); }
.tree-panel { position: sticky; top: 68px; height: calc(100vh - 68px); display: flex; flex-direction: column; padding: 1.5rem 1rem 1rem; background: #eee7da; border-right: 1px solid var(--line); overflow: auto; }
.panel-heading { display: flex; justify-content: space-between; align-items: start; padding: 0 .55rem 1rem; }
.panel-heading h2 { margin: .25rem 0 0; font-family: Georgia, serif; font-size: 1.25rem; }
.wiki-tree ul { margin: 0; padding: 0; list-style: none; }
.wiki-tree ul ul { margin-left: 1rem; padding-left: .45rem; border-left: 1px solid #d3cab9; }
.wiki-tree a { min-height: 38px; display: flex; align-items: center; gap: .55rem; margin: .12rem 0; padding: .45rem .55rem; border-radius: .45rem; color: #40534d; font-size: .88rem; text-decoration: none; }
.wiki-tree a:hover { background: rgb(255 255 255 / 52%); }
.wiki-tree a.active { color: white; background: var(--forest-light); box-shadow: 0 6px 18px rgb(18 58 50 / 18%); }
.wiki-tree a small { margin-left: auto; padding: .1rem .3rem; color: #8d6c60; background: #f2ddd1; border-radius: .2rem; font-size: .62rem; }
.node-icon { width: 1rem; flex: 0 0 1rem; color: #798982; text-align: center; }
.type-chip { color: #d0654d; }
.type-board { color: #547b70; }
.type-project { color: #a97c3b; }
.tree-footer { display: flex; justify-content: space-between; margin-top: auto; padding: 1rem .55rem .25rem; color: var(--muted); font-size: .76rem; border-top: 1px solid var(--line); }
.tree-footer a { color: var(--danger); }

.content { min-width: 0; outline: none; }
.welcome-view { min-height: calc(100vh - 68px); display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(280px, .7fr); align-items: center; gap: 4rem; padding: clamp(3rem, 7vw, 7rem); background: radial-gradient(circle at 80% 20%, rgb(239 179 104 / 17%), transparent 30%), linear-gradient(135deg, #faf6ed, #f1eadc); overflow: hidden; }
.welcome-copy { max-width: 740px; }
.welcome-copy h1 { margin: .7rem 0 1.3rem; font-family: Georgia, "Noto Serif SC", serif; font-size: clamp(2.8rem, 6vw, 6.2rem); font-weight: 500; line-height: .98; letter-spacing: -.045em; }
.welcome-copy h1 em { color: var(--accent); font-weight: inherit; }
.welcome-copy p { max-width: 580px; margin: 0 0 2rem; color: var(--muted); font-size: clamp(1rem, 1.5vw, 1.25rem); line-height: 1.8; }
.memory-card { position: relative; min-height: 430px; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: .8rem; color: #9db1aa; background: var(--forest); border-radius: 1rem 4rem 1rem 4rem; box-shadow: var(--shadow); transform: rotate(2deg); overflow: hidden; }
.memory-card::before { content: ""; position: absolute; inset: 1rem; border: 1px solid rgb(255 255 255 / 12%); border-radius: .6rem 3.3rem .6rem 3.3rem; }
.memory-card img { position: relative; width: 112px; height: 112px; margin-bottom: 1rem; transform: rotate(-2deg) scale(1.1); }
.memory-card span { position: relative; font: 700 .7rem ui-monospace, monospace; letter-spacing: .18em; }
.memory-light { position: absolute; inset: -30%; background: radial-gradient(circle, rgb(239 121 83 / 25%), transparent 44%); }

.page-view, .management-view, .error-view { width: min(1180px, calc(100% - 3rem)); margin: 0 auto; padding: clamp(2rem, 5vw, 5rem) 0 6rem; }
.page-hero { min-height: 170px; display: flex; justify-content: space-between; align-items: center; gap: 2rem; padding-bottom: 2rem; border-bottom: 1px solid var(--line); }
.page-hero h1, .management-view h1, .error-view h1 { margin: .7rem 0 .5rem; font-family: Georgia, "Noto Serif SC", serif; font-size: clamp(2.3rem, 5vw, 4.6rem); font-weight: 500; line-height: 1.05; }
.page-summary { max-width: 720px; margin: .8rem 0 1rem; color: var(--muted); font-size: 1.03rem; line-height: 1.65; }
.page-hero img { width: min(260px, 30vw); max-height: 160px; object-fit: contain; border-radius: .7rem; }
.type-badge { display: inline-flex; align-items: center; gap: .4rem; padding: .28rem .55rem; color: var(--forest); background: #e5dfd2; border-radius: 999px; font-size: .74rem; font-weight: 800; }
.metadata { display: flex; flex-wrap: wrap; gap: .45rem 1rem; color: var(--muted); font-size: .82rem; }
.page-columns { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: clamp(2rem, 5vw, 5rem); padding-top: 2.7rem; }
.page-tools { display: flex; flex-direction: column; gap: 1rem; }
.info-card, .flash-disabled { padding: 1.1rem; background: #eee7da; border: 1px solid var(--line); border-radius: .65rem; }
.info-card dl { margin: .8rem 0 0; }
.info-card dl div { display: flex; justify-content: space-between; gap: 1rem; padding: .48rem 0; border-top: 1px solid var(--line); }
.info-card dt { color: var(--muted); }
.info-card dd { margin: 0; font-weight: 700; }
.tool-actions { display: grid; gap: .5rem; }
.flash-button { display: grid; gap: .25rem; width: 100%; padding: 1.15rem; border: 0; color: white; background: linear-gradient(135deg, var(--forest-light), var(--forest)); border-radius: .65rem; text-align: left; cursor: pointer; box-shadow: 0 12px 28px rgb(18 58 50 / 17%); }
.flash-button span { font-size: 1.05rem; font-weight: 800; }
.flash-button small, .flash-disabled small { color: #b9cbc5; line-height: 1.45; }
.flash-disabled { display: grid; gap: .3rem; color: #667871; }
.flash-disabled small { color: #86928e; }
.flash-target { display: grid; gap: .3rem; padding: 1rem; border: 1px solid var(--line); border-radius: .65rem; background: var(--paper-strong); }
.flash-target strong { font-size: 1.05rem; }
.flash-target span, .flash-warning, .flash-consent, #flash-dialog small { color: var(--muted); line-height: 1.5; }
.flash-warning { padding: .8rem; border-left: 3px solid var(--accent-light); background: #fff8e9; }
.flash-consent { display: flex; gap: .6rem; align-items: flex-start; }

.markdown-body { min-width: 0; color: #2a403a; font-size: 1rem; line-height: 1.85; overflow-wrap: anywhere; }
.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 { margin: 2em 0 .65em; color: var(--ink); font-family: Georgia, "Noto Serif SC", serif; line-height: 1.25; }
.markdown-body h1 { font-size: 2rem; }
.markdown-body h2 { padding-bottom: .4rem; font-size: 1.55rem; border-bottom: 1px solid var(--line); }
.markdown-body h3 { font-size: 1.25rem; }
.markdown-body p { margin: 1em 0; }
.markdown-body a { color: #bd563f; text-underline-offset: .2em; }
.markdown-body code { padding: .15em .35em; color: #9f4d3c; background: #eee4d5; border-radius: .25rem; font: .9em ui-monospace, SFMono-Regular, Consolas, monospace; }
.markdown-body pre { padding: 1.15rem; color: #e6eee9; background: #17362f; border-radius: .65rem; overflow-x: auto; box-shadow: inset 0 1px rgb(255 255 255 / 8%); }
.markdown-body pre code { padding: 0; color: inherit; background: transparent; }
.markdown-body blockquote { margin: 1.5rem 0; padding: .2rem 1.2rem; color: #596c65; background: #eee8db; border-left: 4px solid var(--accent); }
.markdown-body hr { margin: 2.5rem 0; border: 0; border-top: 1px solid var(--line); }
.markdown-body li { margin: .35rem 0; }

.firmware-panel { margin-top: 4rem; padding-top: 2.5rem; border-top: 1px solid var(--line); }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 1.5rem; margin-bottom: 1.5rem; }
.section-heading h1, .section-heading h2 { margin: .35rem 0 0; font-family: Georgia, "Noto Serif SC", serif; font-weight: 500; }
.section-heading h2 { font-size: 2rem; }
.section-heading p { margin: .4rem 0 0; color: var(--muted); }
.section-heading.compact { margin-top: 3rem; }
.mcp-token-form { max-width: 760px; margin-bottom: 1.5rem; }
.mcp-token-form fieldset { display: flex; flex-wrap: wrap; gap: .6rem 1rem; padding: 1rem; border: 1px solid var(--line); border-radius: .5rem; }
.mcp-token-form fieldset label { display: flex; align-items: center; gap: .35rem; }
.token-secret { display: block; margin-top: .5rem; padding: .75rem; overflow-wrap: anywhere; user-select: all; }
.switch { display: flex; align-items: center; gap: .45rem; color: var(--muted); font-size: .85rem; cursor: pointer; }
.switch input { accent-color: var(--forest-light); }
.table-wrap { width: 100%; overflow-x: auto; background: var(--paper-strong); border: 1px solid var(--line); border-radius: .7rem; box-shadow: 0 10px 30px rgb(40 53 48 / 5%); }
table { width: 100%; border-collapse: collapse; font-size: .86rem; }
th, td { padding: .85rem 1rem; text-align: left; border-bottom: 1px solid #ebe5da; vertical-align: middle; white-space: nowrap; }
th { color: var(--muted); background: #f2ede3; font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
td small { display: block; margin-top: .2rem; color: var(--muted); }
td code { font: .8rem ui-monospace, monospace; }
.current-tag { padding: .12rem .3rem; color: #26654f; background: #dceade; border-radius: .25rem; font-size: .62rem; }
.text-button { padding: .25rem; color: var(--forest-light); background: none; font-weight: 700; }
.text-button.danger { color: var(--danger); }

.management-view { min-height: calc(100vh - 68px); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.management-card { min-height: 155px; display: flex; flex-direction: column; align-items: start; justify-content: end; gap: .5rem; padding: 1.25rem; color: var(--ink); background: var(--paper-strong); border: 1px solid var(--line); border-radius: .7rem; text-align: left; box-shadow: 0 10px 25px rgb(40 53 48 / 5%); }
.management-card:hover { border-color: #b9aa95; transform: translateY(-2px); }
.management-card strong { font-family: Georgia, serif; font-size: 1.3rem; }
.management-card span { color: var(--muted); line-height: 1.5; }
.danger-card strong { color: var(--danger); }
.item-list { display: grid; gap: .7rem; }
.item-list article { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 1rem 1.15rem; background: var(--paper-strong); border: 1px solid var(--line); border-radius: .65rem; }
.item-list article > div:first-child { display: grid; gap: .25rem; }
.item-list article span { color: var(--muted); font-size: .8rem; }
.empty { padding: 2rem; color: var(--muted); background: #eee8dc; border: 1px dashed #cfc5b5; border-radius: .6rem; text-align: center; }
.empty.compact { padding: 1rem; font-size: .82rem; }
.error-view { min-height: 70vh; display: flex; flex-direction: column; justify-content: center; align-items: start; }
.error-view p { max-width: 600px; color: var(--muted); font-size: 1.1rem; }
.error-view .button { margin-top: 1rem; }

.search-filters { display: grid; grid-template-columns: minmax(240px, 2fr) repeat(3, minmax(130px, 1fr)) auto; align-items: end; gap: .75rem; margin-bottom: 1.5rem; padding: 1rem; background: #eee7da; border: 1px solid var(--line); border-radius: .7rem; }
.search-filters label { display: grid; gap: .35rem; color: var(--muted); font-size: .74rem; font-weight: 800; }
.search-status { min-height: 2rem; color: var(--muted); font-size: .86rem; }
.search-results { display: grid; gap: .8rem; }
.search-result { display: flex; justify-content: space-between; align-items: start; gap: 2rem; padding: 1.25rem 1.35rem; background: var(--paper-strong); border: 1px solid var(--line); border-radius: .7rem; box-shadow: 0 8px 24px rgb(40 53 48 / 4%); }
.search-result:hover { border-color: #c4b8a6; }
.search-result-main { min-width: 0; }
.search-result h2 { margin: .45rem 0; font-family: Georgia, "Noto Serif SC", serif; font-size: 1.45rem; }
.search-result h2 a { text-decoration: none; }
.search-result h2 a:hover { color: var(--accent); }
.search-result p { margin: .35rem 0 0; line-height: 1.6; }
.result-summary { color: var(--ink); }
.result-snippet { color: var(--muted); font-size: .9rem; }
.result-tags { display: flex; flex-wrap: wrap; gap: .3rem; }
.result-tags span { padding: .15rem .35rem; color: #62736d; background: #eee8dd; border-radius: .25rem; font-size: .67rem; }
.search-result time { flex: 0 0 auto; color: var(--muted); font-size: .74rem; }

.modal { width: min(480px, calc(100% - 2rem)); max-height: calc(100vh - 2rem); padding: 0; color: var(--ink); background: var(--paper-strong); border: 1px solid var(--line); border-radius: .8rem; box-shadow: 0 24px 90px rgb(9 30 24 / 30%); }
.modal.wide { width: min(820px, calc(100% - 2rem)); }
.modal::backdrop { background: rgb(10 31 26 / 60%); backdrop-filter: blur(4px); }
.modal-heading { display: flex; justify-content: space-between; align-items: start; padding: 1.35rem 1.5rem 1rem; border-bottom: 1px solid var(--line); }
.modal-heading h2 { margin: .2rem 0 0; font-family: Georgia, serif; font-size: 1.7rem; }
.tabs { display: flex; gap: .3rem; padding: .8rem 1.5rem 0; }
.tab { padding: .5rem .8rem; color: var(--muted); background: transparent; border-bottom: 2px solid transparent; }
.tab.active { color: var(--forest); border-color: var(--accent); font-weight: 800; }
.form-stack { display: grid; gap: 1rem; padding: 1.35rem 1.5rem 1.5rem; }
.form-stack label { display: grid; gap: .4rem; color: #40524c; font-size: .82rem; font-weight: 700; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.span-two { grid-column: span 2; }
input, textarea, select { width: 100%; padding: .68rem .75rem; color: var(--ink); background: #fffefa; border: 1px solid #cfc6b8; border-radius: .42rem; outline: 0; }
input:focus, textarea:focus, select:focus { border-color: var(--forest-light); box-shadow: 0 0 0 3px rgb(31 89 77 / 12%); }
textarea { resize: vertical; line-height: 1.55; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.form-actions { justify-content: end; }
.form-status { min-height: 1.25em; margin: 0; color: var(--danger); font-size: .82rem; }
progress { width: 100%; height: .6rem; accent-color: var(--accent); }
.toast { position: fixed; right: 1.2rem; bottom: 1.2rem; z-index: 80; max-width: min(420px, calc(100% - 2.4rem)); padding: .85rem 1rem; color: white; background: var(--forest); border-radius: .5rem; box-shadow: var(--shadow); }
.toast.error { background: var(--danger); }
.skeleton { height: 1rem; margin: 1rem 0; background: linear-gradient(90deg, #e8e0d2 25%, #f5f0e8 50%, #e8e0d2 75%); background-size: 200% 100%; border-radius: .3rem; animation: shimmer 1.4s infinite; }
.skeleton.short { width: 55%; }
.skeleton.title { width: 45%; height: 3.5rem; }
@keyframes shimmer { to { background-position: -200% 0; } }

.standalone-error { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(circle at 50% 20%, #fff9ed, var(--paper)); }
.error-card { width: min(560px, calc(100% - 2rem)); padding: 3rem; background: var(--paper-strong); border: 1px solid var(--line); border-radius: 1rem; box-shadow: var(--shadow); text-align: center; }
.error-card h1 { margin: .5rem 0; font-family: Georgia, serif; font-size: 2.5rem; }
.error-card p { margin-bottom: 1.5rem; color: var(--muted); }

@media (max-width: 900px) {
    .site-header { grid-template-columns: auto 1fr auto; }
    .brand small, .chip-nav { display: none; }
    .header-search { width: 100%; max-width: none; flex-basis: auto; }
    .mobile-only { display: grid; }
    .workspace { display: block; }
    .tree-panel { position: fixed; z-index: 40; top: 0; left: 0; width: min(340px, 88vw); height: 100vh; transform: translateX(-105%); transition: transform .22s ease; box-shadow: 15px 0 50px rgb(10 31 26 / 25%); }
    .tree-panel.open { transform: translateX(0); }
    .welcome-view { grid-template-columns: 1fr; padding: 3rem 1.5rem; }
    .memory-card { min-height: 260px; }
    .page-columns { grid-template-columns: 1fr; }
    .page-tools { grid-row: 1; display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
    .search-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .search-query-field { grid-column: span 2; }
}

@media (max-width: 600px) {
    .site-header { min-height: 62px; padding-inline: .75rem; }
    .brand strong { font-size: 1rem; }
    .header-actions { gap: .35rem; }
    .header-center { gap: 0; }
    .header-search { max-width: 155px; }
    .site-header .button { min-height: 36px; padding: .5rem .7rem; }
    #new-page-button { display: none; }
    .welcome-copy h1 { font-size: 2.7rem; }
    .memory-card { display: none; }
    .page-view, .management-view, .error-view { width: min(100% - 2rem, 1180px); padding-top: 2rem; }
    .page-hero { align-items: start; }
    .page-hero img { width: 100px; max-height: 100px; }
    .page-hero h1 { font-size: 2.35rem; }
    .page-columns { gap: 1.5rem; padding-top: 1.5rem; }
    .section-heading { align-items: start; flex-direction: column; }
    .section-heading .inline-actions { width: 100%; justify-content: space-between; }
    .form-grid { grid-template-columns: 1fr; }
    .span-two { grid-column: auto; }
    .item-list article { align-items: start; flex-direction: column; }
    .search-filters { grid-template-columns: 1fr; }
    .search-query-field { grid-column: auto; }
    .search-result { flex-direction: column; gap: .7rem; }
    .modal { max-height: calc(100vh - 1rem); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
