/* Codex — spacious reading, theme-owned colors, transient navigation. */
html[data-route="codex"] #codexView .codex-workspace{width:100%;max-width:1540px!important;margin:0 auto!important;padding:36px clamp(24px,4vw,64px) 70px!important;box-sizing:border-box;container-type:normal;--codex-muted:color-mix(in srgb,var(--muted) 80%,var(--text))}
#codexView .codex-heading{display:flex;align-items:flex-start;justify-content:space-between;gap:24px;margin:0 0 22px!important}
#codexView .codex-heading h1{font:500 clamp(32px,3.5vw,44px)/1.15 var(--theme-heading,var(--theme-ui,system-ui))!important;letter-spacing:-.035em;margin:6px 0 10px!important}
#codexView .codex-heading small{font-size:10px;letter-spacing:.14em;color:var(--codex-muted)}
#codexView .codex-heading p{font:400 14px/1.6 var(--theme-ui,system-ui)!important;color:var(--codex-muted);margin:0}
#codexView .heading-actions{display:flex;gap:8px;flex-wrap:wrap;align-items:center}
#codexView :is(button,summary){font-family:var(--theme-ui,system-ui);cursor:pointer;touch-action:manipulation}
#codexView svg{width:18px;height:18px;fill:none;stroke:currentColor;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;flex:none}
#codexView :is(.soft-btn,.primary-btn),#codexView .codex-tools>summary{display:inline-flex;align-items:center;justify-content:center;gap:8px;min-height:44px;padding:10px 14px;border-radius:8px;font-size:13px;box-shadow:none;white-space:normal}
#codexView .soft-btn,#codexView .codex-tools>summary{background:transparent;color:var(--text);border:1px solid var(--line)}
#codexView .codex-tools{position:relative}
#codexView .codex-tools>summary{list-style:none}
#codexView .codex-tools>summary::-webkit-details-marker{display:none}
#codexView .codex-tools>div{position:absolute;right:0;top:calc(100% + 8px);width:210px;padding:8px;background:var(--surface-strong);border:1px solid var(--line);box-shadow:0 8px 28px color-mix(in srgb,var(--text) 12%,transparent);border-radius:10px;z-index:20}
#codexView .codex-tools button{display:block;text-align:left;width:100%;min-height:44px;padding:10px;border:0;border-radius:5px;background:transparent;color:var(--text);font-size:13px}
#codexView .codex-tools button:hover{background:var(--accent-soft)}
#codexView .codex-tools button.danger{color:var(--danger,var(--text));border-top:1px solid var(--line);margin-top:6px}
#codexView .codex-work-summary{display:flex;flex-wrap:wrap;gap:12px 26px;align-items:center;margin:0 0 28px;color:var(--codex-muted);font-size:12px}
#codexView .codex-work-summary b{font-size:18px;font-weight:500;color:var(--text);margin-right:5px}
#codexView .codex-work-summary button{border:0;background:var(--accent-soft);color:var(--text);border-radius:6px;min-height:36px;padding:8px 12px;text-decoration:underline;text-underline-offset:3px}
#codexView .codex-work-toolbar{display:grid;grid-template-columns:minmax(220px,1fr) minmax(160px,.55fr) minmax(160px,.55fr) minmax(135px,.4fr) auto;gap:12px;align-items:end;padding-bottom:26px;margin-bottom:26px;border-bottom:1px solid var(--line)}
#codexView .codex-work-toolbar>label{display:flex;flex-direction:column;gap:7px;font-size:12px;color:var(--codex-muted);min-width:0}
#codexView .codex-work-toolbar :is(input,select){width:100%;min-width:0;max-width:100%;height:46px;padding:10px 12px;border:1px solid var(--line);border-radius:8px;background:var(--surface);color:var(--text);font:400 14px/1.5 var(--theme-ui,system-ui);box-sizing:border-box;box-shadow:none}
#codexView .codex-work-toolbar input::placeholder{color:var(--codex-muted);opacity:1}
#codexView [hidden]{display:none!important}
#codexView .codex-work-layout{display:grid;grid-template-columns:minmax(270px,320px) minmax(0,1fr);gap:36px;align-items:start}
#codexView .codex-work-index{min-width:0;position:sticky;top:22px;padding-right:22px;border-right:1px solid var(--line)}
#codexView .codex-index-heading{display:flex;align-items:center;gap:12px;margin:0 0 16px}
#codexView .codex-index-heading h2{font:500 16px var(--theme-ui,system-ui);margin:0}
#codexView .codex-index-heading>span{font-size:12px;color:var(--codex-muted);font-variant-numeric:tabular-nums}
#codexView .codex-text-button{padding:8px 0;min-height:36px;border:0;background:transparent;color:var(--accent);font-size:12px;text-align:left}
#codexView .codex-index-heading .codex-text-button{margin-left:auto}
#codexView .codex-category-actions{display:flex;flex-wrap:wrap;align-items:center;gap:8px 12px;font-size:12px;color:var(--codex-muted);overflow-wrap:anywhere}
#codexView .codex-category-actions:empty{display:none}
#codexView .codex-entry-list{display:flex!important;flex-direction:column;gap:4px;max-height:calc(100dvh - 380px);min-height:220px;overflow:auto;scrollbar-gutter:stable;padding-right:4px}
#codexView .codex-entry-row{display:flex;flex-shrink:0;align-items:center;min-width:0;border:1px solid transparent;border-radius:8px;position:relative}
#codexView .codex-entry-row:hover{background:color-mix(in srgb,var(--accent-soft) 60%,transparent)}
#codexView .codex-entry-row.selected{background:var(--accent-soft);border-color:var(--line)}
#codexView .codex-entry-open{display:flex;align-items:flex-start;gap:12px;flex:1;min-width:0;text-align:left;border:0;background:transparent;color:var(--text);padding:15px 8px 15px 12px;min-height:70px}
#codexView .codex-entry-symbol{color:var(--entry-color);padding-top:2px}
#codexView .codex-entry-open>span:last-child{display:flex;flex-direction:column;gap:5px;min-width:0}
#codexView .codex-entry-open b{font:500 15px/1.45 var(--theme-ui,system-ui);white-space:normal;overflow-wrap:anywhere}
#codexView .codex-entry-open small{font:400 12px/1.5 var(--theme-ui,system-ui);color:var(--codex-muted);white-space:normal;overflow-wrap:anywhere}
#codexView .codex-entry-alias{display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
#codexView .codex-row-edit{display:grid;place-items:center;align-self:flex-start;flex:none;margin-top:8px;width:38px;height:44px;padding:8px;border:0;background:none;color:var(--codex-muted);border-radius:5px}
#codexView .codex-row-edit:hover{color:var(--accent);background:var(--surface)}
#codexView .codex-work-detail{min-width:0;scroll-margin-top:76px}
#codexView .codex-work-detail .codex-read-top{padding:0 0 18px;position:static;background:transparent;gap:10px;flex-wrap:wrap}
#codexView .codex-read-top>span{font-size:10px;letter-spacing:.13em;color:var(--codex-muted)}
#codexView .codex-read-top [data-close]{display:none}
#codexView .codex-work-detail .codex-read-body{max-width:none;margin:0;padding:28px 0}
#codexView .codex-reading h2{font:500 clamp(27px,3vw,36px)/1.2 var(--theme-heading,var(--theme-ui,system-ui));text-wrap:initial;overflow-wrap:anywhere}
#codexView .codex-reading h3{font:500 18px/1.5 var(--theme-ui,system-ui)}
#codexView .codex-read-symbol{width:46px;height:54px;background:none;border-radius:8px}
#codexView .codex-read-symbol svg{width:25px;height:25px}
#codexView .codex-read-heading{margin-bottom:24px;gap:18px}
#codexView .codex-read-prose{font-size:16px!important;line-height:1.8!important}
#codexView .codex-read-fields{gap:24px}
#codexView .codex-read-field dd{font-size:15px;line-height:1.75}
#codexView .codex-reading :is(.codex-read-kind,.codex-read-categories,.codex-read-muted,.codex-read-field dt){color:var(--codex-muted)}
.codex-read-nav{display:flex;flex-wrap:wrap;gap:4px 18px;border-bottom:1px solid var(--line);padding:8px 0}
.codex-read-nav button{font:400 12px var(--theme-ui,system-ui);min-height:36px;padding:6px 0;border:0;background:transparent;color:var(--accent);cursor:pointer;text-decoration:underline;text-underline-offset:4px}
.codex-reading-modal .codex-read-nav{padding:8px 28px}
.codex-reading :is(.codex-read-description,.codex-read-fields,.codex-read-relations,.codex-appearances,.codex-context,.codex-backlinks){scroll-margin-top:85px}
#codexView .codex-reading :is(.codex-appearances,.codex-context){border:0;border-top:1px solid var(--line);border-radius:0;background:transparent;padding:28px 0 0;box-shadow:none}
#codexView .codex-reading .codex-context-grid{grid-template-columns:1fr;gap:24px}
#codexView .codex-reading .codex-context-block{grid-column:auto;background:none;border:0;padding:0;border-radius:0}
#codexView .codex-reading .codex-appearance-head h3{font-size:18px!important}
#codexView .codex-reading :is(.codex-appearance-head>span,.codex-appearance-empty,.codex-appearance-jump small,.codex-context-links small,.codex-timeline-links small){font-size:12px!important;line-height:1.6}
#codexView .codex-reading :is(.codex-appearance-jump b,.codex-context-links b,.codex-timeline-links b,.codex-context-title b){font-size:14px!important;line-height:1.5;overflow-wrap:anywhere}
#codexView .codex-reading .codex-appearance-jump em{font-size:13px!important;line-height:1.65}
#codexView .codex-reading .codex-appearance-list{max-height:none;overflow:visible}
#codexView .codex-geography{border-bottom:1px solid var(--line);padding-bottom:12px;margin-bottom:14px}
#codexView .codex-geography>summary{font-size:12px;padding:8px 0;color:var(--accent)}
#codexView .codex-world-overview{padding:10px 0!important;background:none!important;border:0!important;box-shadow:none!important}
#codexView .codex-world-head{display:none}
#codexView .location-tree{max-height:260px;overflow:auto}
#codexView .location-tree button{min-height:44px;white-space:normal;overflow-wrap:anywhere}
#codexView .codex-work-empty{padding:38px 14px;max-width:550px;margin:auto;text-align:left;color:var(--codex-muted)}
#codexView .codex-work-empty h2,#codexView .codex-work-empty h3{font:500 22px/1.4 var(--theme-heading,var(--theme-ui,system-ui));color:var(--text)}
#codexView .codex-work-empty p{font-size:14px;line-height:1.8}
#codexView .codex-work-empty>span svg{width:34px;height:34px}
.codex-backlink-list{display:grid;gap:8px}
.codex-backlink-list button{display:flex;align-items:center;justify-content:space-between;gap:16px;width:100%;padding:13px 14px;border:1px solid var(--line);border-radius:7px;background:transparent;color:var(--text);text-align:left;cursor:pointer}
.codex-backlink-list button>span{display:flex;flex-direction:column;gap:5px;min-width:0}
.codex-backlink-list b{font-size:14px;font-weight:500;overflow-wrap:anywhere}
.codex-backlink-list small{font-size:12px;color:var(--muted);overflow-wrap:anywhere}
/* Editing keeps ordinary writing first; composition controls are opt-in. */
#modal.codex-entry-modal{width:min(1040px,calc(100vw - 40px));padding:28px 34px;background:var(--surface-strong);color:var(--text)}
#modal.codex-entry-modal .codex-entry-head h2{font:500 28px/1.3 var(--theme-heading,var(--theme-ui,system-ui));overflow-wrap:anywhere}
#modal.codex-entry-modal .codex-entry-head p{font-size:14px;line-height:1.6}
#modal.codex-entry-modal .codex-entry-form{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:22px 26px}
#modal.codex-entry-modal :is(input:not([type="checkbox"]):not([type="file"]),select,textarea){width:100%;min-width:0;min-height:46px;font:400 15px/1.65 var(--theme-ui,system-ui);padding:10px 12px;border-radius:8px;box-sizing:border-box;border:1px solid var(--line);background:var(--surface);color:var(--text)}
#modal.codex-entry-modal textarea{min-height:120px;resize:vertical}
#modal.codex-entry-modal #ceDesc{min-height:180px}
#modal.codex-entry-modal .form-row>label{font-size:13px;color:var(--muted);margin-bottom:8px;display:block}
#modal.codex-entry-modal .form-row small{font-size:12px;line-height:1.6}
#modal.codex-entry-modal .codex-category-picker{gap:7px;display:flex;flex-wrap:wrap}
#modal.codex-entry-modal .category-check{min-height:42px;padding:8px 10px;border-radius:7px;font-size:13px}
#modal.codex-entry-modal .codex-symbol-options{grid-column:1/-1;grid-row:4}
#modal.codex-entry-modal .codex-symbol-options summary{font-size:13px;cursor:pointer;padding:12px 0;color:var(--accent)}
#modal.codex-entry-modal .codex-symbol-options>div{padding:8px 0 16px}
#modal.codex-entry-modal .world-template-grid{gap:20px 24px}
#modal.codex-entry-modal .worldbuilding-section{background:none;border:0;padding:0}
#modal.codex-entry-modal .codex-alias-hint{font-size:12px;line-height:1.6;padding:10px 12px;border-radius:6px}
#modal.codex-entry-modal .codex-alias-hint span{font-size:12px;line-height:1.6}
#modal.codex-entry-modal .color-grid{display:flex;flex-wrap:wrap;gap:9px}
#modal.codex-entry-modal .color-choice{width:30px;height:30px;min-height:30px;border-radius:50%}
#modal.codex-entry-modal .cb-editor{margin-top:28px}
#modal.codex-entry-modal .cb-editor-head{display:flex;align-items:center;justify-content:space-between;gap:14px;margin-bottom:14px}
#modal.codex-entry-modal .cb-editor-head h3{font:500 18px var(--theme-ui,system-ui);margin:0 0 6px}
#modal.codex-entry-modal .cb-editor-head p{font-size:12px;line-height:1.6;margin:0;color:var(--muted)}
#modal.codex-entry-modal .cb-edit-block{border:0;border-top:1px solid var(--line);border-radius:0;margin-bottom:20px;background:none}
#modal.codex-entry-modal .cb-edit-body{padding:22px 0 4px}
#modal.codex-entry-modal .cb-edit-block>header{background:none;padding:12px 0}
#modal.codex-entry-modal .cb-editor:not(.is-arranging) .cb-builtin>header{display:none}
#modal.codex-entry-modal .cb-editor:not(.is-arranging) .cb-custom>header :is(.cb-grip,[data-cb-action="up"],[data-cb-action="down"]){display:none}
#modal.codex-entry-modal .cb-pattern-disclosure>summary{font-size:13px;color:var(--accent);padding:14px 0;cursor:pointer}
#modal.codex-entry-modal .cb-patterns{padding:16px;gap:14px;background:var(--surface);border-radius:8px}
#modal.codex-entry-modal .cb-add{border-top:1px solid var(--line);padding-top:20px;gap:12px}
#modal.codex-entry-modal .modal-actions{position:sticky;bottom:-28px;margin-top:20px;padding:14px 0;gap:10px;z-index:4;background:var(--surface-strong);border-top:1px solid var(--line)}
#modal.codex-entry-modal .modal-actions button{min-height:44px;font-size:14px}
#codexView :is(button,input,select,summary):focus-visible,#modal.codex-entry-modal :is(button,input,textarea,select,summary):focus-visible{outline:2px solid var(--accent);outline-offset:3px}
@media(max-width:1150px){#codexView .codex-work-toolbar{grid-template-columns:minmax(210px,1fr) 1fr 1fr}#codexView .codex-work-search{grid-column:1/-1}#codexView #codexClearFilters{grid-column:1/-1;justify-self:start}#codexView .codex-work-layout{grid-template-columns:270px minmax(0,1fr);gap:24px}#codexView .codex-entry-list{max-height:calc(100dvh - 440px)}#codexView .codex-work-index{padding-right:16px}}
@media(max-width:1000px){html[data-route="codex"] #codexView .codex-workspace{padding:28px 28px 60px!important}#codexView .codex-heading{flex-wrap:wrap}#codexView .codex-work-layout{display:block}#codexView .codex-work-index{position:static;padding:0;border:0}#codexView .codex-entry-list{max-height:none;min-height:100px}#codexView .codex-work-detail{display:none}#codexView .detail-open .codex-work-index{display:none}#codexView .detail-open .codex-work-detail{display:block}#codexView .codex-read-top [data-close]{display:inline-flex}#codexView .codex-entry-open{padding:16px;min-height:78px}#codexView .codex-row-edit{margin:12px 8px;width:44px}#modal.codex-entry-modal{padding:24px}#modal.codex-entry-modal .modal-actions{bottom:-24px}}
@media(max-width:650px){#codexView .codex-work-toolbar{grid-template-columns:1fr 1fr}#codexView .codex-work-toolbar>label:first-child{grid-column:1/-1}#codexView .codex-work-toolbar>label:nth-child(2){grid-column:1/-1}#modal.codex-entry-modal .codex-entry-form{grid-template-columns:1fr}#modal.codex-entry-modal .codex-symbol-options{grid-row:auto}#modal.codex-entry-modal .modal-actions{flex-wrap:wrap}.codex-read-nav{gap:4px 14px}}
@media(pointer:coarse){#codexView .codex-work-toolbar :is(input,select){font-size:16px}#codexView .codex-text-button,.codex-read-nav button{min-height:44px}}
@media(prefers-reduced-motion:reduce){#codexView *{scroll-behavior:auto!important;transition:none!important}}
