:root{
  --bg:#f6f7f8;--surface:#ffffff;--surface-2:#f0f2f4;--text:#202124;--muted:#6b7280;--line:#e2e5e9;--accent:#253142;--accent-text:#fff;--danger:#b42318;--shadow:0 16px 42px rgba(17,24,39,.10);
  --reader-font:17px;--reader-line:1.85;--reader-width:760px;--math-scale:1;
  font-family:Inter,ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI","Noto Sans JP",sans-serif;color:var(--text);background:var(--bg);font-synthesis:none;
}
:root[data-theme="dark"]{--bg:#111315;--surface:#181b1e;--surface-2:#202429;--text:#e8eaed;--muted:#a5abb3;--line:#30353b;--accent:#e7ebef;--accent-text:#151719;--danger:#ff8a80;--shadow:0 18px 45px rgba(0,0,0,.35)}
@media(prefers-color-scheme:dark){:root[data-theme="system"]{--bg:#111315;--surface:#181b1e;--surface-2:#202429;--text:#e8eaed;--muted:#a5abb3;--line:#30353b;--accent:#e7ebef;--accent-text:#151719;--danger:#ff8a80;--shadow:0 18px 45px rgba(0,0,0,.35)}}
*{box-sizing:border-box}html,body,#app{margin:0;min-height:100%;background:var(--bg);color:var(--text)}body{overflow:hidden}button,input,textarea,select{font:inherit;color:inherit}button{cursor:pointer}button,input,textarea,select{outline:none}button:focus-visible,input:focus-visible,textarea:focus-visible,select:focus-visible,a:focus-visible{box-shadow:0 0 0 3px color-mix(in srgb,var(--accent) 25%,transparent)}
.app-shell{height:100dvh;display:flex;flex-direction:column;overflow:hidden}.topbar{height:60px;min-height:60px;padding:env(safe-area-inset-top) 10px 0;display:flex;align-items:center;gap:8px;border-bottom:1px solid var(--line);background:color-mix(in srgb,var(--bg) 92%,transparent);backdrop-filter:blur(16px);z-index:20}.brand-mark{width:44px;height:44px;display:grid;place-items:center;border-radius:12px;background:var(--accent);color:var(--accent-text);font-size:21px;font-weight:700;margin-left:2px}.topbar-title{min-width:0;flex:1;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.topbar-title strong{font-size:15px}.icon-btn{width:44px;height:44px;min-width:44px;border:0;background:transparent;border-radius:12px;display:grid;place-items:center;font-weight:700}.icon-btn:hover{background:var(--surface-2)}
.list-screen{flex:1;overflow:auto;padding:18px 14px calc(90px + env(safe-area-inset-bottom));overscroll-behavior:contain}.hero{max-width:980px;margin:0 auto 18px;padding:24px;border:1px solid var(--line);border-radius:24px;background:linear-gradient(145deg,var(--surface),color-mix(in srgb,var(--surface-2) 55%,var(--surface)));display:flex;justify-content:space-between;gap:18px;align-items:flex-end}.eyebrow{font-size:11px;letter-spacing:.14em;font-weight:800;color:var(--muted);margin:0 0 8px}.hero h1{font-size:clamp(24px,6vw,40px);letter-spacing:-.04em;line-height:1.08;margin:0;max-width:650px}.hero p:not(.eyebrow){color:var(--muted);margin:10px 0 0;line-height:1.6}.hero-new,.primary-btn{min-height:46px;padding:0 18px;border:0;border-radius:13px;background:var(--accent);color:var(--accent-text);font-weight:750;white-space:nowrap}.library-controls{max-width:980px;margin:0 auto 16px}.search-box{height:50px;border:1px solid var(--line);background:var(--surface);border-radius:15px;display:flex;align-items:center;padding:0 14px;gap:8px}.search-box input{border:0;background:transparent;flex:1;min-width:0;height:100%}.control-row{display:flex;gap:10px;margin-top:10px;align-items:center}.chip-scroll{display:flex;gap:8px;overflow:auto;flex:1;scrollbar-width:none}.chip{min-height:40px;padding:0 14px;border-radius:999px;border:1px solid var(--line);background:var(--surface);white-space:nowrap;font-size:13px}.chip.selected{background:var(--accent);color:var(--accent-text);border-color:var(--accent)}select{min-height:44px;border:1px solid var(--line);background:var(--surface);border-radius:12px;padding:0 10px}.doc-list{max-width:980px;margin:0 auto;display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}.doc-card{position:relative;padding:18px;border:1px solid var(--line);border-radius:18px;background:var(--surface);min-height:180px;transition:transform .12s ease,border-color .12s ease}.doc-card:hover{transform:translateY(-1px);border-color:color-mix(in srgb,var(--muted) 35%,var(--line))}.doc-card-top{display:flex;align-items:center;justify-content:space-between}.category-dot{font-size:12px;color:var(--muted);font-weight:700}.star-btn{border:0;background:transparent;width:40px;height:40px;border-radius:10px;font-size:20px}.star-btn.on{color:#c78c13}.doc-card h2{margin:8px 0;font-size:19px;line-height:1.35;letter-spacing:-.02em}.doc-card>p{margin:0;color:var(--muted);line-height:1.6;font-size:14px;display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden}.doc-meta{display:flex;gap:12px;margin-top:14px;font-size:11px;color:var(--muted)}.tag-row{display:flex;gap:6px;flex-wrap:wrap;margin-top:10px}.tag-row span{font-size:11px;background:var(--surface-2);padding:4px 7px;border-radius:8px}.empty{text-align:center;padding:56px 12px;color:var(--muted);grid-column:1/-1}.empty-symbol{font-size:34px}.empty h2{color:var(--text);margin-bottom:6px}
.bottom-nav{position:fixed;z-index:30;left:50%;transform:translateX(-50%);bottom:max(10px,env(safe-area-inset-bottom));width:min(360px,calc(100% - 24px));height:66px;padding:6px;border:1px solid var(--line);border-radius:22px;background:color-mix(in srgb,var(--surface) 92%,transparent);box-shadow:var(--shadow);backdrop-filter:blur(18px);display:grid;grid-template-columns:1fr 1fr 1fr}.nav-btn{border:0;background:transparent;border-radius:16px;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;min-width:0}.nav-btn span{font-size:20px}.nav-btn small{font-size:10px}.nav-btn.primary{background:var(--accent);color:var(--accent-text)}.nav-btn.active:not(.primary){background:var(--surface-2)}
.reader-scroll{flex:1;overflow-y:auto;overflow-x:hidden;overscroll-behavior:contain}.reader{width:min(var(--reader-width),calc(100% - 32px));margin:0 auto;padding:38px 0 64px;font-size:var(--reader-font);line-height:var(--reader-line);overflow-wrap:anywhere}.reader h1,.reader h2,.reader h3,.reader h4,.reader h5,.reader h6{line-height:1.28;letter-spacing:-.025em;scroll-margin-top:78px;position:relative}.reader h1{font-size:2em;margin:0 0 1.0em}.reader h2{font-size:1.48em;margin:2.3em 0 .8em;padding-top:.35em;border-top:1px solid var(--line)}.reader h3{font-size:1.23em;margin:1.8em 0 .65em}.reader h4{font-size:1.08em;margin:1.5em 0 .5em}.reader p{margin:1em 0}.reader ul,.reader ol{padding-left:1.5em}.reader li+li{margin-top:.35em}.reader blockquote{margin:1.3em 0;padding:.2em 1em;border-left:3px solid var(--muted);color:var(--muted);background:color-mix(in srgb,var(--surface-2) 55%,transparent);border-radius:0 10px 10px 0}.reader a{color:inherit;text-decoration-thickness:1px;text-underline-offset:3px}.reader code{font-family:"SFMono-Regular",Consolas,"Liberation Mono",monospace;font-size:.88em;padding:.13em .35em;border-radius:6px;background:var(--surface-2)}.reader pre{position:relative;margin:1.35em 0;background:#1d2025;color:#e8eaed;border-radius:14px;padding:17px;overflow:auto;line-height:1.55}.reader pre code{padding:0;background:none;color:inherit;white-space:pre}.copy-code{position:absolute;right:8px;top:8px;min-height:34px;border:1px solid #414853;border-radius:9px;background:#2b3037;color:#e8eaed;font-size:11px;padding:0 10px}.reader hr{border:0;border-top:1px solid var(--line);margin:2em 0}.table-scroll{max-width:100%;overflow-x:auto;margin:1.25em 0;border:1px solid var(--line);border-radius:12px}.reader table{border-collapse:collapse;width:max-content;min-width:100%;font-size:.9em}.reader th,.reader td{padding:9px 11px;border-bottom:1px solid var(--line);text-align:left;vertical-align:top}.reader th{background:var(--surface-2);font-weight:700}.reader tr:last-child td{border-bottom:0}.heading-link{opacity:0;border:0;background:transparent;color:var(--muted);font-size:.7em;margin-left:7px;vertical-align:middle}.reader h1:hover .heading-link,.reader h2:hover .heading-link,.reader h3:hover .heading-link,.heading-link:focus{opacity:1}.raw-html-disabled{font-family:monospace;color:var(--muted);white-space:pre-wrap}.unsafe-link{border-bottom:1px dotted var(--danger)}.image-disabled{color:var(--muted);font-style:italic}
.math-wrap{font-size:calc(1em * var(--math-scale));cursor:zoom-in}.math-inline{display:inline-block;max-width:100%;vertical-align:middle;overflow-x:auto;overflow-y:hidden}.math-display{display:block;max-width:100%;overflow-x:auto;overflow-y:hidden;padding:.65em .2em;margin:.8em 0;text-align:center;-webkit-overflow-scrolling:touch}.math-display>.katex-display{margin:0;min-width:max-content}.math-inline>.katex{white-space:nowrap}.math-error{cursor:pointer;border:1px solid color-mix(in srgb,var(--danger) 40%,var(--line));background:color-mix(in srgb,var(--danger) 7%,var(--surface));border-radius:10px;padding:10px 12px;color:var(--danger);text-align:left}.math-error code{display:block;white-space:pre-wrap;margin:6px 0;background:transparent;padding:0;color:inherit}.math-error-title{font-size:.8em;font-weight:800}.math-error-hint{display:block;font-size:.7em;color:var(--muted)}.reader-footer{width:min(var(--reader-width),calc(100% - 32px));margin:0 auto;padding:0 0 40px;color:var(--muted);font-size:12px;display:flex;justify-content:space-between;gap:12px}.reading-progress{position:absolute;top:59px;left:0;right:0;height:2px;z-index:25;background:transparent}.reading-progress i{display:block;height:100%;width:0;background:var(--accent);transition:width .08s linear}
.editor-main{flex:1;min-height:0;display:flex;flex-direction:column;padding:14px 14px calc(14px + env(safe-area-inset-bottom));overflow:hidden}.editor-meta{max-width:900px;width:100%;margin:0 auto 10px}.title-input{width:100%;height:48px;border:0;border-bottom:1px solid var(--line);background:transparent;font-size:22px;font-weight:750;letter-spacing:-.02em}.meta-grid{display:grid;grid-template-columns:160px 1fr;gap:10px;margin-top:10px}.meta-grid label,.settings-form label{font-size:11px;color:var(--muted);display:flex;flex-direction:column;gap:5px}.meta-grid input,.meta-grid select,.inline-form input{height:42px;border:1px solid var(--line);background:var(--surface);border-radius:11px;padding:0 10px;color:var(--text)}.segmented{width:min(420px,100%);margin:0 auto 10px;background:var(--surface-2);border-radius:12px;padding:3px;display:grid;grid-template-columns:repeat(3,1fr)}.segmented button{height:38px;border:0;border-radius:9px;background:transparent;font-size:13px}.segmented button.active{background:var(--surface);box-shadow:0 1px 3px rgba(0,0,0,.08);font-weight:700}.editor-pane{flex:1;min-height:0;max-width:900px;width:100%;margin:0 auto;border:1px solid var(--line);background:var(--surface);border-radius:16px;overflow:auto}.editor-pane textarea{display:block;width:100%;height:100%;min-height:340px;resize:none;border:0;padding:16px;background:transparent;color:var(--text);line-height:1.7;font-family:"SFMono-Regular",Consolas,monospace;font-size:14px}.preview-reader{width:100%;padding:24px 18px 50px}.source-view{min-height:100%;position:relative;padding:16px}.source-view pre{white-space:pre-wrap;overflow-wrap:anywhere;margin:0;padding-top:38px;font-family:"SFMono-Regular",Consolas,monospace;font-size:13px;line-height:1.65}.source-view .small-btn{position:absolute;right:12px;top:10px}.editor-actions{max-width:900px;width:100%;margin:10px auto 0;display:flex;gap:10px;justify-content:flex-end}.ghost-btn,.wide-btn,.small-btn,.danger-btn{min-height:44px;border:1px solid var(--line);background:var(--surface);border-radius:12px;padding:0 14px}.primary-btn{min-height:44px}.danger-btn{background:var(--danger);border-color:var(--danger);color:white}.wide-btn{width:100%}.small-btn{min-height:38px;font-size:12px}.save-status{font-size:11px;color:var(--muted);padding:7px 9px;border-radius:9px}.save-status.dirty{background:var(--surface-2)}
.modal-backdrop{position:fixed;inset:0;z-index:80;background:rgba(0,0,0,.38);backdrop-filter:blur(2px)}.sheet{position:fixed;z-index:81;left:50%;bottom:0;transform:translateX(-50%);width:min(620px,100%);max-height:min(82dvh,760px);background:var(--surface);border:1px solid var(--line);border-bottom:0;border-radius:24px 24px 0 0;box-shadow:var(--shadow);padding-bottom:env(safe-area-inset-bottom);overflow:hidden}.sheet-grabber{width:40px;height:4px;border-radius:10px;background:var(--line);margin:8px auto 0}.sheet-head{height:54px;display:flex;align-items:center;padding:0 12px 0 18px;border-bottom:1px solid var(--line)}.sheet-head h2{font-size:17px;flex:1}.sheet-body{padding:16px;overflow:auto;max-height:calc(82dvh - 70px)}.dialog{position:fixed;z-index:81;left:50%;top:50%;transform:translate(-50%,-50%);width:min(520px,calc(100% - 28px));max-height:85dvh;overflow:auto;background:var(--surface);border:1px solid var(--line);border-radius:20px;padding:18px;box-shadow:var(--shadow)}.modal-head{display:flex;align-items:flex-start;gap:12px}.modal-head>div{flex:1}.modal-head h2{margin:0;font-size:20px}.dialog-actions{display:flex;justify-content:flex-end;gap:10px;margin-top:20px}.toc-item{display:block;width:100%;min-height:44px;border:0;background:transparent;text-align:left;border-radius:10px;padding:7px 9px}.toc-item:hover,.toc-item.current{background:var(--surface-2)}.toc-item.level-2{padding-left:18px}.toc-item.level-3{padding-left:32px}.toc-item.level-4,.toc-item.level-5,.toc-item.level-6{padding-left:46px}.math-modal-visual{min-height:120px;display:flex;align-items:center;justify-content:center;overflow:auto;padding:24px 10px;font-size:1.45em}.latex-source{white-space:pre-wrap;overflow-wrap:anywhere;background:var(--surface-2);border-radius:12px;padding:12px;max-height:220px;overflow:auto}.action-list{display:grid;gap:8px}.action-list button{min-height:48px;border:0;border-radius:12px;background:var(--surface-2);text-align:left;padding:0 14px}.action-list button.danger{color:var(--danger)}.settings-form{display:grid;gap:16px}.settings-form label{font-size:12px}.settings-form label output{align-self:flex-end;margin-top:-19px;color:var(--text)}.settings-form input[type=range]{width:100%;accent-color:var(--accent)}.category-manager{display:flex;gap:7px;flex-wrap:wrap}.category-manager span{display:flex;align-items:center;gap:6px;background:var(--surface-2);border-radius:999px;padding:6px 8px 6px 11px;font-size:13px}.category-manager button{width:26px;height:26px;border:0;border-radius:50%;background:transparent}.inline-form{display:flex;gap:8px;margin-top:10px}.inline-form input{flex:1;min-width:0}.toast{position:fixed;z-index:100;left:50%;bottom:calc(88px + env(safe-area-inset-bottom));transform:translateX(-50%);max-width:calc(100% - 28px);min-height:46px;border-radius:13px;background:#25292e;color:#fff;padding:9px 10px 9px 14px;display:flex;align-items:center;gap:12px;box-shadow:var(--shadow);font-size:13px}.text-btn{border:0;background:transparent;color:#fff;min-height:34px;font-weight:800}.muted{color:var(--muted)}.small{font-size:12px}.fatal{padding:30px;max-width:700px;margin:auto}
@media(max-width:620px){.topbar{height:58px;min-height:58px}.hero{padding:19px;border-radius:19px;display:block}.hero h1{font-size:27px}.hero-new{width:100%;margin-top:17px}.doc-list{grid-template-columns:1fr}.doc-card{min-height:160px}.control-row{align-items:flex-start}.control-row select{width:104px}.reader{width:calc(100% - 28px);padding-top:26px}.reader h1{font-size:1.65em}.reader h2{font-size:1.34em;margin-top:2em}.reader h3{font-size:1.16em}.heading-link{opacity:.55}.reader-footer{width:calc(100% - 28px)}.meta-grid{grid-template-columns:1fr 1.35fr}.editor-main{padding:10px 10px calc(10px + env(safe-area-inset-bottom))}.title-input{font-size:20px}.editor-pane{border-radius:13px}.editor-actions>*{flex:1}.reading-progress{top:57px}.math-display{text-align:left}.math-display>.katex-display{text-align:center}}
@media(max-width:370px){.topbar{padding-left:4px;padding-right:4px}.brand-mark{width:40px;height:40px}.icon-btn{width:42px;height:42px;min-width:42px}.list-screen{padding-left:10px;padding-right:10px}.hero{padding:16px}.hero h1{font-size:24px}.meta-grid{grid-template-columns:1fr}.editor-meta{margin-bottom:6px}.segmented{margin-bottom:7px}.reader{width:calc(100% - 22px)}.bottom-nav{width:calc(100% - 18px)}}
@media(orientation:landscape) and (max-height:500px){.hero{display:none}.bottom-nav{width:300px;height:58px}.list-screen{padding-top:10px}.editor-meta{display:grid;grid-template-columns:1fr 1fr;gap:10px}.meta-grid{margin-top:0}.reader{padding-top:24px}.sheet{max-height:94dvh}.sheet-body{max-height:calc(94dvh - 70px)}}
@media(min-width:1000px){.list-screen{padding-top:28px}.reader{padding-top:56px}.topbar{padding-left:max(18px,calc((100vw - 1100px)/2));padding-right:max(18px,calc((100vw - 1100px)/2))}}
.source-icon{font-size:11px;letter-spacing:-.08em}.source-sheet-actions{display:flex;justify-content:flex-end;margin-bottom:10px}.reader-source-pre{margin:0;white-space:pre-wrap;overflow-wrap:anywhere;font-family:"SFMono-Regular",Consolas,monospace;font-size:13px;line-height:1.65;background:var(--surface-2);border-radius:12px;padding:14px;max-height:58dvh;overflow:auto}
/* Keep KaTeX's accessible MathML layer inside the viewport even when a display
   formula is wider than the reader. The visual HTML layer remains horizontally
   scrollable in .math-display. */
.math-wrap .katex-mathml{left:0!important;clip-path:inset(50%)}
